gpt4 book ai didi

javascript - 谷歌地图 API v3 : update rectangle bounds when the shape is dragged or resized

转载 作者:行者123 更新时间:2023-11-30 18:07:23 25 4
gpt4 key购买 nike

我正在尝试使用绘图工具在 google map 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);
});

最佳答案

为 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) .

关于javascript - 谷歌地图 API v3 : update rectangle bounds when the shape is dragged or resized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15497447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com