0
正如您在下面看到的,我有两个具有边的多边形。基本上2个三角形与他们各自的坐标。请参阅:使用Google Maps API合并多边形
function initialize() {
// Define the LatLng coordinates for the polygon's path.
var bounds = new google.maps.LatLngBounds();
var i;
var polygonCoords = [
new google.maps.LatLng(25.774252, -80.190262),
new google.maps.LatLng(18.466465, -66.118292),
new google.maps.LatLng(32.321384, -64.757370)
];
for (i = 0; i < polygonCoords.length; i++) {
bounds.extend(polygonCoords[i]);
}
var map = new google.maps.Map(document.getElementById("map_canvas2"), {
zoom: 4,
center: bounds.getCenter(),
mapTypeId: "roadmap"
});
var triangle1 = new google.maps.Polygon({
paths: polygonCoords,
strokeColor: '#0000ff',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#0000ff',
fillOpacity: 0.35
});
triangle1.setMap(map);
var polygonCoords2 = [
new google.maps.LatLng(25.774252, -80.190262),
new google.maps.LatLng(18.466465, -66.118292),
new google.maps.LatLng(14.979063, -83.500871)
];
var triangule2 = new google.maps.Polygon({
paths: polygonCoords2,
strokeColor: '#0000ff',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#0000ff',
fillOpacity: 0.35
});
triangule2.setMap(map);
}
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
<body onload="initialize()">
<div id="map_canvas2" style="height: 100vh; width:100vw"></div>
</body>
我想,这样的风险不会出现在两者之间的中间,从而使多边形与4个边或4个坐标合并两个三角形。什么是最好的方法来做到这一点?
更换
paths: polygonCoords,
是它预计是到坐标被合并为一个(即在波多黎各和佛罗里达州的点)总是相同的坐标只是不同折线的一部分?希望这是有道理的 –