From 5995e2e8797eeb029defc8639d1924bf973b9fe3 Mon Sep 17 00:00:00 2001 From: Gautier P Date: Wed, 2 Dec 2020 20:53:02 +0100 Subject: [PATCH 1/4] Do not crash if circlego is not enabled (#349) --- js/index.js | 26 ++++++++++++++------------ js/plugin/POIMarkers.js | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/js/index.js b/js/index.js index c964db4..2c75973 100644 --- a/js/index.js +++ b/js/index.js @@ -34,7 +34,7 @@ drawButton, deleteRouteButton, pois, - circleGo, + circlego, urlHash; // By default bootstrap-select use glyphicons @@ -260,8 +260,6 @@ }); pois = new BR.PoiMarkers(routing); - circleGo = new BR.CircleGoArea(routing, nogos, pois); - pois.circlego = circleGo; exportRoute = new BR.Export(router, pois); @@ -322,18 +320,22 @@ nogos.addTo(map); - var shouldAddCircleGo = false; + var circlegoRadius = null; var lang = i18next.languages.length && i18next.languages[0]; if (lang.startsWith('fr')) { - circleGo.options.radius = 20000; - shouldAddCircleGo = true; + circlegoRadius = 20000; } - if (shouldAddCircleGo) circleGo.addTo(map); + if (circlegoRadius != null) { + circlego = new BR.CircleGoArea(routing, nogos, pois); + circlego.options.radius = circlegoRadius; + pois.circlego = circlego; + circlego.addTo(map); + } var buttons = [drawButton, reverseRouteButton, nogos.getButton()]; - if (shouldAddCircleGo) buttons.push(circleGo.getButton()); + if (circlegoRadius) buttons.push(circlego.getButton()); buttons.push(deletePointButton, deleteRouteButton); L.easyBar(buttons).addTo(map); @@ -392,10 +394,10 @@ var opts = router.parseUrlParams(url2params(url)); router.setOptions(opts); routingOptions.setOptions(opts); - if (opts.circlego) { + if (circlego && opts.circlego) { // must be done before nogos! - circleGo.options.radius = opts.circlego[2]; - circleGo.setCircle([opts.circlego[0], opts.circlego[1]]); + circlego.options.radius = opts.circlego[2]; + circlego.setCircle([opts.circlego[0], opts.circlego[1]]); } nogos.setOptions(opts); profile.update(opts); @@ -423,7 +425,7 @@ // this callback is used to append anything in URL after L.Hash wrote #map=zoom/lat/lng/layer urlHash.additionalCb = function() { var url = router - .getUrl(routing.getWaypoints(), pois.getMarkers(), circleGo.getCircle(), null) + .getUrl(routing.getWaypoints(), pois.getMarkers(), circlego ? circlego.getCircle() : null, null) .substr('brouter?'.length + 1); // by default brouter use | as separator. To make URL more human-readable, we remplace them with ; for users diff --git a/js/plugin/POIMarkers.js b/js/plugin/POIMarkers.js index 76d132a..247da53 100644 --- a/js/plugin/POIMarkers.js +++ b/js/plugin/POIMarkers.js @@ -59,7 +59,7 @@ BR.PoiMarkers = L.Control.extend({ this.drawButton.state(enable ? 'deactivate-poi' : 'activate-poi'); if (enable) { this.routing.draw(false); - this.circlego.draw(false); + if (this.circlego) this.circlego.draw(false); this.map.on('click', this.onMapClick, this); L.DomUtil.addClass(this.map.getContainer(), 'pois-draw-enabled'); } else { From fde629fcb09fcfeda7fe6cd31b07d884ffab2c32 Mon Sep 17 00:00:00 2001 From: Gautier P Date: Wed, 2 Dec 2020 21:01:33 +0100 Subject: [PATCH 2/4] Reduce circle segments count (#349) --- js/plugin/CircleGoArea.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/plugin/CircleGoArea.js b/js/plugin/CircleGoArea.js index 5fffebc..d44276d 100644 --- a/js/plugin/CircleGoArea.js +++ b/js/plugin/CircleGoArea.js @@ -88,6 +88,7 @@ BR.CircleGoArea = L.Control.extend({ if (center) { var polygon = this.circleToPolygon(center, this.options.radius); $('#nogoJSON').val(JSON.stringify(polygon)); + $('#nogoBuffer').val(0); this.nogos.uploadNogos(); } else { this.nogos.clear(); @@ -164,7 +165,7 @@ BR.CircleGoArea = L.Control.extend({ }, circleToPolygon: function(center, radius, numberOfSegments) { - var n = numberOfSegments ? numberOfSegments : 64; + var n = numberOfSegments ? numberOfSegments : 32; var inner = []; for (var i = 0; i < n; ++i) { From 8ca602575c8404313413fe5c4a8f4f3854d8f971 Mon Sep 17 00:00:00 2001 From: Gautier P Date: Wed, 2 Dec 2020 21:11:57 +0100 Subject: [PATCH 3/4] Do not override nogos on url load (#349) --- js/index.js | 9 ++++----- js/plugin/CircleGoArea.js | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/js/index.js b/js/index.js index 2c75973..722d2f0 100644 --- a/js/index.js +++ b/js/index.js @@ -394,11 +394,6 @@ var opts = router.parseUrlParams(url2params(url)); router.setOptions(opts); routingOptions.setOptions(opts); - if (circlego && opts.circlego) { - // must be done before nogos! - circlego.options.radius = opts.circlego[2]; - circlego.setCircle([opts.circlego[0], opts.circlego[1]]); - } nogos.setOptions(opts); profile.update(opts); @@ -410,6 +405,10 @@ if (opts.pois) { pois.setMarkers(opts.pois); } + if (circlego && opts.circlego) { + circlego.options.radius = opts.circlego[2]; + circlego.setCircle([opts.circlego[0], opts.circlego[1]], opts.polylines != null); + } }; var onInvalidHashChangeCb = function(params) { diff --git a/js/plugin/CircleGoArea.js b/js/plugin/CircleGoArea.js index d44276d..fe0c07f 100644 --- a/js/plugin/CircleGoArea.js +++ b/js/plugin/CircleGoArea.js @@ -96,10 +96,10 @@ BR.CircleGoArea = L.Control.extend({ }, onMapClick: function(e) { - this.setCircle([e.latlng.lng, e.latlng.lat]); + this.setCircle([e.latlng.lng, e.latlng.lat], false); }, - setCircle: function(center) { + setCircle: function(center, skipNogo) { var self = this; var icon = L.VectorMarkers.icon({ icon: 'home', @@ -119,7 +119,7 @@ BR.CircleGoArea = L.Control.extend({ this.clear(); marker.addTo(this.circleLayer); - this.setNogoCircle(center); + if (!skipNogo) this.setNogoCircle(center); this.draw(false); }, From a2366a26bdf7c710e330c907e4fbc6929d77907c Mon Sep 17 00:00:00 2001 From: Gautier P Date: Thu, 3 Dec 2020 00:06:20 +0100 Subject: [PATCH 4/4] Split ring in two to avoid routing issue --- js/control/Message.js | 2 ++ js/plugin/CircleGoArea.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/js/control/Message.js b/js/control/Message.js index 426ebde..fe1a213 100644 --- a/js/control/Message.js +++ b/js/control/Message.js @@ -50,6 +50,8 @@ BR.Message = L.Class.extend({ err = i18next.t('warning.invalid-route-to'); } else if (err == 'from-position not mapped in existing datafile\n') { err = i18next.t('warning.invalid-route-from'); + } else if (err && err.startsWith('null description for: ')) { + err = i18next.t('warning.no-route-found'); } this._show(err, 'error'); }, diff --git a/js/plugin/CircleGoArea.js b/js/plugin/CircleGoArea.js index fe0c07f..eeab771 100644 --- a/js/plugin/CircleGoArea.js +++ b/js/plugin/CircleGoArea.js @@ -173,6 +173,9 @@ BR.CircleGoArea = L.Control.extend({ } inner.push(inner[0]); + /* hack: it seems there is a bug when using a single closed ring line, + cf. https://github.com/nrenner/brouter-web/issues/349#issue-755514458 + so instead we use 2 half rings to ensure we properly close the area */ return { type: 'FeatureCollection', features: [ @@ -181,7 +184,15 @@ BR.CircleGoArea = L.Control.extend({ properties: {}, geometry: { type: 'LineString', - coordinates: inner + coordinates: inner.slice(n / 2 - 1) + } + }, + { + type: 'Feature', + properties: {}, + geometry: { + type: 'LineString', + coordinates: inner.slice(0, n / 2 + 1) } } ]