2012-04-23 64 views
1

我想:矩形通過谷歌地圖的DrawingManager繪製不會觸發mousemove事件

  • 一個谷歌地圖
  • 最多有上矩形
  • 顯示鼠標時的當前位置上繪製矩形它的動作

所以,我想出了這個代碼 - http://jsfiddle.net/mark69_fnd/vBwf6/4/ 我訂閱rectanglecomplete事件的實例,以便處理前一個矩形,保存對新矩形的引用並訂閱矩形上的mousemove事件。

問題是,mousemove事件永遠不會被觸發。

我在做什麼錯誤,以及如何解決它?

謝謝。

回答

7

這裏是一個函數,它給出了與地圖容器左上角相關的像素偏移量的GPS座標。

function getLatLngByOffset(map, offsetX, offsetY){ 
    var currentBounds = map.getBounds(); 
    var topLeftLatLng = new google.maps.LatLng(currentBounds.getNorthEast().lat(), 
               currentBounds.getSouthWest().lng()); 
    var point = map.getProjection().fromLatLngToPoint(topLeftLatLng); 
    point.x += offsetX/(1<<map.getZoom()); 
    point.y += offsetY/(1<<map.getZoom()); 
    return map.getProjection().fromPointToLatLng(point); 
} 

添加地圖的div元素上'onmousemove'事件偵聽器,然後通過與div的左上角的鼠標位置。

UPDATEDEMO(測試

+0

你能的jsfiddle呢?謝謝。 – mark 2012-05-03 19:25:31

+0

@mark請參閱* DEMO *。 – Engineer 2012-05-05 14:37:33

+0

它的工作。非常感謝。 – mark 2012-05-05 17:26:08

相關問題