aboutsummaryrefslogtreecommitdiff
path: root/modern/src/map/MapDirection.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-03 09:08:31 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-03 09:08:31 -0700
commitaed55c77c58d74879dd9acedbab8965233d47aa3 (patch)
tree8eab4b729100aab5e5f13d7a35a2d2288feb477a /modern/src/map/MapDirection.js
parent7d521e8411dbeb9ca6bbeb98453145b44c7e5913 (diff)
downloadtrackermap-web-aed55c77c58d74879dd9acedbab8965233d47aa3.tar.gz
trackermap-web-aed55c77c58d74879dd9acedbab8965233d47aa3.tar.bz2
trackermap-web-aed55c77c58d74879dd9acedbab8965233d47aa3.zip
Selected device direction (fix #924)
Diffstat (limited to 'modern/src/map/MapDirection.js')
-rw-r--r--modern/src/map/MapDirection.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/modern/src/map/MapDirection.js b/modern/src/map/MapDirection.js
new file mode 100644
index 00000000..251fa962
--- /dev/null
+++ b/modern/src/map/MapDirection.js
@@ -0,0 +1,57 @@
+import { useEffect } from 'react';
+
+import { map } from './core/MapView';
+
+const MapDirection = ({ position }) => {
+ const id = 'directions';
+
+ useEffect(() => {
+ map.addSource(id, {
+ type: 'geojson',
+ data: {
+ type: 'FeatureCollection',
+ features: [],
+ },
+ });
+ map.addLayer({
+ id,
+ type: 'symbol',
+ source: id,
+ layout: {
+ 'icon-image': 'direction',
+ 'icon-rotate': ['get', 'rotation'],
+ },
+ });
+
+ return () => {
+ if (map.getLayer(id)) {
+ map.removeLayer(id);
+ }
+ if (map.getSource(id)) {
+ map.removeSource(id);
+ }
+ };
+ }, []);
+
+ useEffect(() => {
+ map.getSource(id).setData({
+ type: 'FeatureCollection',
+ features: [
+ {
+ type: 'Feature',
+ geometry: {
+ type: 'Point',
+ coordinates: [position.longitude, position.latitude],
+ },
+ properties: {
+ rotation: position.course,
+ },
+ },
+ ],
+ });
+ }, [position]);
+
+ return null;
+};
+
+export default MapDirection;