I'm struggling with a problem in the Leaflet.contextmenu
library.
I got a number of different maps, saved in a global Array. Then I'm using the contextmenu
options to have a contextmenu
in my maps. When I want to define my callback functions, I can't access my arrMap[id]
, because the function doesn't know the id
I'm using.
My question here is: How can I give an object (the id
, for example) into a callback function of the Leaflet.contextmenu
library?
function x(){
arrMap[id] = new L.map('map'+id,{
contextmenu: true,
contextmenuWidth: 140,
contextmenuItems: [{
text: 'Messung an dieser Position einfügen',
callback: newMeasurement
}, {
text: 'zeige Koordinaten',
callback: showCoordinates
}, {
text: 'Karte hier zentrieren',
callback: centerMap
}]
});
}
function newMeasurement(e){
//do something with e AND ID
}
I thought about something like:
//function x(){...
callback: newMeasurement(e,id)
//...}
function newMeasurement(e,id){
console.log(id);
}
...but that's not working :(
Thanks everybody for the help!