Do not crash if circlego is not enabled (#349)

This commit is contained in:
Gautier P 2020-12-02 20:53:02 +01:00
parent 779c720b7d
commit 5995e2e879
2 changed files with 15 additions and 13 deletions

View file

@ -34,7 +34,7 @@
drawButton, drawButton,
deleteRouteButton, deleteRouteButton,
pois, pois,
circleGo, circlego,
urlHash; urlHash;
// By default bootstrap-select use glyphicons // By default bootstrap-select use glyphicons
@ -260,8 +260,6 @@
}); });
pois = new BR.PoiMarkers(routing); pois = new BR.PoiMarkers(routing);
circleGo = new BR.CircleGoArea(routing, nogos, pois);
pois.circlego = circleGo;
exportRoute = new BR.Export(router, pois); exportRoute = new BR.Export(router, pois);
@ -322,18 +320,22 @@
nogos.addTo(map); nogos.addTo(map);
var shouldAddCircleGo = false; var circlegoRadius = null;
var lang = i18next.languages.length && i18next.languages[0]; var lang = i18next.languages.length && i18next.languages[0];
if (lang.startsWith('fr')) { if (lang.startsWith('fr')) {
circleGo.options.radius = 20000; circlegoRadius = 20000;
shouldAddCircleGo = true;
} }
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()]; var buttons = [drawButton, reverseRouteButton, nogos.getButton()];
if (shouldAddCircleGo) buttons.push(circleGo.getButton()); if (circlegoRadius) buttons.push(circlego.getButton());
buttons.push(deletePointButton, deleteRouteButton); buttons.push(deletePointButton, deleteRouteButton);
L.easyBar(buttons).addTo(map); L.easyBar(buttons).addTo(map);
@ -392,10 +394,10 @@
var opts = router.parseUrlParams(url2params(url)); var opts = router.parseUrlParams(url2params(url));
router.setOptions(opts); router.setOptions(opts);
routingOptions.setOptions(opts); routingOptions.setOptions(opts);
if (opts.circlego) { if (circlego && opts.circlego) {
// must be done before nogos! // must be done before nogos!
circleGo.options.radius = opts.circlego[2]; circlego.options.radius = opts.circlego[2];
circleGo.setCircle([opts.circlego[0], opts.circlego[1]]); circlego.setCircle([opts.circlego[0], opts.circlego[1]]);
} }
nogos.setOptions(opts); nogos.setOptions(opts);
profile.update(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 // this callback is used to append anything in URL after L.Hash wrote #map=zoom/lat/lng/layer
urlHash.additionalCb = function() { urlHash.additionalCb = function() {
var url = router 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); .substr('brouter?'.length + 1);
// by default brouter use | as separator. To make URL more human-readable, we remplace them with ; for users // by default brouter use | as separator. To make URL more human-readable, we remplace them with ; for users

View file

@ -59,7 +59,7 @@ BR.PoiMarkers = L.Control.extend({
this.drawButton.state(enable ? 'deactivate-poi' : 'activate-poi'); this.drawButton.state(enable ? 'deactivate-poi' : 'activate-poi');
if (enable) { if (enable) {
this.routing.draw(false); this.routing.draw(false);
this.circlego.draw(false); if (this.circlego) this.circlego.draw(false);
this.map.on('click', this.onMapClick, this); this.map.on('click', this.onMapClick, this);
L.DomUtil.addClass(this.map.getContainer(), 'pois-draw-enabled'); L.DomUtil.addClass(this.map.getContainer(), 'pois-draw-enabled');
} else { } else {