Skip to content

Commit 5a5a5ea

Browse files
committed
fix: optimization route download as GeoJSON
1 parent 2b21550 commit 5a5a5ea

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

src/fragments/forms/map-form/components/download/download.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ export default {
198198
resolve(toGPX)
199199
} else if (context.downloadFormat === 'geojson') {
200200
if (this.mapViewData) {
201-
// TODO: does not include vehicle and job information when downloading optimization route
202201
jsonData = context.mapViewData.getGeoJson()
203202
} else {
204203
jsonData = context.dataGeoJson

src/models/job.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,23 @@ class Job extends Place {
132132
}
133133

134134
toGeoJSON(stringify = false) {
135-
let props = {
136-
id: this.id,
137-
service: this.service,
138-
delivery: this.delivery,
139-
pickup: this.pickup
135+
let props = {label: 'Job ' + this.id}
136+
for (const p in ['id', 'service', 'delivery', 'pickup', 'time_windows']) {
137+
if (this[p] && this[p].length) {
138+
props[p] = this[p]
139+
}
140140
}
141141

142-
if (this.skills) {
142+
if (this.skills && this.skills.length) {
143143
let skillIds = []
144144
for (const skill of this.skills) {
145145
skillIds.push(skill.id)
146146
}
147147
skillIds.sort((a,b) => a-b)
148148
props.skills = skillIds
149149
}
150-
if (this.time_windows) {
151-
props.time_windows = this.time_windows
152-
}
153150

154-
const geoJsonData = { type: 'Feature', geometry: { type: 'Point', coordinates: this.location }, properties: props }
151+
const geoJsonData = { type: 'Feature', properties: props, geometry: { type: 'Point', coordinates: this.location }}
155152
return stringify ? JSON.stringify(geoJsonData) : geoJsonData
156153
}
157154

src/models/map-view-data.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ class MapViewData {
167167
geoJsonData.features.push(routeFeature)
168168
}
169169

170-
// TODO: OPTIMIZATION - build Points with properties for jobs and vehicles
171170
// Build and add places/points features to the GeoJSON
172171
for (const plaKey in this.places) {
173172
const placeFeature = {
@@ -181,16 +180,12 @@ class MapViewData {
181180
geoJsonData.features.push(placeFeature)
182181
}
183182

184-
// Build and add polygons features to the GeoJSON
185-
for (const polKey in this.polygons) {
186-
const polygon = this.polygons[polKey]
183+
for (const jobKey in this.jobs) {
184+
geoJsonData.features.push(this.jobs[jobKey].toGeoJSON())
185+
}
187186

188-
const polygonFeature = {
189-
type: 'Feature',
190-
properties: polygon.properties,
191-
geometry: polygon.geometry
192-
}
193-
geoJsonData.features.push(polygonFeature)
187+
for (const vKey in this.vehicles) {
188+
geoJsonData.features.push(this.vehicles[vKey].toGeoJSON())
194189
}
195190

196191
// Return GeoJSON with features

src/models/vehicle.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ class Vehicle extends Place {
150150
}
151151

152152
toGeoJSON(stringify = false) {
153-
let props = {
154-
id: this.id,
155-
description: this.description,
156-
profile: this.profile,
157-
capacity: this.capacity,
153+
let props = {label: 'Vehicle ' + this.id}
154+
for (const p in ['id', 'description', 'profile', 'capacity']) {
155+
if (this[p] && this[p].length) {
156+
props[p] = this[p]
157+
}
158158
}
159159

160-
if (this.skills) {
160+
if (this.skills && this.skills.length) {
161161
let skillIds = []
162162
for (const skill of this.skills) {
163163
skillIds.push(skill.id)
@@ -169,9 +169,8 @@ class Vehicle extends Place {
169169
props.time_windows = this.time_windows
170170
}
171171

172-
const geoJsonData = { type: 'Feature',
173-
geometry: { type: 'MultiPoint', coordinates: [this.start, this.end] },
174-
properties: props }
172+
const geoJsonData = { type: 'Feature', properties: props,
173+
geometry: { type: 'MultiPoint', coordinates: [this.start, this.end] }}
175174
return stringify ? JSON.stringify(geoJsonData) : geoJsonData
176175
}
177176

0 commit comments

Comments
 (0)