diff --git a/src/components/Map/index.jsx b/src/components/Map/index.jsx index 841083f31..9ace49cc4 100644 --- a/src/components/Map/index.jsx +++ b/src/components/Map/index.jsx @@ -69,6 +69,15 @@ const useDefaultCoordinates = () => { return [latitude, longitude]; }; +const getCoordinates = geoJsonFeature => { + if (!geoJsonFeature) { + return null; + } + + const center = Leaflet.geoJSON(geoJsonFeature).getBounds().getCenter(); + return [center.lat, center.lng]; +}; + const LeaftletMap = ({ geoJsonFeature, onGeoJsonFeatureSet, @@ -81,7 +90,8 @@ const LeaftletMap = ({ const featureGroupRef = useRef(); const intl = useIntl(); const defaultCoordinates = useDefaultCoordinates(); - const coordinates = defaultCoordinates; + const geoJsonCoordinates = getCoordinates(geoJsonFeature); + const coordinates = geoJsonCoordinates ?? defaultCoordinates; const modifiers = disabled ? ['disabled'] : []; const className = getBEMClassName('leaflet-map', modifiers); @@ -142,11 +152,7 @@ const LeaftletMap = ({ }} /> - {coordinates ? ( - <> - - - ) : null} + {coordinates && } {/*{disabled ? : }*/} - {/*{markerCoordinates && markerCoordinates.length && (*/} - {/* */} - {/*)}*/} + {geoJsonCoordinates && geoJsonCoordinates.length && ( + + )} ); };