diff options
author | Anton Tananaev <anton@traccar.org> | 2022-05-22 09:57:51 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-05-22 09:57:51 -0700 |
commit | 67d7ce8e0f428c521d3d032e8145108c9b2a5f45 (patch) | |
tree | 9f350497ebc64951ce2070723ab2b66e1a0f5472 /modern/src/map/main/MapAccuracy.js | |
parent | 111347e3f40640aa4c43c0bc2666d7a92ce03bb2 (diff) | |
download | trackermap-web-67d7ce8e0f428c521d3d032e8145108c9b2a5f45.tar.gz trackermap-web-67d7ce8e0f428c521d3d032e8145108c9b2a5f45.tar.bz2 trackermap-web-67d7ce8e0f428c521d3d032e8145108c9b2a5f45.zip |
Rename map plugins
Diffstat (limited to 'modern/src/map/main/MapAccuracy.js')
-rw-r--r-- | modern/src/map/main/MapAccuracy.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/modern/src/map/main/MapAccuracy.js b/modern/src/map/main/MapAccuracy.js new file mode 100644 index 00000000..11ea64ed --- /dev/null +++ b/modern/src/map/main/MapAccuracy.js @@ -0,0 +1,55 @@ +import { useEffect } from 'react'; +import { useSelector } from 'react-redux'; +import circle from '@turf/circle'; + +import { map } from '../core/Map'; + +const MapAccuracy = () => { + const id = 'accuracy'; + + const positions = useSelector((state) => ({ + type: 'FeatureCollection', + features: Object.values(state.positions.items).filter((position) => position.accuracy > 0).map((position) => circle([position.longitude, position.latitude], position.accuracy * 0.001)), + })); + + useEffect(() => { + map.addSource(id, { + type: 'geojson', + data: { + type: 'FeatureCollection', + features: [], + }, + }); + map.addLayer({ + source: id, + id, + type: 'fill', + filter: [ + 'all', + ['==', '$type', 'Polygon'], + ], + paint: { + 'fill-color': '#3bb2d0', + 'fill-outline-color': '#3bb2d0', + 'fill-opacity': 0.25, + }, + }); + + return () => { + if (map.getLayer(id)) { + map.removeLayer(id); + } + if (map.getSource(id)) { + map.removeSource(id); + } + }; + }, []); + + useEffect(() => { + map.getSource(id).setData(positions); + }, [positions]); + + return null; +}; + +export default MapAccuracy; |