带有“孔"的 Google Maps API 多边形在中心 [英] Google Maps API Polygon with "Hole" In Center
问题描述
在另一个多边形内插入一个多边形应该会在中心形成一个洞"(参见谷歌地图五角大楼示例).但是,我的程序始终无法打孔,而是在内部插入了两层多边形线.
Inserting a polygon inside another polygon is supposed to make a "hole" in the center (see the Google maps Pentagon example). However, my program keeps failing to make a hole and instead makes two layers of polygon lines insead.
http://cl.ly/1c243E1V1G2M1D3H3c0O <-- 我的地图图像
http://cl.ly/1c243E1V1G2M1D3H3c0O <-- image of my map
有人说改变坐标顺序解决了他们的问题,所以我在他们的例子中准确地选择了谷歌给出的百慕大三角形的坐标,但是,它有我以前遇到的同样问题.相关代码如下:
Someone said changing the coordinate order fixed their problem so I selected exactly the coordinates of the bermuda triangle as given by Google in their example, however, it had the same problem I encountered before. The relevant code is below:
var everythingElse = [
new google.maps.LatLng(25.774252, -82.190262),
new google.maps.LatLng(17.466465, -65.118292),
new google.maps.LatLng(34.321384, -63.75737),
new google.maps.LatLng(25.774252, -82.190262)
];
var circleOverlay = [
new google.maps.LatLng(25.774252, -80.190262),
new google.maps.LatLng(18.466465, -66.118292),
new google.maps.LatLng(32.321384, -64.75737),
new google.maps.LatLng(25.774252, -80.190262)
];
PropertySearch.tintPolygon = new google.maps.Polygon({
paths: [ everythingElse, circleOverlay ],
strokeColor: "#000000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#000000",
fillOpacity: 0.5
});
PropertySearch.tintPolygon.setMap(PropertySearch.map);
推荐答案
这确实是多边形中索引方向的问题,一个是顺时针方向,另一个应该是逆时针方向.将您的第二个数组更改为:
It really is a matter of direction of indices in your polygons, while one is clockwise other should be counter-clockwise. Change your second array to:
var circleOverlay = [
new google.maps.LatLng(25.774252, -80.190262),
new google.maps.LatLng(32.321384, -64.75737), //second and third coordinates
new google.maps.LatLng(18.466465, -66.118292), //are swapped compared to your original
new google.maps.LatLng(25.774252, -80.190262)
];
它会在你的三角形中显示一个漂亮的洞
and it will display a nice hole in your triangle
这篇关于带有“孔"的 Google Maps API 多边形在中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!