fleetmap-reports 1.0.388 → 1.0.391
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 +46 -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 - 1)
|
|
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
|
@@ -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.filter(g => g.area.startsWith('POLYGON') || g.area.startsWith('CIRCLE')).map(g => convertToFeature(g))
|
|
158
158
|
|
|
159
159
|
const entryMap = []
|
|
160
160
|
routePoints.forEach(p => {
|
|
161
161
|
geofencesFeatures.forEach(g => {
|
|
162
|
-
if(
|
|
163
|
-
if(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
})
|