Event after modifying polygon in Google Maps API v3

前端 未结 5 1770
借酒劲吻你
借酒劲吻你 2020-12-13 19:09

I made a mapping application that uses the drawing manager (and implements selectable shapes). The program works as follows: when finishing drawing the polygon after clickin

5条回答
  •  清歌不尽
    2020-12-13 19:24

    I solved it by calling .getPath() and putting the listener inside the listener which is called every time a shape is clicked. I think the Google API documentation is not very clear on how to use the set_at so it may be useful for other people too.

    // Add an event listener that selects the newly-drawn shape when the user
    // mouses down on it.
    var newShape = e.overlay;
    newShape.type = e.type;
    google.maps.event.addListener(newShape, 'click', function() {
        google.maps.event.addListener(newShape.getPath(), 'set_at', function() {
            console.log("test");
        });
    
        google.maps.event.addListener(newShape.getPath(), 'insert_at', function() {
            console.log("test");
        });
        setSelection(newShape);
    });
    

提交回复
热议问题