[英]Can't get lon-lat from mouseUp event after dragging element to map (openlayers)
嘗試獲取發生mouseUp事件的點的坐標時遇到的問題。 這是一個事件處理程序:
$('#someDiv')
.on("mouseup", map, function(event) {
click.trigger(event, map, d[i]);
})
這是一個觸發器:
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'mouseup': this.trigger
}, this.handlerOptions
);
},
trigger: function(e, map, k) {
var marker = map.getLonLatFromPixel(e.xy);
var point = new OpenLayers.Geometry.Point(new OpenLayers.LonLat(marker.lat.toFixed(5),
marker.lng.toFixed(5)));
}
});
我遇到了Uncaught TypeError:無法讀取null的屬性“ lat”那么,如何獲取注冊了mouseUp事件的點的經緯度?
您應該將具有x和y屬性的對象發送到getLonLatFromPixel方法。 因此,在您的情況下,它將如下所示:var marker = map.getLonLatFromPixel({x:e.pageX,y:e.pageY});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.