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 +1 -1
- package/src/util/utils.js +11 -0
- package/src/zone-report.js +47 -20
package/package.json
CHANGED
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) {
|
package/src/zone-report.js
CHANGED
|
@@ -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(
|
|
162
|
-
if(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
})
|