diff options
Diffstat (limited to 'modern/src/map/SelectedGeofenceMap.js')
-rw-r--r-- | modern/src/map/SelectedGeofenceMap.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/modern/src/map/SelectedGeofenceMap.js b/modern/src/map/SelectedGeofenceMap.js new file mode 100644 index 0000000..2ed3a2d --- /dev/null +++ b/modern/src/map/SelectedGeofenceMap.js @@ -0,0 +1,29 @@ +import { useEffect } from 'react'; + +import { useSelector } from 'react-redux'; +import { map } from './Map'; +import { getGeofenceCenter } from './mapUtil'; + +const SelectedGeofenceMap = () => { + const mapCenter = useSelector((state) => { + console.log (state.geofences.selectedId); + if (state.geofences.selectedId) { + const geofence = state.geofences.items[state.geofences.selectedId] || null; + const center = getGeofenceCenter (geofence); + if (geofence) { + return { position: [center.longitude, center.latitude] }; + } + } + return null; + }); + + useEffect(() => { + if (mapCenter) { + map.easeTo({ center: mapCenter.position, zoom: 18 }); + } + }, [mapCenter]); + + return null; +}; + +export default SelectedGeofenceMap; |