我想在这个问题Extract drawingManager polygon path Google Maps on click中修改代码。我想通过DOM按钮触发协调更新 下面是原始代码,它的效果非常好:
function exportCoor(overlay){
google.maps.event.addListener(overlay, "mouseup", function(event) {
$('#textarea').val(overlay.getPath().getArray());
});
function initialize(){
//some code
google.maps.event.addListener(drawManager, 'overlaycomplete', function (event) {
exportCoor (event.overlay);
}
}
我想要这样想:
function exportCoor(overlay){
google.maps.event.addDomListener(exportBtn, "click", function(event) {
$('#textarea').val(overlay.getPath().getArray());
});
function initialize(){
//some code
...
或
function exportCoor(overlay){
$("#exportBtn").click(function(event) {
$('#textarea').val(overlay.getPath().getArray());
});
首先两个都不起作用。请问,有人可以建议任何解决方案吗?
Thx,Jakub
答案 0 :(得分:0)
您需要遍历顶点(并且您需要对多边形的引用:
$('#save').click(function(){
vertices = "";
for (var i=0; i<polygons.length; i++) {
vertices += "polygon "+i+"<br>";
for (var j=0; j<polygons[i].getPath().getLength(); j++) {
vertices += polygons[i].getPath().getAt(j).toUrlValue(6)+"<br>";
}
}
document.getElementById('verticesclick').innerHTML = vertices;
});