As the title suggests, I am somewhat unable to figure out the correct syntax for this function.
Currently, I have an event listener on a map that fires a function when the map is clicked as seen below:
map.on("click",(event)=>addMarker(event,parameter))
This is fine, but I want to combine the function fired into one complete function. I am aware it can be done such that I don't have to define the event outside of the addMarker
function. Rather, I want to define the event within the addMarker
function such that I only have the single function that is fired once the map is clicked.
Below is what I am trying to achieve (it's not the correct syntax):
map.on("click",addMarker(map))
and the addMarker function is:
const addMarker = (event) => (parameter) =>{
new mapboxgl.addMarker({}).setLngLat(coords).addTo(parameter)
}
can anyone help with the proper syntax of the proposed addMarker function? When I do it this way I get the error "Cannot read properties of undefined (reading:"lng")"