使用Google Maps API v3创建多边形时,如何防止多边形捕捉到其他地图'?
所以代替:
我想让多边形像这样关闭:
答案 0 :(得分:1)
当路径中2个连续点的经度之差>> 180
时,会出现问题前两个点的经度是-97和93,所以这个问题就是问题(差异是190)
到目前为止,我唯一可以建议的是分开这部分路径:
new google.maps.LatLng(81, -97),
//additional point
new google.maps.LatLng(80.5, -12),
new google.maps.LatLng(80, 93),
new google.maps.LatLng(56, 78),
new google.maps.LatLng(60, -94)
答案 1 :(得分:0)
有一次我也需要它,谢天谢地,Devs提供了研究,所以我与你分享
//Taking Example of Bermuda Triangle
function initialize() {
var mapOptions = {
zoom: 5,
center: new google.maps.LatLng(24.886436490787712, -70.2685546875),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var bermudaTriangle;
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
// Define the LatLng coordinates for the polygon's path.
var triangleCoords = [
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)
];
// Construct the polygon.
bermudaTriangle = new google.maps.Polygon({
paths: triangleCoords,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
bermudaTriangle.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
更多参考资料
https://developers.google.com/maps/documentation/javascript/examples/polygon-simple