Commit 8408f1e 1 parent 775bb98 commit 8408f1e Copy full SHA for 8408f1e
File tree 1 file changed +21
-11
lines changed
1 file changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -92,17 +92,27 @@ const LeaftletMap = ({
92
92
onGeoJsonGeometrySet ?. ( newFeatureLayer . toGeoJSON ( ) . geometry ) ;
93
93
} ;
94
94
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
+ ) ;
106
116
107
117
return (
108
118
< >
You can’t perform that action at this time.
0 commit comments