aboutsummaryrefslogtreecommitdiff
path: root/modern/src/map/MapCamera.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-08-02 07:11:16 -0700
committerAnton Tananaev <anton@traccar.org>2022-08-02 07:11:16 -0700
commitf57d9020d5031744e3e0e19ac8178cc8f7010f03 (patch)
tree4140037469ff44a7ce91b255d4142189e4832116 /modern/src/map/MapCamera.js
parent91c121647293dd04daf8c932371dbe7f17e96f98 (diff)
downloadtrackermap-web-f57d9020d5031744e3e0e19ac8178cc8f7010f03.tar.gz
trackermap-web-f57d9020d5031744e3e0e19ac8178cc8f7010f03.tar.bz2
trackermap-web-f57d9020d5031744e3e0e19ac8178cc8f7010f03.zip
Refactor map route plugin
Diffstat (limited to 'modern/src/map/MapCamera.js')
-rw-r--r--modern/src/map/MapCamera.js26
1 files changed, 19 insertions, 7 deletions
diff --git a/modern/src/map/MapCamera.js b/modern/src/map/MapCamera.js
index 7ebf24fb..63f070f8 100644
--- a/modern/src/map/MapCamera.js
+++ b/modern/src/map/MapCamera.js
@@ -1,16 +1,28 @@
import { useEffect } from 'react';
-
+import maplibregl from 'maplibre-gl';
import { map } from './core/MapView';
const MapCamera = ({
- latitude, longitude,
+ latitude, longitude, positions,
}) => {
useEffect(() => {
- map.jumpTo({
- center: [longitude, latitude],
- zoom: Math.max(map.getZoom(), 10),
- });
- }, [latitude, longitude]);
+ if (positions) {
+ const coordinates = positions.map((item) => [item.longitude, item.latitude]);
+ if (coordinates.length) {
+ const bounds = coordinates.reduce((bounds, item) => bounds.extend(item), new maplibregl.LngLatBounds(coordinates[0], coordinates[1]));
+ const canvas = map.getCanvas();
+ map.fitBounds(bounds, {
+ padding: Math.min(canvas.width, canvas.height) * 0.1,
+ duration: 0,
+ });
+ }
+ } else {
+ map.jumpTo({
+ center: [longitude, latitude],
+ zoom: Math.max(map.getZoom(), 10),
+ });
+ }
+ }, [latitude, longitude, positions]);
return null;
};