From 3e8a09ef5cc493ffb1532b0400dff2de6f0aec2c Mon Sep 17 00:00:00 2001 From: Henri Nieminen Date: Tue, 30 Jul 2024 13:17:05 +0300 Subject: [PATCH] fix leaflet typing issues --- src/areaNote/components/AreaNotesEditMap.tsx | 15 ++++++++++----- src/util/map.ts | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/areaNote/components/AreaNotesEditMap.tsx b/src/areaNote/components/AreaNotesEditMap.tsx index 69a3c46d9..53d91a236 100644 --- a/src/areaNote/components/AreaNotesEditMap.tsx +++ b/src/areaNote/components/AreaNotesEditMap.tsx @@ -71,11 +71,16 @@ class AreaNotesEditMap extends Component { if (!isEmpty(geoJSON)) { const featuresGeoJSON = new L.GeoJSON(geoJSON); - featuresGeoJSON.eachLayer(layer => { - layer.options.color = SHAPE_COLOR; - layer.options.fillOpacity = SHAPE_FILL_OPACITY; - this.featureGroup?.leafletElement.addLayer(layer); - layer.showMeasurements(); + featuresGeoJSON.eachLayer((layer) => { + if (layer instanceof L.Polyline || layer instanceof L.Polygon || layer instanceof L.Circle) { + layer.setStyle({ + "color": SHAPE_COLOR, + "fillOpacity": SHAPE_FILL_OPACITY} + ); + this.featureGroup?.leafletElement.addLayer(layer); + layer.showMeasurements(); + } + }); this.setState({ isValid: true diff --git a/src/util/map.ts b/src/util/map.ts index 8f6e0dc7d..37b72768b 100644 --- a/src/util/map.ts +++ b/src/util/map.ts @@ -1,4 +1,5 @@ import isArray from "lodash/isArray"; +import type { LatLngBounds } from "leaflet"; /** * Translate leaflet draw literals in Finnish @@ -123,7 +124,7 @@ export const getBoundsFromBBox = (bbox: Array>): Record): Record => { +export const getBoundsFromCoordinates = (coordinates: Array): LatLngBounds => { const L = require('leaflet'); const lats = [],