Skip to content

Commit 8408f1e

Browse files
committed
🐛 [open-formulieren/open-forms#5038] Missing map shapes in summary
Because the geoJsonGeometry is available before the featureGroupRef is set, can the useEffect hook not draw the map shapes
1 parent 775bb98 commit 8408f1e

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/components/Map/LeafletMap.jsx

+21-11
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,27 @@ const LeaftletMap = ({
9292
onGeoJsonGeometrySet?.(newFeatureLayer.toGeoJSON().geometry);
9393
};
9494

95-
useEffect(() => {
96-
// Remove all shapes from the map.
97-
// Only `geoJsonGeometry` should be shown on the map.
98-
featureGroupRef.current?.clearLayers();
99-
if (!geoJsonGeometry) {
100-
return;
101-
}
102-
// Add the current `geoJsonGeometry` as shape
103-
const layer = Leaflet.GeoJSON.geometryToLayer(geoJsonGeometry);
104-
featureGroupRef.current?.addLayer(layer);
105-
}, [geoJsonGeometry]);
95+
useEffect(
96+
() => {
97+
if (!featureGroupRef.current) {
98+
// If there is no feature group, nothing should be done..
99+
return;
100+
}
101+
102+
// Remove all shapes from the map.
103+
// Only `geoJsonGeometry` should be shown on the map.
104+
featureGroupRef.current.clearLayers();
105+
if (!geoJsonGeometry) {
106+
return;
107+
}
108+
// Add the current `geoJsonGeometry` as shape
109+
const layer = Leaflet.GeoJSON.geometryToLayer(geoJsonGeometry);
110+
featureGroupRef.current.addLayer(layer);
111+
},
112+
// `featureGroupRef.current` is needed as dependency to make sure that
113+
// the featureGroupRef can be used.
114+
[geoJsonGeometry, featureGroupRef.current]
115+
);
106116

107117
return (
108118
<>

0 commit comments

Comments
 (0)