问题描述
我有这个 DrawingManager 对象:
I have this DrawingManager Object:
drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.POLYGON,
markerOptions: {
draggable: true
},
polylineOptions: {
editable: true
},
polygonOptions: polyOptions,
map: map
});
当一个多边形完成时,我得到他们的坐标:
And when a Polygon is completed I get their coords with:
google.maps.event.addListener(drawingManager, 'polygoncomplete', function (polygon) {
var coordinates = (polygon.getPath().getArray());
console.log(coordinates);
});
但是,如果我使用 DrawingManager 更改多边形,显然形状会改变,可能会添加更多点..
那么如何在修改后获取所有点及其坐标,例如单击按钮以完成编辑??提前致谢.
But if I change the polygon using DrawingManager obviously the shape will change, maybe adding more Points..
Then How can I get all Points with their coords after modify it and for example click a button to finish the edition?? Thanks in advance.
推荐答案
好的,我的第二个代码有了答案:
Ok having the answer on my second code:
var coordinates = (polygon.getPath().getArray());
最后,我通过添加一个监听器来调用获取数组的函数,从而得到了最后一个带有坐标的数组:
Finally I got the last array with coordinates calling this code by adding a listener to call a function that get the array:
JS
function getCoordinates() {
console.log(polygon.getPath().getArray());
}
google.maps.event.addDomListener(document.getElementById('CoordsButton'), 'click', getCoordinates);
HTML
<button id="CoordsButton">Coordinates</button>
然后当现在点击按钮时,我得到了坐标...
Then when the button is clicked now I get the coords...
还是谢谢
这篇关于如何获取修改后的绘图管理器形状的点坐标?谷歌地图 API v3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!