gpt4 book ai didi

javascript - gmaps.js - 绘制多边形

转载 作者:行者123 更新时间:2023-12-03 02:10:58 28 4
gpt4 key购买 nike

我正在使用 gmaps.js,我可以使用此代码绘制多边形

var paths = [];
function drawPoly(p1, p2) {
paths.push([p1, p2]);
console.log(paths);

oldPolygon = null;

map.drawPolygon({
paths: paths,
strokeColor: '#432070',
strokeOpacity: 1,
strokeWeight: 3,
fillColor: '#432070',
fillOpacity: 0.6
});
}

但我的问题是它们相互重叠,导致 enter image description here

我的问题是如何删除重叠的多边形(旧多边形),以便剩余的多边形将是最后生成的多边形。我希望我解释得很好。谢谢。

最佳答案

解决我的问题的方法是使用 map.removePolygon 方法:

var paths = [];
var oldPolygon;
function drawPoly(p1, p2) {
paths.push([p1, p2]);
console.log(paths);

polygons = map.drawPolygon({
paths: paths,
strokeColor: '#432070',
strokeOpacity: 1,
strokeWeight: 3,
fillColor: '#432070',
fillOpacity: 0.6
});

// remove old one if exists.
if(oldPolygon != null){
map.removePolygon(oldPolygon);
}

// ... and save a reference to the new polygon for next time around.
oldPolygon = polygons;
}

关于javascript - gmaps.js - 绘制多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49575444/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com