多边形坐标已更改/已编辑/移动事件(Google Maps V3)

Tim*_*ess 5 google-maps google-maps-api-3

由于谷歌映射v3.11,可以将draggable属性设置为Polygon,CircleRectangle.例如,new google.maps.Polygon({ draggable: true }).

对于CircleRectangle,有类似事件radius_changed,center_changedbounds_changed为我们订阅当有任何变化.

但是Polygon,我们只能认购set_at,insert_atremove_at事件polygon.getPath().

因此,拖动多边形后会出现问题,多边形的位置已被更改/编辑/移动,但没有事件可以监听此更改.

Rod*_*olo 10

有一个更好的方法来实现这个,如果你想听路径位置的变化和路径中的新点,这里是代码:

place_polygon = new google.maps.Polygon({/*...*/});
var place_polygon_path = place_polygon.getPath()
google.maps.event.addListener(place_polygon_path, 'set_at', polygonChanged);
google.maps.event.addListener(place_polygon_path, 'insert_at', polygonChanged);

function polygonChanged(){
    console.log('Changed');
}
Run Code Online (Sandbox Code Playgroud)


geo*_*zip 7

"dragend"活动怎么样?

对我有用

  • @chrismarx他们有记录,很难找到:https://developers.google.com/maps/documentation/javascript/shapes#dragging_events (2认同)