Skip to content

Commit e60447a

Browse files
committed
fix: optimization route download
jobs and vehicles are correctly parsed for JSON export
1 parent ee2ea48 commit e60447a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Vehicle from '@/models/vehicle'
66
import constants from '@/resources/constants'
77
import toKml from '@maphubs/tokml'
88
import toGpx from 'togpx'
9+
import vehicle from "@/models/vehicle";
910

1011
export default {
1112
data: () => ({
@@ -180,7 +181,7 @@ export default {
180181
if (context.downloadFormat === 'json') {
181182
// Get the ORS mapViewData model and stringify it
182183
if (this.mapViewData) {
183-
jsonData = JSON.stringify(context.mapViewData)
184+
jsonData = JSON.stringify(this.parseMapView(context.mapViewData))
184185
} else {
185186
jsonData = JSON.stringify(context.dataJson)
186187
}
@@ -199,6 +200,7 @@ export default {
199200
resolve(toGPX)
200201
} else if (context.downloadFormat === 'geojson') {
201202
if (this.mapViewData) {
203+
// TODO: does not include vehicle and job information when downloading optimization route
202204
jsonData = context.mapViewData.getGeoJson()
203205
} else {
204206
jsonData = context.dataGeoJson
@@ -230,6 +232,27 @@ export default {
230232
})
231233
},
232234

235+
parseMapView (mapViewData) {
236+
let localMapViewData = mapViewData
237+
238+
if (mapViewData.mode === constants.modes.optimization) {
239+
// TODO: fix parsing of humanised distance and duration
240+
let jsonJobs = []
241+
for (const job of mapViewData.jobs) {
242+
jsonJobs.push(job.toJSON())
243+
}
244+
localMapViewData.jobs = jsonJobs
245+
246+
let jsonVehicles = []
247+
for (const v of mapViewData.vehicles) {
248+
jsonVehicles.push(v.toJSON())
249+
}
250+
localMapViewData.vehicles = jsonVehicles
251+
}
252+
253+
return localMapViewData
254+
},
255+
233256
copyToClipboard () {
234257
const data = this.dataJson
235258

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ export default {
443443
if (data) {
444444
MapViewDataBuilder.buildMapData(data, context.$store.getters.appRouteData).then((mapViewData) => {
445445
context.mapViewData = mapViewData
446+
context.mapViewData.mode = constants.modes.optimization
446447
context.mapViewData.jobs = context.jobs
447448
context.mapViewData.vehicles = context.vehicles
448449
EventBus.$emit('mapViewDataChanged', mapViewData)

0 commit comments

Comments
 (0)