Rewrite leaflet

I am trying to rewrite a boxzoom event like

map.on('boxzoomend', function(e) {
    console.log('end')
})

However, boxzoom is still scalable, and I have no idea how to stop it and just print the text in the console. I hope to rewrite boxzoom as follows

  • Stop from scaling
  • Print text in the console

Can you provide the correct way to rewrite an event? Thank.

0
source share
1 answer

Scaling is not performed in the event boxzoomend, but rather in the BoxZoom handler. Let me give the source code of the leaflet fromsrc/map/handler/Map.BoxZoom.js :

_onMouseUp: function (e) {

    ...

    this._map
        .fitBounds(bounds)
        .fire('boxzoomend', {boxZoomBounds: bounds});
},

, BoxZoom, , .

, , , .

BoxZoom:

L.Map.BoxPrinter = L.Map.BoxZoom.extend({

... _onMouseUp...

    _onMouseUp: function (e) {

... :

        ...
        console.log(bounds);
        this._map.fire('boxzoomend', {boxZoomBounds: bounds});
   }
}

, :

L.Map.mergeOptions({boxPrinter: true});
L.Map.addInitHook('addHandler', 'boxPrinter', L.Map.BoxPrinter);

, BoxZoom :

L.Map.mergeOptions({boxZoom: false});

.

+3

Source: https://habr.com/ru/post/1680625/


All Articles