From ac2744f584a7aec30c65ea6637db31f0c26ec474 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Thu, 9 May 2019 08:48:59 +0200 Subject: [PATCH] Fix for a few errors when loading nogos with weight * Nogo weight was not set when loading nogos with a default weight value. * The URL would show up "NaN" values upon reloading the web interface after having loaded some nogos. Fix #174. --- js/router/BRouter.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/js/router/BRouter.js b/js/router/BRouter.js index 1fe7bc9d..603169c5 100644 --- a/js/router/BRouter.js +++ b/js/router/BRouter.js @@ -234,9 +234,13 @@ L.BRouter = L.Class.extend({ s += this._formatLatLng(circle.getLatLng()); s += L.BRouter.NUMBER_SEPARATOR; s += Math.round(circle.getRadius()); - if (circle.options.nogoWeight) { + var nogoWeight = ( + (circle.feature && circle.feature.properties && circle.feature.properties.nogoWeight) + || circle.options.nogoWeight + ); + if (nogoWeight) { s += L.BRouter.NUMBER_SEPARATOR; - s += circle.options.nogoWeight; + s += nogoWeight; } if (i < (nogos.length - 1)) { s += L.BRouter.GROUP_SEPARATOR; @@ -282,9 +286,13 @@ L.BRouter = L.Class.extend({ } s += this._formatLatLng(vertices[j]); } - if (polyline.options.nogoWeight) { + var nogoWeight = ( + (polyline.feature && polyline.feature.properties && polyline.feature.properties.nogoWeight) + || polyline.options.nogoWeight + ); + if (nogoWeight) { s += L.BRouter.NUMBER_SEPARATOR; - s += polyline.options.nogoWeight; + s += nogoWeight; } if (i < (nogos.length - 1)) { s += L.BRouter.GROUP_SEPARATOR; @@ -333,9 +341,13 @@ L.BRouter = L.Class.extend({ } s += this._formatLatLng(vertices[j]); } - if (polygon.options.nogoWeight) { + var nogoWeight = ( + (polygon.feature && polygon.feature.properties && polygon.feature.properties.nogoWeight) + || polygon.options.nogoWeight + ); + if (nogoWeight) { s += L.BRouter.NUMBER_SEPARATOR; - s += polygon.options.nogoWeight; + s += nogoWeight; } if (i < (nogos.length - 1)) { s += L.BRouter.GROUP_SEPARATOR; @@ -376,9 +388,9 @@ L.BRouter = L.Class.extend({ // formats L.LatLng object as lng,lat string _formatLatLng: function(latLng) { var s = ''; - s += L.Util.formatNum(latLng.lng, L.BRouter.PRECISION); + s += L.Util.formatNum(latLng.lng || latLng[0], L.BRouter.PRECISION); s += L.BRouter.NUMBER_SEPARATOR; - s += L.Util.formatNum(latLng.lat, L.BRouter.PRECISION); + s += L.Util.formatNum(latLng.lat || latLng[1], L.BRouter.PRECISION); return s; } });