2014-06-30 64 views
0

我'上mapbox porjekt和使用JavaScript,我讀出了KML文件,並添加自定義圖標,它的工作原理,但我得到這個錯誤在瀏覽器控制檯:mapbox JavaScript的自定義圖標

Uncaught TypeError: undefined is not a function mytilemillscript.js:565 
(anonymous function) mytilemillscript.js:565 
s.LayerGroup.s.Class.extend.eachLayer mapbox.js:2 
(anonymous function) mytilemillscript.js:564 
s.Mixin.Events.fireEvent mapbox.js:1 
t leaflet-omnivore.min.js:1 
o 

這裏的js代碼:

var greenIcon = L.icon({ 
    iconUrl: 'icon/bergbahn_pitztalgletscher.svg', 
    iconSize:  [38, 95], // size of the icon 
    iconAnchor: [22, 94], 
    popupAnchor: [-3, -76], 
    shadowAnchor: [22, 94] 

}); 


runLayer = omnivore.kml('data/InntalradwegImst-SilzRundeTour14-02.kml').on('ready', function() { 

runLayer.eachLayer(function(marker) { 
    marker.setIcon(greenIcon); 
}); 

}) .addTo(map); 

此行導致錯誤:

marker.setIcon(greenIcon); 

爲什麼是錯誤messag è? 謝謝!

+0

什麼是565? – durrrutti

+0

對不起,它的那一行marker.setIcon(greenIcon); – miholzi

+0

您的KML的外觀如何? – geocodezip

回答

2
marker.setIcon(greenIcon); 

雖然這是不可能說沒有你的數據,這是非常有可能的問題是,這種代碼有硬假設您的KML數據只包含標記,因爲你在每一層調用.setIcon。所以,你可能在混合中有一條線或多邊形,並且由於線和多邊形沒有圖標,所以它們沒有.setIcon方法,因此是錯誤消息。