From 4c27f5894c101c9e6bad7e6d99e832b6bb960ce4 Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Tue, 9 Mar 2021 07:53:26 +0100 Subject: [PATCH] Handle missing voicehints and times --- js/format/VoiceHints.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/js/format/VoiceHints.js b/js/format/VoiceHints.js index 030b02c..46e45d8 100644 --- a/js/format/VoiceHints.js +++ b/js/format/VoiceHints.js @@ -56,14 +56,8 @@ this.turnInstructionMode = turnInstructionMode; this.transportMode = transportMode; - for (const feature of geoJson.features) { - let voicehints = feature?.properties.voicehints; - if (voicehints) { - this.voicehints = voicehints; - this.track = feature; - break; - } - } + this.track = geoJson.features?.[0]; + this.voicehints = this.track?.properties?.voicehints; }, getGpxTransform: function () { @@ -110,6 +104,7 @@ }, _loopHints: function (hintCallback) { + if (!this.voicehints) return; for (const [i, values] of this.voicehints.entries()) { const [indexInTrack, commandId, exitNumber, distance, time, angle, geometry] = values; const hint = { indexInTrack, commandId, exitNumber, distance, time, angle, geometry }; @@ -330,13 +325,17 @@ const trkseg = gpx.trk[0].trkseg[0]; let trkpt = trkseg.trkpt[0]; - const startTime = this.track.properties.times[this.voicehints[0][0]]; - rteptList.push({ + const startPt = { '@lat': trkpt['@lat'], '@lon': trkpt['@lon'], desc: 'start', - extensions: { time: Math.round(startTime), offset: 0 }, - }); + }; + const times = this.track?.properties?.times; + if (this.voicehints && times) { + const startTime = times[this.voicehints[0][0]]; + startPt.extensions = { time: Math.round(startTime), offset: 0 }; + } + rteptList.push(startPt); this._loopHints((hint, cmd, coord) => { const rtept = {