admin管理员组文章数量:1398831
I have a editable polygon and I want to listen to events when a vertex is dragged(polygon resized) . Normally attaching the paths to 'set_at' event is good but it fires a lot of events when the whole polygon is dragged.
google.maps.event.addListener(polygon, 'dragend', function(){search();});
google.maps.event.addListener(polygon.getPath(), 'insert_at', function(e, e1){search();});
google.maps.event.addListener(polygon.getPath(), 'remove_at', function(e, e1){search();});
//this also fires a lot of events when ploygon is dragged
google.maps.event.addListener(polygon.getPath(), 'set_at', function(){search();});
What I want to achieve is have an event something like "shape_changed" which doesn't fire events when it is dragged.
I have a editable polygon and I want to listen to events when a vertex is dragged(polygon resized) . Normally attaching the paths to 'set_at' event is good but it fires a lot of events when the whole polygon is dragged.
google.maps.event.addListener(polygon, 'dragend', function(){search();});
google.maps.event.addListener(polygon.getPath(), 'insert_at', function(e, e1){search();});
google.maps.event.addListener(polygon.getPath(), 'remove_at', function(e, e1){search();});
//this also fires a lot of events when ploygon is dragged
google.maps.event.addListener(polygon.getPath(), 'set_at', function(){search();});
What I want to achieve is have an event something like "shape_changed" which doesn't fire events when it is dragged.
Share Improve this question edited Oct 31, 2013 at 19:46 JJJ 33.2k20 gold badges94 silver badges103 bronze badges asked Oct 31, 2013 at 18:52 James LinJames Lin 26.6k39 gold badges144 silver badges249 bronze badges2 Answers
Reset to default 7Remove the set_at
-listener on dragstart
and re-assign the set_at
-listener on dragend
Another option is to set a flag at dragstart and at dragend, and have your set_at listeners look at that flag before doing anything:
polygon.addListener('dragstart', function (event) {
dragging = true;
});
polygon.addListener('dragend', function (event) {
//do drag end stuff here
dragging = false;
});
//setup resize handler
var paths = polygon.getPaths();
paths.forEach(function (path) {
path.addListener('set_at', function (event) {
if (!dragging) //ignore this event while dragging
//do resize stuff here
});
});
本文标签: javascriptGoogle Map Editable Polygon Filter Drag event from setat eventsStack Overflow
版权声明:本文标题:javascript - Google Map Editable Polygon Filter Drag event from set_at events - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744123287a2591840.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论