From c58818e50b1cf2ff1fde223bb78f69e7be8d24e8 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/index.js | 4 +--- js/router/BRouter.js | 13 ++++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/js/index.js b/js/index.js index 9f69c4d..e3dc68c 100644 --- a/js/index.js +++ b/js/index.js @@ -415,9 +415,7 @@ var geoJSON = L.geoJson(turf.featureCollection(cleanedGeoJSONFeatures), { onEachFeature: function (feature, layer) { - if (!feature.properties.nogoWeight) { - feature.properties.nogoWeight = nogoWeight; - } + layer.options.nogoWeight = feature.properties.nogoWeight || nogoWeight; } }); var nogosPoints = geoJSON.getLayers().filter(function (e) { diff --git a/js/router/BRouter.js b/js/router/BRouter.js index 1fe7bc9..e45da4c 100644 --- a/js/router/BRouter.js +++ b/js/router/BRouter.js @@ -234,7 +234,8 @@ L.BRouter = L.Class.extend({ s += this._formatLatLng(circle.getLatLng()); s += L.BRouter.NUMBER_SEPARATOR; s += Math.round(circle.getRadius()); - if (circle.options.nogoWeight) { + // -1 is default nogo exclusion, it should not be passed as a URL parameter. + if (circle.options.nogoWeight !== null && circle.options.nogoWeight !== -1) { s += L.BRouter.NUMBER_SEPARATOR; s += circle.options.nogoWeight; } @@ -282,7 +283,8 @@ L.BRouter = L.Class.extend({ } s += this._formatLatLng(vertices[j]); } - if (polyline.options.nogoWeight) { + // -1 is default nogo exclusion, it should not be passed as a URL parameter. + if (polyline.options.nogoWeight !== null && polyline.options.nogoWeight !== -1) { s += L.BRouter.NUMBER_SEPARATOR; s += polyline.options.nogoWeight; } @@ -333,7 +335,8 @@ L.BRouter = L.Class.extend({ } s += this._formatLatLng(vertices[j]); } - if (polygon.options.nogoWeight) { + // -1 is default nogo exclusion, it should not be passed as a URL parameter. + if (polygon.options.nogoWeight !== null && polygon.options.nogoWeight !== -1) { s += L.BRouter.NUMBER_SEPARATOR; s += polygon.options.nogoWeight; } @@ -376,9 +379,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[1], L.BRouter.PRECISION); s += L.BRouter.NUMBER_SEPARATOR; - s += L.Util.formatNum(latLng.lat, L.BRouter.PRECISION); + s += L.Util.formatNum(latLng.lat || latLng[0], L.BRouter.PRECISION); return s; } });