google map api v3:拖动或重新设置形状时更新矩形边界 [英] google map api v3 : update rectangle bounds when the shape is dragged or reseized

查看:125
本文介绍了google map api v3:拖动或重新设置形状时更新矩形边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用绘图工具在Google地图api v3上绘制一个矩形。我希望用户能够:

1)在形状完成时获取矩形边界。

2)拖动或重新设置矩形时更新边界。



(1 )工作正常,但我需要一些帮助(2)。

这是我使用的代码:



Hi,
I'm trying to draw a rectangle on google map api v3 using the draw tool.I want the user to be able to :
1)get the rectangle bounds when the shape is complete.
2)update the bounds when the rectangle is dragged or reseized.

The (1) worked fine but i need some help on (2).
This is the code i used :

//----------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);
     });



请帮忙吗?


Any help please?

推荐答案

你好,



试试这个:



Hi there,

Try this:

//----------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);
     
     //Here the new code
     var rectangle = rectangle.overlay;

     //get new bounds
     google.maps.event.addListener(rectangle, "bounds_changed", function(event) {

	document.getElementById("savedata").value = rectangle.getBounds();

     });
});


这篇关于google map api v3:拖动或重新设置形状时更新矩形边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆