2013-03-19 22 views
1

我試圖在繪製工具上使用谷歌地圖api v3繪製矩形。我希望用戶能夠:谷歌地圖api v3:當形狀被拖動或調整大小時更新矩形邊界

  1. 當形狀完成時,獲取矩形邊界。
  2. 更新矩形拖動或重新捕獲時的邊界。

(1)工作正常,但我需要一些關於(2)的幫助。 這是我用於(1)中的代碼:

//----------on rectangle complete event 
     google.maps.event.addDomListener(drawingManager, 'rectanglecomplete', function(rectangle) { 
     //get the rectangle bounds 
     document.getElementById("savedata").value =rectangle.getBounds();  
    //hide draw tool 
    drawingManager.setOptions({ 
     drawingControl: false 
      }); 
    //disable draw tool 
    drawingManager.setDrawingMode(null); 
     }); 

回答

2

添加事件偵聽到矩形爲的bounds_changed,捕獲新的座標。代碼(未測試):

google.maps.event.addListener(rectangle, "bounds_changed", function() { 
    document.getElementById("savedata").value =rectangle.getBounds(); 
}); 

這裏是an example using the DrawingManager,使您可以繪製矩形,對其進行修改並捕獲更改值。唯一缺少的是change event (bounds_changed on the rectangle)

+0

感謝您的幫助,它工作正常 – AnouarDjerba 2013-03-19 13:43:10

相關問題