I try to rewrite the boxzoom event, like this,
map.on('boxzoomend', function(e) {
console.log('end')
})
However, the boxzoom still zoomed and I have no idea how to stop it and just print text in console. I hope to rewrite boxzoom as the following
- Stop from zooming
- Print text in console
Can you provide correct way to rewrite the event? Thank you.
The zooming is not performed in the
boxzoomend
event, but rather in the BoxZoom handler. Let me quote the Leaflet source code fromsrc/map/handler/Map.BoxZoom.js
:A better way to achieve the functionality you want is to create a new handler that extends the BoxZoom handler, modifying the methods that you need.
I recommend that you read the Leaflet tutorials, specially the ones on creating Leaflet plugins before doing this.
The idea is to extend the BoxZoom handler:
...modifying the _onMouseUp method...
...so that instead of zooming, it just prints things:
And as the tutorial explains, hook the handler and provide some map options for it:
While we're at it, disable the default BoxZoom handler for all map instances by default:
The whole thing would look like in this working example.