fleetmap-reports 1.0.388 → 1.0.389

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.388",
3
+ "version": "1.0.389",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/util/utils.js CHANGED
@@ -62,6 +62,17 @@ function convertToFeature(geofence) {
62
62
  }
63
63
  return feature
64
64
  }
65
+
66
+ if(geofence.area.startsWith('CIRCLE')) {
67
+ const str = geofence.area.substring('CIRCLE(('.length, geofence.area.length - 2)
68
+ const coord_list = str.split(',')
69
+ const coord = coord_list[0].trim().split(' ')
70
+ const point = turf.point([parseFloat(coord[1]), parseFloat(coord[0])])
71
+ point.properties.geofence = geofence
72
+ point.properties.distance = coord_list[1].trim()
73
+ console.log(point)
74
+ return point
75
+ }
65
76
  }
66
77
 
67
78
  function getDates(startDate, endDate) {
@@ -154,31 +154,57 @@ function getInAndOutEvents(devices, route, userData) {
154
154
  const deviceRoute = route.filter(p => p.deviceId === d.id)
155
155
 
156
156
  const routePoints = deviceRoute.map(p => convertPositionToFeature(p))
157
- const geofencesFeatures = userData.geofences.filter(g => g.area.startsWith('POLYGON')).map(g => convertToFeature(g))
157
+ const geofencesFeatures = userData.geofences.map(g => convertToFeature(g))
158
158
 
159
159
  const entryMap = []
160
160
  routePoints.forEach(p => {
161
161
  geofencesFeatures.forEach(g => {
162
- if(turf.inside(p, g)) {
163
- if(!entryMap.includes(g)) {
164
- events.push({
165
- type: "geofenceEnter",
166
- position: p.properties.position,
167
- geofenceId: g.properties.geofence.id,
168
- deviceId: d.id
169
- })
170
- entryMap.push(g)
162
+ if(g.geometry.type === 'Polygon') {
163
+ if (turf.inside(p, g)) {
164
+ if (!entryMap.includes(g)) {
165
+ events.push({
166
+ type: "geofenceEnter",
167
+ position: p.properties.position,
168
+ geofenceId: g.properties.geofence.id,
169
+ deviceId: d.id
170
+ })
171
+ entryMap.push(g)
172
+ }
173
+ } else {
174
+ if (entryMap.includes(g)) {
175
+ events.push({
176
+ type: "geofenceExit",
177
+ position: p.properties.position,
178
+ geofenceId: g.properties.geofence.id,
179
+ deviceId: d.id
180
+ })
181
+ const index = entryMap.indexOf(g)
182
+ entryMap.splice(index, 1)
183
+ }
171
184
  }
172
- } else {
173
- if(entryMap.includes(g)) {
174
- events.push({
175
- type: "geofenceExit",
176
- position: p.properties.position,
177
- geofenceId: g.properties.geofence.id,
178
- deviceId: d.id
179
- })
180
- const index = entryMap.indexOf(g)
181
- entryMap.splice(index, 1)
185
+ }
186
+ if(g.geometry.type === 'Point') {
187
+ if (turf.distance(p, g, 'meters') < g.properties.distance) {
188
+ if (!entryMap.includes(g)) {
189
+ events.push({
190
+ type: "geofenceEnter",
191
+ position: p.properties.position,
192
+ geofenceId: g.properties.geofence.id,
193
+ deviceId: d.id
194
+ })
195
+ entryMap.push(g)
196
+ }
197
+ } else {
198
+ if (entryMap.includes(g)) {
199
+ events.push({
200
+ type: "geofenceExit",
201
+ position: p.properties.position,
202
+ geofenceId: g.properties.geofence.id,
203
+ deviceId: d.id
204
+ })
205
+ const index = entryMap.indexOf(g)
206
+ entryMap.splice(index, 1)
207
+ }
182
208
  }
183
209
  }
184
210
  })