[英]Google Maps API v3 Polygon closing
使用Google Maps API v3創建多邊形時,如何防止多邊形捕捉到其他“地圖”?
所以代替:
我想讓多邊形像這樣關閉:
當路徑中2個連續點的經度之差> = 180時,會出現問題
前2點的經度是-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)
有一次我也需要它,謝天謝地,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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.