11 javascript events google-maps google-maps-api-3
如何检测何时修改可编辑多边形(点移动,点添加,移除点)或拖动?Google Maps API文档仅列出多边形的鼠标事件.
小智 30
多边形由Paths组成,它们只是MVCArrays(在这种情况下,它们是LatLng对象的列表).MVCArrays有三个事件:insert_at,remove_at,和set_at.我们可以使用这些事件来检测多边形点的变化.
也有多边形拖动事件:dragstart,drag,和dragend.dragend如果你想知道一个形状被拖动,最好听.
总之,我们可以检测到多边形的任何变化:
// Loop through all paths in the polygon and add listeners
// to them. If we just used `getPath()` then we wouldn't
// detect all changes to shapes like donuts.
polygon.getPaths().forEach(function(path, index){
google.maps.event.addListener(path, 'insert_at', function(){
// New point
});
google.maps.event.addListener(path, 'remove_at', function(){
// Point was removed
});
google.maps.event.addListener(path, 'set_at', function(){
// Point was moved
});
});
google.maps.event.addListener(polygon, 'dragend', function(){
// Polygon was dragged
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9488 次 |
| 最近记录: |