From 7c02d78f0b853c2c12da9d50a0ea8715111c0add Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sat, 24 Oct 2020 12:28:26 +0200 Subject: [PATCH] Fix color coding by cost. Closes #340. (#341) Fix color coding by cost. Closes #340. This makes sure it is relative to the length of the path. --- js/plugin/RoutingPathQuality.js | 15 ++++++++------- js/router/BRouter.js | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/js/plugin/RoutingPathQuality.js b/js/plugin/RoutingPathQuality.js index 2d5a97b..7c714c1 100644 --- a/js/plugin/RoutingPathQuality.js +++ b/js/plugin/RoutingPathQuality.js @@ -70,13 +70,14 @@ BR.RoutingPathQuality = L.Control.extend({ }, valueFunction: function(latLng) { var feature = latLng.feature; - return ( - feature.cost.perKm + - feature.cost.elev + - feature.cost.turn + - feature.cost.node + - feature.cost.initial - ); + var cost = feature.cost.perKm; + var distance = feature.distance / 1000; // in km + if (distance > 0) { + cost += + (feature.cost.elev + feature.cost.turn + feature.cost.node + feature.cost.initial) / + distance; + } + return cost; } }) } diff --git a/js/router/BRouter.js b/js/router/BRouter.js index 9f39e18..d8985b1 100644 --- a/js/router/BRouter.js +++ b/js/router/BRouter.js @@ -236,6 +236,7 @@ L.BRouter = L.Class.extend({ node: parseInt(featureMessage[7]), initial: parseInt(featureMessage[8]) }, + distance: parseInt(featureMessage[3]), wayTags: featureMessage[9], nodeTags: featureMessage[10] };