I have been trying to select multiple polygons using box select. I have modified box zoom for this purpose and included turf.js for intersect function. The problem is if i select a particular area and use interset function it shows polygons from different area. If i select two polygons it show four polygons from another area.below is my code

Tried postgis intersection, bounds intersect in leaflet, turf intersect all results in same.

Note - geojson data contains 7000 polygons.

 $(function() {
        L.Map.BoxZoom.prototype._onMouseUp = function (e) {

            if (!this._moved) { return; }

             var nw = this._map.layerPointToLatLng(this._startLayerPoint);
            var se = this._map.layerPointToLatLng(this._map.mouseEventToContainerPoint(e));
            var bounds = new L.LatLngBounds(nw,se);

function getparcels(bounds) {
       var geodata = L.rectangle(bounds).toGeoJSON();
       geojsonlayer = L.geoJson(Data, {
          onEachFeature: function (feature, layer) {
                      fillColor: 'black',
                      fillOpacity: 0.3
                }catch (e) {

need a function to select multiple polygons by box-selections

  • Formally it looks OK. Did you try to debug and step through layer selection to find out why wrong layer is selected as being intersected? – TomazicM May 5 at 9:32
  • It's hard to know what "another area" exactly means without seeing a MCVE – IvanSanchez May 6 at 7:29

Your Answer

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

Browse other questions tagged or ask your own question.