diff options
author | mikems66 <> | 2021-03-10 15:12:32 +0100 |
---|---|---|
committer | mikems66 <> | 2021-03-10 15:12:32 +0100 |
commit | dfebe4fde8da3fdae568b1b5e4f07686c6c4a7f3 (patch) | |
tree | 3bb4f6038a86ff16eaf8b5ffe2a1fa2a2a9634a0 /modern/src/map/GeofenceMap.js | |
parent | 7d3454b40dfaf170000be00fdc70a11a27f78139 (diff) | |
download | trackermap-web-dfebe4fde8da3fdae568b1b5e4f07686c6c4a7f3.tar.gz trackermap-web-dfebe4fde8da3fdae568b1b5e4f07686c6c4a7f3.tar.bz2 trackermap-web-dfebe4fde8da3fdae568b1b5e4f07686c6c4a7f3.zip |
Moved geofence feature creation to mapUtil.
Diffstat (limited to 'modern/src/map/GeofenceMap.js')
-rw-r--r-- | modern/src/map/GeofenceMap.js | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/modern/src/map/GeofenceMap.js b/modern/src/map/GeofenceMap.js index 31da290d..c98a8c16 100644 --- a/modern/src/map/GeofenceMap.js +++ b/modern/src/map/GeofenceMap.js @@ -1,18 +1,8 @@ -import wellknown from 'wellknown'; import { useEffect, useState } from 'react'; import { map } from './Map'; import { useEffectAsync } from '../reactHelper'; -import { reverseCoordinates } from './mapUtil'; -import circle from '@turf/circle'; - - -const circleToPolygon = (item) => { - let coordinates = item.area.replace(/CIRCLE|\(|\)|,/g, " ").trim().split(/ +/); - var options = { steps: 32, units: 'meters' }; - let polygon = circle([Number(coordinates[1]), Number(coordinates[0])], Number(coordinates[2]), options); - return [item.name, polygon.geometry]; -} +import { geofenceToFeature } from './mapUtil'; const GeofenceMap = () => { const id = 'geofences'; @@ -81,14 +71,9 @@ const GeofenceMap = () => { }, []); useEffect(() => { - let circleFence = geofences.filter((item => item.area.indexOf('CIRCLE') > -1)).map(circleToPolygon); map.getSource(id).setData({ type: 'FeatureCollection', - features: geofences.map(item => [item.name, reverseCoordinates(wellknown(item.area))]).filter(([, geometry]) => !!geometry).concat(circleFence).map(([name, geometry]) => ({ - type: 'Feature', - geometry: geometry, - properties: { name }, - })), + features: geofences.map(geofenceToFeature) }); }, [geofences]); |