2013-06-13 16 views
1

嘗試獲取mouseUp事件發生點的座標時遇到問題。 這裏是事件處理程序:將元素拖動到地圖後,無法從mouseUp事件中獲取lon-lat(開放層)

$('#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))); 
    } 
}); 

遺漏的類型錯誤:無效的不能讀取屬性「緯度」 所以,我怎樣才能得到LAT和lon的點,在哪裏mouseUp事件被註冊?

回答

2

你應該發送一個x和y屬性的對象給getLonLatFromPixel方法。所以在你的情況下,它會看起來像這樣: var marker = map.getLonLatFromPixel({x:e.pageX,y:e.pageY});

+0

ty bro!accepted。 – Arti88

相關問題