fleetmap-reports 1.0.387 → 1.0.390

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.387",
3
+ "version": "1.0.390",
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) {
@@ -66,6 +66,7 @@ async function createZoneReport(from, to, userData, traccar) {
66
66
  if (data.length) {
67
67
  allData.devices.push(...await processDevices(from, to, devices, userData.drivers, userData.geofences, data, traccar))
68
68
  }
69
+ deviceCount = deviceCount + slice.length
69
70
  }
70
71
 
71
72
  reportData.push(allData)
@@ -153,31 +154,57 @@ function getInAndOutEvents(devices, route, userData) {
153
154
  const deviceRoute = route.filter(p => p.deviceId === d.id)
154
155
 
155
156
  const routePoints = deviceRoute.map(p => convertPositionToFeature(p))
156
- const geofencesFeatures = userData.geofences.filter(g => g.area.startsWith('POLYGON')).map(g => convertToFeature(g))
157
+ const geofencesFeatures = userData.geofences.filter(g => g.area.startsWith('POLYGON') || g.area.startsWith('CIRCLE')).map(g => convertToFeature(g))
157
158
 
158
159
  const entryMap = []
159
160
  routePoints.forEach(p => {
160
161
  geofencesFeatures.forEach(g => {
161
- if(turf.inside(p, g)) {
162
- if(!entryMap.includes(g)) {
163
- events.push({
164
- type: "geofenceEnter",
165
- position: p.properties.position,
166
- geofenceId: g.properties.geofence.id,
167
- deviceId: d.id
168
- })
169
- 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
+ }
170
184
  }
171
- } else {
172
- if(entryMap.includes(g)) {
173
- events.push({
174
- type: "geofenceExit",
175
- position: p.properties.position,
176
- geofenceId: g.properties.geofence.id,
177
- deviceId: d.id
178
- })
179
- const index = entryMap.indexOf(g)
180
- 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
+ }
181
208
  }
182
209
  }
183
210
  })