如何获取修改后的绘图管理器形状的点坐标? GoogleMaps API v3 [英] How to get point coordinates of a modified drawingManager shape? GoogleMaps API v3

查看:130
本文介绍了如何获取修改后的绘图管理器形状的点坐标? GoogleMaps API v3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个DrawingManager对象:

  drawingManager = new google.maps.drawing.DrawingManager({
drawingMode :google.maps.drawing.OverlayType.POLYGON,
markerOptions:{
draggable:true
},
polylineOptions:{
editable:true
} ,
polygonOptions:polyOptions,
map:map
});

当一个Polygon完成时,我得到它们的和弦:

  google.maps.event.addListener(drawingManager,'polygoncomplete',function(polygon){
var coordinates =(polygon.getPath()。getArray ));
console.log(coordinates);
});

但是如果我使用DrawingManager更改多边形,显然形状会改变,也许会添加更多的点。< br>然后如何修改它,并且例如点击一个按钮来完成这个版本,我怎样才能得到所有点与他们的坐标?提前致谢。

解决方案

好的,我的第二个代码有答案:

  var coordinates =(polygon.getPath()。getArray()); 

最后,我通过添加一个侦听器来调用一个函数,数组:

JS

 函数getCoordinates(){
console.log(polygon.getPath()。getArray());
}

google.maps.event.addDomListener(document.getElementById('CoordsButton'),'click',getCoordinates);

HTML

 < button id =CoordsButton>坐标< / button> 

然后当按钮被点击时,我得到了坐标......

非常感谢

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

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...

Thanks anyway

这篇关于如何获取修改后的绘图管理器形状的点坐标? GoogleMaps API v3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆