Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Event Handler for Multiple Events in Leaflet

Is it possible to create a trigger for multiple events in this manner?

map.on('click, dragstart, zoomstart', eventHandler);

If not what will be the next best way to trigger the same event handler for multiple events?

map.on('click', eventHandler);
map.on('dragstart', eventHandler);
map.on('zoomstart', eventHandler);
like image 357
Nyxynyx Avatar asked Feb 03 '13 22:02

Nyxynyx


1 Answers

It is possible, just remove the comma's:

map.on('click dragstart zoomstart', eventHandler);

function eventHandler(e) {
    console.log(e.type); //shows event type, i.e. "click", "dragstart" etc.
}
like image 192
adeneo Avatar answered Oct 29 '22 15:10

adeneo