Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google Map可编辑多边形过滤器从set_事件中拖动事件_Javascript_Google Maps_Events_Polygon_Drag - Fatal编程技术网

Javascript Google Map可编辑多边形过滤器从set_事件中拖动事件

Javascript Google Map可编辑多边形过滤器从set_事件中拖动事件,javascript,google-maps,events,polygon,drag,Javascript,Google Maps,Events,Polygon,Drag,我有一个可编辑多边形,我想在拖动顶点(调整多边形大小)时收听事件。通常,将路径附加到“set_at”事件是好的,但当拖动整个多边形时,它会触发很多事件 google.maps.event.addListener(polygon, 'dragend', function(){search();}); google.maps.event.addListener(polygon.getPath(), 'insert_at', function(e, e1){search();}); google.ma

我有一个可编辑多边形,我想在拖动顶点(调整多边形大小)时收听事件。通常,将路径附加到“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”的事件在被拖动时不会触发事件。

删除
设置在
拖动启动上的监听器,并重新分配
设置在
拖动启动上的监听器
另一个选项是在拖动启动和拖动启动上设置标志,在做任何事情之前,让你的听众看一下这个标志:

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