2017-04-07 101 views
-2

我試圖在點擊時更改Google地圖多邊形fillColor。 這裏是我的代碼=>https://jsfiddle.net/nw6j52f6/使用javascript更改多邊形fillColor(谷歌地圖)

這裏是代碼的問題部分。 應該改變多邊形的設計功能:

function polyopt(i) { 
setOptions({ 
    strokeColor: '#FF0000', strokeOpacity: 0.8, 
    strokeWeight: 3, fillColor: '#FF0000', fillOpacity: 0.35 
}); 
} 

但控制檯返回此錯誤:

map-array.html:56 Uncaught ReferenceError: setOptions is not defined 
at polyopt (map-array.html:56) 
at HTMLInputElement.onclick (map-array.html:69) 

我使用谷歌地圖API https://developers.google.com/maps/documentation/javascript/reference#PolygonOptions

,但我不明白爲什麼控制檯顯示此錯誤。如果多邊形是

+0

你在哪裏調用'polyopt'功能,和你有什麼傳遞給它? – duncan

+0

https://jsfiddle.net/nw6j52f6/ 這是整個代碼。我在74行調用polyopt函數

+0

'onclick =「polyopt()」' - 您不會傳遞任何參數給該函數可用於確定要更改的多邊形。 – duncan

回答

0

i必須使用i.setOptions

function polyopt(i) { 
    i.setOptions({ 
    strokeColor: '#FF0000', strokeOpacity: 0.8, 
    strokeWeight: 3, fillColor: '#FF0000', fillOpacity: 0.35 
}); 
+0

同樣的錯誤: 遺漏的類型錯誤:在HTMLInputElement.onclick(地圖array.html:63) :無法讀取性能在polyopt的不確定 「setOptions」(51地圖array.html) –

+0

似乎已經不確定的,而不是一個有效的多邊形..你myst通過一個有效的多邊形在var(i)..檢查你的代碼,你創建多邊形和調用funcion – scaisEdge

+0

我有5個多邊形在陣列 var layers = []; layers [1] = new google.maps.KmlLayer({url:'http://googlemaps.github.io/js-v2-samples/ggeoxml/cta.kml', map:gmap}); layers [2] = new google.maps.KmlLayer({url:'http://***.com/testovoo.kml', map:null}); –