diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-03-10 09:30:17 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-10 09:30:17 -0800 |
commit | cdb873bef8bfc951a7d95e55c995ac0d186c3143 (patch) | |
tree | 2c3c41a8d3d6e75bf0c6be06f7a46534bc75783d /modern/src/map/mapUtil.js | |
parent | 624914d7bbafc3b78c439dd35d725ca368f0fd0d (diff) | |
parent | dfebe4fde8da3fdae568b1b5e4f07686c6c4a7f3 (diff) | |
download | trackermap-web-cdb873bef8bfc951a7d95e55c995ac0d186c3143.tar.gz trackermap-web-cdb873bef8bfc951a7d95e55c995ac0d186c3143.tar.bz2 trackermap-web-cdb873bef8bfc951a7d95e55c995ac0d186c3143.zip |
Merge pull request #822 from mikems66/circlefence
Transform circle fence to polygon fence
Diffstat (limited to 'modern/src/map/mapUtil.js')
-rw-r--r-- | modern/src/map/mapUtil.js | 24 |
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 } + }; + } +} + + |