aboutsummaryrefslogtreecommitdiff
path: root/modern/src/map/DefaultCameraMap.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-08 11:29:16 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-08 11:29:16 -0700
commit15d7000b16e90db68f52931cc16dfa3ebbd74114 (patch)
treeac336a1ea285fdbc536f71556e473767d6e3c8e2 /modern/src/map/DefaultCameraMap.js
parentbe0409f7e855cecceb4e38db611afd3beca255ff (diff)
downloadtrackermap-web-15d7000b16e90db68f52931cc16dfa3ebbd74114.tar.gz
trackermap-web-15d7000b16e90db68f52931cc16dfa3ebbd74114.tar.bz2
trackermap-web-15d7000b16e90db68f52931cc16dfa3ebbd74114.zip
Reorganize map folder
Diffstat (limited to 'modern/src/map/DefaultCameraMap.js')
-rw-r--r--modern/src/map/DefaultCameraMap.js52
1 files changed, 0 insertions, 52 deletions
diff --git a/modern/src/map/DefaultCameraMap.js b/modern/src/map/DefaultCameraMap.js
deleted file mode 100644
index 9b501ce5..00000000
--- a/modern/src/map/DefaultCameraMap.js
+++ /dev/null
@@ -1,52 +0,0 @@
-import maplibregl from 'maplibre-gl';
-import { useEffect, useState } from 'react';
-import { useSelector } from 'react-redux';
-import { usePreference } from '../common/preferences';
-import { map } from './Map';
-
-const DefaultCameraMap = () => {
- const selectedDeviceId = useSelector((state) => state.devices.selectedId);
- const positions = useSelector((state) => state.positions.items);
-
- const defaultLatitude = usePreference('latitude');
- const defaultLongitude = usePreference('longitude');
- const defaultZoom = usePreference('zoom');
-
- const [initialized, setInitialized] = useState(false);
-
- useEffect(() => {
- if (selectedDeviceId) {
- setInitialized(true);
- } else if (!initialized) {
- if (defaultLatitude && defaultLongitude) {
- map.jumpTo({
- center: [defaultLongitude, defaultLatitude],
- zoom: defaultZoom,
- });
- setInitialized(true);
- } else {
- const coordinates = Object.values(positions).map((item) => [item.longitude, item.latitude]);
- if (coordinates.length > 1) {
- const bounds = coordinates.reduce((bounds, item) => bounds.extend(item), new maplibregl.LngLatBounds(coordinates[0], coordinates[0]));
- const canvas = map.getCanvas();
- map.fitBounds(bounds, {
- duration: 0,
- padding: Math.min(canvas.width, canvas.height) * 0.1,
- });
- setInitialized(true);
- } else if (coordinates.length) {
- const [individual] = coordinates;
- map.jumpTo({
- center: individual,
- zoom: Math.max(map.getZoom(), 10),
- });
- setInitialized(true);
- }
- }
- }
- }, [selectedDeviceId, initialized, defaultLatitude, defaultLongitude, defaultZoom, positions]);
-
- return null;
-};
-
-export default DefaultCameraMap;