将事件侦听器应用于可编辑的多边形 [英] Apply event listener to an editable polygon
问题描述
如何在用户更改边界时将事件侦听器添加到Google maps可编辑多边形?
我尝试了下面的代码。 p>
代码片段(来自链接的小提琴): data-lang =jsdata-hide =truedata-console =falsedata-babel =false>
html,body {height:100%;保证金:0; padding:0;}#map {height:100%;}
< div id =map>< / div>< script> var PolygonPath;函数initMap(){var map = new google.maps.Map(document.getElementById('map'),{zoom:8,center:{lat:0,lng:0}}); PolygonPath = new google.maps.Polygon({strokeColor:'#FF8C00',strokeOpacity:1.0,strokeWeight:3,editable:true,// geodesic:true,map:map});的console.log(PolygonPath); google.maps.event.addListener(map,'click',function(e){addLatLng(e);}); google.maps.event.addListener(PolygonPath,'drag',function(e){window.alert(Hi);}); } function addLatLng(event){pathLine = PolygonPath.getPath(); pathLine.push(event.latLng); // ValueUnit = google.maps.geometry.spherical.computeArea(pathLine); }< / script>< script src =https://maps.googleapis.com/maps/api/js?libraries=geometry&callback=initMapasync defer>< / script>