aboutsummaryrefslogtreecommitdiff
path: root/modern/src/main/MainMap.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-10-19 18:17:49 -0700
committerAnton Tananaev <anton@traccar.org>2022-10-19 18:17:49 -0700
commitb3b724dd8ccd7b2e6a7bb88465165b1ca54fe50d (patch)
tree315522f7d9188892643798b3b25d329bc7572fbb /modern/src/main/MainMap.js
parent6d733a77314eb2877689e652dd5a0da2737c42b0 (diff)
downloadtrackermap-web-b3b724dd8ccd7b2e6a7bb88465165b1ca54fe50d.tar.gz
trackermap-web-b3b724dd8ccd7b2e6a7bb88465165b1ca54fe50d.tar.bz2
trackermap-web-b3b724dd8ccd7b2e6a7bb88465165b1ca54fe50d.zip
Extract main map
Diffstat (limited to 'modern/src/main/MainMap.js')
-rw-r--r--modern/src/main/MainMap.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/modern/src/main/MainMap.js b/modern/src/main/MainMap.js
new file mode 100644
index 00000000..81d214f9
--- /dev/null
+++ b/modern/src/main/MainMap.js
@@ -0,0 +1,69 @@
+import React, { useCallback } from 'react';
+import { useTheme } from '@mui/material/styles';
+import useMediaQuery from '@mui/material/useMediaQuery';
+import { useDispatch, useSelector } from 'react-redux';
+import MapView from '../map/core/MapView';
+import MapSelectedDevice from '../map/main/MapSelectedDevice';
+import MapAccuracy from '../map/main/MapAccuracy';
+import MapGeofence from '../map/MapGeofence';
+import MapCurrentLocation from '../map/MapCurrentLocation';
+import PoiMap from '../map/main/PoiMap';
+import MapPadding from '../map/MapPadding';
+import { devicesActions } from '../store';
+import MapDefaultCamera from '../map/main/MapDefaultCamera';
+import usePersistedState from '../common/util/usePersistedState';
+import MapLiveRoutes from '../map/main/MapLiveRoutes';
+import MapPositions from '../map/MapPositions';
+import MapOverlay from '../map/overlay/MapOverlay';
+import MapGeocoder from '../map/geocoder/MapGeocoder';
+import MapScale from '../map/MapScale';
+import MapNotification from '../map/notification/MapNotification';
+import useFeatures from '../common/util/useFeatures';
+
+const MainMap = ({ filteredPositions, selectedPosition, onEventsClick }) => {
+ const theme = useTheme();
+ const dispatch = useDispatch();
+
+ const desktop = useMediaQuery(theme.breakpoints.up('md'));
+
+ const eventsAvailable = useSelector((state) => !!state.events.items.length);
+
+ const features = useFeatures();
+
+ const [mapLiveRoutes] = usePersistedState('mapLiveRoutes', false);
+
+ const onMarkerClick = useCallback((_, deviceId) => {
+ dispatch(devicesActions.select(deviceId));
+ }, [dispatch]);
+
+ return (
+ <>
+ <MapView>
+ <MapOverlay />
+ <MapGeofence />
+ <MapAccuracy positions={filteredPositions} />
+ {mapLiveRoutes && <MapLiveRoutes />}
+ <MapPositions
+ positions={filteredPositions}
+ onClick={onMarkerClick}
+ selectedPosition={selectedPosition}
+ showStatus
+ />
+ <MapDefaultCamera />
+ <MapSelectedDevice />
+ <PoiMap />
+ </MapView>
+ <MapScale />
+ <MapCurrentLocation />
+ <MapGeocoder />
+ {!features.disableEvents && (
+ <MapNotification enabled={eventsAvailable} onClick={onEventsClick} />
+ )}
+ {desktop && (
+ <MapPadding left={parseInt(theme.dimensions.drawerWidthDesktop, 10)} />
+ )}
+ </>
+ );
+};
+
+export default MainMap;