2014-03-29 108 views
3

使用Google Maps API v3創建多邊形時,如何防止多邊形貼齊到其他「地圖」?Google Maps API v3多邊形關閉

所以不是: enter image description here

我想提出的多邊形接近這樣的: enter image description here

+0

你能告訴我們你正在使用的多邊形座標嗎? –

+0

您可以很容易地重現該問題,例如:http://the-di-lab.com/polygon但是,您可以: – Laurent

+0

(81,-97)(80,93)(56,78)(60, -94) – Laurent

回答

1

的問題,當在所述路徑的連續的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) 

演示:http://jsfiddle.net/doktormolle/39CtV/

+0

因此,我應該總是使用6來代替4點,以防止多邊形連接到其他地圖。爲了防止在Y軸上出現相同的行爲,是否需要使用8? – Laurent

+0

http://jsfiddle.net/39CtV/1/ – Laurent

+0

它不應該是Y軸的祕密。這也不是點數的問題(只要你不想繪製跨越日期線的多邊形,分割每個部分只會起作用)。 –

0

有一次,我也需要它,幸運的是離散事件已提供有研究,所以我共享隨着你

//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

+0

這對於座標'(81,-97)(80,93)(56,78)(60,94)' –

+0

爲什麼就像例子引用改變方法Latlng的位置來改變多邊形路徑的座標 –

+0

用這些座標試着看看結果。 –

相關問題