Apply event listener to an editable polygon

后端 未结 1 1311
不知归路
不知归路 2021-01-27 19:15

How to add a event listener to a google maps editable Polygon when the user changes its boundary?

I tried the code below. Here is a Fiddle example

google         


        
1条回答
  •  情书的邮戳
    2021-01-27 19:38

    You need to add the event listener to the Polygon's path:

    google.maps.event.addListener(PolygonPath.getPath(), 'insert_at', function(evt) {
      document.getElementById('info').innerHTML = PolygonPath.getPath().getAt(evt).toUrlValue(6);
    });
    

    There are three interesting events on an MVCArray (as they apply to a Polygon path):

    • insert_at - add a vertex
    • remove_at - delete a vertex
    • set_at - change a vertex

    code snippet implementing insert_at and set_at listeners on the Polygon path:

    html,
    body {
      height: 100%;
      margin: 0;
      padding: 0;
    }
    #map {
      height: 100%;
    }

    0 讨论(0)
提交回复
热议问题