2013-10-31 50 views
3

我有一个可编辑的多边形,并且我想在拖动顶点(多边形调整大小)时监听事件。通常将路径附加到'set_at'事件是很好的,但是当整个多边形被拖拽时它会触发很多事件。Google Map可编辑多边形过滤器从set_at事件拖动事件

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

我想达到什么是有一个事件像“shape_changed”它被拖到时不会触发事件。

回答

3

dragstart取出set_at章24 -listener和dragend

0

另一种选择是的dragstart和dragend设置一个标志,和你的听众set_at看那个标志做任何事情之前重新分配set_at章24 -listener :

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