From b772924106666306c6db1157e6a07d7fdb9de7cb Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Tue, 16 May 2023 11:55:26 +0200 Subject: [PATCH] Move export dialog check outside onUpdate (#729) to only check once on init, not on every update. Waypoints available at time of callback. Add check for lonlats param as event isn't called without and error check. --- js/index.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/js/index.js b/js/index.js index 9819ecb..d22c72a 100644 --- a/js/index.js +++ b/js/index.js @@ -313,6 +313,20 @@ onUpdate(evt && evt.err); }); + // Open export dialog immediately when the `export` query parameter is set; + // this is used for the QR code export: + var searchParams = new URLSearchParams(window.location.search); + if (searchParams.has('export') && searchParams.get('export') === 'dialog') { + // event won't get called without lonlats + if (new URLSearchParams(window.location.hash).has('lonlats')) { + routing.once('routing:setWaypointsEnd', (evt) => { + if (!evt.err && routing.getWaypoints().length > 1) { + $('#exportButton').trigger('click'); + } + }); + } + } + map.on('routing:draw-start', function () { drawButton.state('deactivate-draw'); beelineButton.enable(); @@ -348,17 +362,6 @@ trackAnalysis.update(track, segments); exportRoute.update(latLngs, segments); - - // Open export dialog immediately when the `export` query parameter is set; - // this is used for the QR code export: - var searchParams = new URLSearchParams(window.location.search); - if (searchParams.has('export') && searchParams.get('export') === 'dialog') { - routing.once('routing:setWaypointsEnd', () => { - if (latLngs.length > 1) { - $('#exportButton').trigger('click'); - } - }); - } } routing.addTo(map);