Reputation: 1004
i'am working on a mapbox porjekt and with javascript i read out a kml file and add a custom icons, it works but i get this error in the browser console:
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
here the js code:
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);
this line causes the error:
marker.setIcon( greenIcon);
why is that error message? thanks!
Upvotes: 0
Views: 426
Reputation: 11882
marker.setIcon( greenIcon);
Though it's impossible to tell without your data, it's very likely that the problem is that this code has the hard assumption that your KML data only contains markers, since you're calling .setIcon
on every layer. So, you probably have a line or polygon in the mix, and since lines and polygons don't have icons, they don't have the .setIcon
method, hence the error message.
Upvotes: 2