Skip to content

Commit

Permalink
Add invalid bounds checking
Browse files Browse the repository at this point in the history
In some cases there can be layers without bounds, for example, empty polylines (in general - paths) made for dynamic changes or workarounds, like makinacorpus/Leaflet.TextPath#83. This fix prevents later exceptions on bounds relation calculation.
  • Loading branch information
Azbesciak committed Jul 28, 2021
1 parent 19278ea commit a6d768d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/calc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export function getLayersInPolygon(polygon: L.Polygon, layers: L.Layer[], option
layerGeometry = layerToGeoJSONGeometry(layer, options);
layerBounds = geoJSONGeometryToBounds(layerGeometry);
}

// some bounds may be invalid, for example for empty polylines
if (!layerBounds?.isValid())
return false;
const boundsResult = options.intersect ?
polygonBounds.intersects(layerBounds) :
polygonBounds.contains(layerBounds);
Expand All @@ -85,4 +87,4 @@ export function getLayersInPolygon(polygon: L.Polygon, layers: L.Layer[], option
});

return selectedLayers;
}
}

0 comments on commit a6d768d

Please sign in to comment.