yagajs / leaflet-ng2

Angular.io integration of Leaflet
https://leaflet-ng2.yagajs.org
ISC License
66 stars 26 forks source link

BoxZoom events #388

Closed jochenjonc closed 6 years ago

jochenjonc commented 6 years ago

Is there a 'nice' way to subscribe to the boxzoomend event? Or is map.on("boxzoomend", function(e) { ... } the only solution?

The purpose it to list all markers that are in the zoombox bounds.

atd-schubert commented 6 years ago

I don't know the boxzoomend event, yet. Can you provide a link to the according documentation or source-code?

jochenjonc commented 6 years ago

Wel it's something I found on StackOverflow, but I can't find it in the leaflet API. https://stackoverflow.com/questions/17611596/multiple-marker-selection-within-a-box-in-leaflet

I can get it working via the following code:

    // Select multiple trucks
    const that = this;
    this.mapComponent.on('boxzoomend', function(event: any) {
      this.lastTrucksSelected = new Array();

      that.truckGroup.eachLayer(function (layer) {
        if (layer instanceof L.Marker) {
          if (event.boxZoomBounds.contains(layer.getLatLng())) {
            const truckMarker = layer as any;
            that.lastTrucksSelected.push(truckMarker.options.truckId);
          }
        }
      });
    });
atd-schubert commented 6 years ago

It seems that there is a BoxZoom handler, but it is not part of the documentation. We can add this event-handler to leaflet-ng2, also.