diff options
author | Anton Tananaev <anton@traccar.org> | 2022-08-21 12:54:25 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-08-21 12:54:25 -0700 |
commit | 4cce933164ace68833a07da463997e53226c1b6a (patch) | |
tree | 3f29997490a4f2d9b79305933a84a7efe1bbc9e3 /modern/src/map/MapPositions.js | |
parent | fb8f8764aae3e509df75f5d3f25daf11a19a0029 (diff) | |
download | trackermap-web-4cce933164ace68833a07da463997e53226c1b6a.tar.gz trackermap-web-4cce933164ace68833a07da463997e53226c1b6a.tar.bz2 trackermap-web-4cce933164ace68833a07da463997e53226c1b6a.zip |
Handle direction with clusering
Diffstat (limited to 'modern/src/map/MapPositions.js')
-rw-r--r-- | modern/src/map/MapPositions.js | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/modern/src/map/MapPositions.js b/modern/src/map/MapPositions.js index e38e2694..92487fee 100644 --- a/modern/src/map/MapPositions.js +++ b/modern/src/map/MapPositions.js @@ -7,9 +7,10 @@ import { mapIconKey } from './core/preloadImages'; import { findFonts } from './core/mapUtil'; import { useAttributePreference } from '../common/util/preferences'; -const MapPositions = ({ positions, onClick, showStatus }) => { +const MapPositions = ({ positions, onClick, showStatus, selectedPosition }) => { const id = useId(); const clusters = `${id}-clusters`; + const direction = `${id}-direction`; const devices = useSelector((state) => state.devices.items); @@ -76,7 +77,7 @@ const MapPositions = ({ positions, onClick, showStatus }) => { id, type: 'symbol', source: id, - filter: ['!', ['has', 'point_count']], + filter: ['!has', 'point_count'], layout: { 'icon-image': '{category}-{color}', 'icon-size': iconScale, @@ -106,6 +107,21 @@ const MapPositions = ({ positions, onClick, showStatus }) => { 'text-size': 14, }, }); + if (selectedPosition && selectedPosition.course) { + map.addLayer({ + id: direction, + type: 'symbol', + source: id, + filter: ['all', ['!has', 'point_count'], ['==', 'id', selectedPosition.id]], + layout: { + 'icon-image': 'direction', + 'icon-size': iconScale, + 'icon-allow-overlap': true, + 'icon-rotate': ['get', 'rotation'], + 'icon-rotation-alignment': 'map', + }, + }); + } map.on('mouseenter', id, onMouseEnter); map.on('mouseleave', id, onMouseLeave); @@ -130,11 +146,14 @@ const MapPositions = ({ positions, onClick, showStatus }) => { if (map.getLayer(clusters)) { map.removeLayer(clusters); } + if (map.getLayer(direction)) { + map.removeLayer(direction); + } if (map.getSource(id)) { map.removeSource(id); } }; - }, [mapCluster, clusters, onMarkerClick, onClusterClick]); + }, [selectedPosition, mapCluster, clusters, direction, onMarkerClick, onClusterClick]); useEffect(() => { map.getSource(id).setData({ |