aboutsummaryrefslogtreecommitdiff
path: root/modern/src/map/mapUtil.js
diff options
context:
space:
mode:
authormikems66 <>2021-03-10 15:12:32 +0100
committermikems66 <>2021-03-10 15:12:32 +0100
commitdfebe4fde8da3fdae568b1b5e4f07686c6c4a7f3 (patch)
tree3bb4f6038a86ff16eaf8b5ffe2a1fa2a2a9634a0 /modern/src/map/mapUtil.js
parent7d3454b40dfaf170000be00fdc70a11a27f78139 (diff)
downloadtrackermap-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/mapUtil.js')
-rw-r--r--modern/src/map/mapUtil.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/modern/src/map/mapUtil.js b/modern/src/map/mapUtil.js
index 15f16202..e7dc0327 100644
--- a/modern/src/map/mapUtil.js
+++ b/modern/src/map/mapUtil.js
@@ -1,3 +1,6 @@
+import wellknown from 'wellknown';
+import circle from '@turf/circle';
+
export const loadImage = (url) => {
return new Promise(imageLoaded => {
const image = new Image();
@@ -43,3 +46,24 @@ export const reverseCoordinates = it => {
}
}
}
+
+export const geofenceToFeature = (item) => {
+ if (item.area.indexOf('CIRCLE') > -1) {
+ 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 {
+ type: 'Feature',
+ geometry: polygon.geometry,
+ properties: { name: item.name }
+ };
+ } else {
+ return {
+ type: 'Feature',
+ geometry: reverseCoordinates(wellknown(item.area)),
+ properties: { name: item.name }
+ };
+ }
+}
+
+