diff --git a/src/calc.ts b/src/calc.ts index 73bdc66..616981e 100644 --- a/src/calc.ts +++ b/src/calc.ts @@ -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); @@ -85,4 +87,4 @@ export function getLayersInPolygon(polygon: L.Polygon, layers: L.Layer[], option }); return selectedLayers; -} \ No newline at end of file +}