Merge pull request #350 from bagage/fix/limit-area

This commit is contained in:
Norbert Renner 2020-12-04 10:48:45 +01:00 committed by GitHub
commit 04d549ad61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 20 deletions

View file

@ -50,6 +50,8 @@ BR.Message = L.Class.extend({
err = i18next.t('warning.invalid-route-to'); err = i18next.t('warning.invalid-route-to');
} else if (err == 'from-position not mapped in existing datafile\n') { } else if (err == 'from-position not mapped in existing datafile\n') {
err = i18next.t('warning.invalid-route-from'); 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'); this._show(err, 'error');
}, },

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,11 +394,6 @@
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) {
// must be done before nogos!
circleGo.options.radius = opts.circlego[2];
circleGo.setCircle([opts.circlego[0], opts.circlego[1]]);
}
nogos.setOptions(opts); nogos.setOptions(opts);
profile.update(opts); profile.update(opts);
@ -408,6 +405,10 @@
if (opts.pois) { if (opts.pois) {
pois.setMarkers(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) { var onInvalidHashChangeCb = function(params) {
@ -423,7 +424,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

@ -88,6 +88,7 @@ BR.CircleGoArea = L.Control.extend({
if (center) { if (center) {
var polygon = this.circleToPolygon(center, this.options.radius); var polygon = this.circleToPolygon(center, this.options.radius);
$('#nogoJSON').val(JSON.stringify(polygon)); $('#nogoJSON').val(JSON.stringify(polygon));
$('#nogoBuffer').val(0);
this.nogos.uploadNogos(); this.nogos.uploadNogos();
} else { } else {
this.nogos.clear(); this.nogos.clear();
@ -95,10 +96,10 @@ BR.CircleGoArea = L.Control.extend({
}, },
onMapClick: function(e) { 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 self = this;
var icon = L.VectorMarkers.icon({ var icon = L.VectorMarkers.icon({
icon: 'home', icon: 'home',
@ -118,7 +119,7 @@ BR.CircleGoArea = L.Control.extend({
this.clear(); this.clear();
marker.addTo(this.circleLayer); marker.addTo(this.circleLayer);
this.setNogoCircle(center); if (!skipNogo) this.setNogoCircle(center);
this.draw(false); this.draw(false);
}, },
@ -164,7 +165,7 @@ BR.CircleGoArea = L.Control.extend({
}, },
circleToPolygon: function(center, radius, numberOfSegments) { circleToPolygon: function(center, radius, numberOfSegments) {
var n = numberOfSegments ? numberOfSegments : 64; var n = numberOfSegments ? numberOfSegments : 32;
var inner = []; var inner = [];
for (var i = 0; i < n; ++i) { for (var i = 0; i < n; ++i) {
@ -172,6 +173,9 @@ BR.CircleGoArea = L.Control.extend({
} }
inner.push(inner[0]); 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 { return {
type: 'FeatureCollection', type: 'FeatureCollection',
features: [ features: [
@ -180,7 +184,15 @@ BR.CircleGoArea = L.Control.extend({
properties: {}, properties: {},
geometry: { geometry: {
type: 'LineString', type: 'LineString',
coordinates: inner coordinates: inner.slice(n / 2 - 1)
}
},
{
type: 'Feature',
properties: {},
geometry: {
type: 'LineString',
coordinates: inner.slice(0, n / 2 + 1)
} }
} }
] ]

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 {