I am learning Leaflet. I want to create a function that will request WMS feature info when the map is clicked. And I want to do this for different maps, each with their WMS layers.

I imagine I will have to create a function that takes wms_url and map_object as parameters in the function in map.on('click', function). But I don't know how to pass parameters to the function in .on(). It seems .on automatically passes event object as a parameter to the function, and I don't see how to add other parameters.

1 Answer 1


The .on function only takes the event parameter - but you can add a second callback function within the .on callback function. Like this:

function someOtherCallbackFunction(wms_url, map_object) {
  // console.log(wms_url, map_object)
  // whatever you like

myMap.on('click', function(e) {
  // console.log(e.latlng)
  // whatever you like
  someOtherCallbackFunction('http://wmsurl.etc', yourMapObj})

Having a unique callback with your wms url and the map instance will make this easy to apply to different maps. You can use the same callback on all the different maps, just modifying your parameters for each one.

Here's a quick codesandbox with this code in working order.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.