From fe050816785e274b02e9299c26bcea42cd54e611 Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Fri, 2 Jul 2021 19:44:43 +0200 Subject: [PATCH] Add beeline support to distance markers - update on beeline toggle - avoid distance markers wandering accross the map while routing many waypoints, because beelines are added immediately, by turning off updates in-between --- js/plugin/Routing.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/js/plugin/Routing.js b/js/plugin/Routing.js index 627ed41..7d048a6 100644 --- a/js/plugin/Routing.js +++ b/js/plugin/Routing.js @@ -54,13 +54,36 @@ BR.Routing = L.Routing.extend({ this._waypoints.on('layeradd', this._setMarkerOpacity, this); - this.on('routing:routeWaypointStart routing:rerouteAllSegmentsStart', function (evt) { - this._removeDistanceMarkers(); + // flag if (re-)routing of all segments is ongoing + this._routingAll = false; + this.on('routing:rerouteAllSegmentsStart routing:setWaypointsStart', function (evt) { + this._routingAll = true; + }); + this.on('routing:rerouteAllSegmentsEnd routing:setWaypointsEnd', function (evt) { + this._routingAll = false; }); - this.on('routing:routeWaypointEnd routing:setWaypointsEnd routing:rerouteAllSegmentsEnd', function (evt) { - this._updateDistanceMarkers(evt); - }); + this.on( + 'routing:routeWaypointStart routing:rerouteAllSegmentsStart routing:rerouteSegmentStart', + function (evt) { + if (!this._routingAll || evt.type === 'routing:rerouteAllSegmentsStart') { + this._removeDistanceMarkers(); + } + } + ); + + this.on( + 'routing:routeWaypointEnd routing:setWaypointsEnd routing:rerouteAllSegmentsEnd routing:rerouteSegmentEnd', + function (evt) { + if ( + !this._routingAll || + evt.type === 'routing:rerouteAllSegmentsEnd' || + evt.type === 'routing:setWaypointsEnd' + ) { + this._updateDistanceMarkers(evt); + } + } + ); // turn line mouse marker off while over waypoint marker this.on(