I'm trying to add popups to omnivore layers in Leaflet. I'm going to have a lot of these layers, so I want to write a function to add the same style and popup to each layer. Each of the layers needs to have its own popup text. I wrote the function, but when I try to run the code, I get "Uncaught TypeError: undefined is not a function".
This code won't work:
function stylize(place) {
this.setStyle({
color: '#f00',
opacity: 1
});
this.bindPopup(place);
this.addTo(mapLayer);
};
omnivore.gpx('place-a.gpx')
.on('ready', stylize('Place A'));
And this won't work:
omnivore.gpx('place-a.gpx')
.on('ready', function() {stylize('Place A');});
While this will:
function stylize() {
this.setStyle({
color: '#f00',
opacity: 1
});
this.bindPopup('Place A');
this.addTo(mapLayer);
};
omnivore.gpx('place-a.gpx')
.on('ready', stylize);
Why am I not able to add arguments to this function?