Support beelines in hash url (first stab)
This commit is contained in:
parent
f3d48dc63e
commit
3c8be96085
5 changed files with 50 additions and 10 deletions
|
|
@ -74,7 +74,15 @@ BR.Export = L.Class.extend({
|
||||||
link.download = (name || 'brouter') + '.' + format;
|
link.download = (name || 'brouter') + '.' + format;
|
||||||
link.click();
|
link.click();
|
||||||
} else {
|
} else {
|
||||||
var uri = this.router.getUrl(this.latLngs, this.pois.getMarkers(), null, format, nameUri, includeWaypoints);
|
var uri = this.router.getUrl(
|
||||||
|
this.latLngs,
|
||||||
|
null,
|
||||||
|
this.pois.getMarkers(),
|
||||||
|
null,
|
||||||
|
format,
|
||||||
|
nameUri,
|
||||||
|
includeWaypoints
|
||||||
|
);
|
||||||
var evt = document.createEvent('MouseEvents');
|
var evt = document.createEvent('MouseEvents');
|
||||||
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||||
var link = document.createElement('a');
|
var link = document.createElement('a');
|
||||||
|
|
|
||||||
10
js/index.js
10
js/index.js
|
|
@ -432,7 +432,7 @@
|
||||||
if (opts.lonlats) {
|
if (opts.lonlats) {
|
||||||
routing.draw(false);
|
routing.draw(false);
|
||||||
routing.clear();
|
routing.clear();
|
||||||
routing.setWaypoints(opts.lonlats);
|
routing.setWaypoints(opts.lonlats, opts.beelineFlags);
|
||||||
}
|
}
|
||||||
if (opts.pois) {
|
if (opts.pois) {
|
||||||
pois.setMarkers(opts.pois);
|
pois.setMarkers(opts.pois);
|
||||||
|
|
@ -455,7 +455,13 @@
|
||||||
// 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 ? circlego.getCircle() : null, null)
|
.getUrl(
|
||||||
|
routing.getWaypoints(),
|
||||||
|
routing.getBeelineFlags(),
|
||||||
|
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
|
||||||
|
|
|
||||||
|
|
@ -341,7 +341,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (routingPoints.length > 0) {
|
if (routingPoints.length > 0) {
|
||||||
routing.setWaypoints(routingPoints, function (event) {
|
routing.setWaypoints(routingPoints, null, function (event) {
|
||||||
if (!event) return;
|
if (!event) return;
|
||||||
var err = event.error;
|
var err = event.error;
|
||||||
BR.message.showError(
|
BR.message.showError(
|
||||||
|
|
|
||||||
|
|
@ -290,7 +290,7 @@ BR.Routing = L.Routing.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setWaypoints: function (latLngs, cb) {
|
setWaypoints: function (latLngs, beelineFlags, cb) {
|
||||||
var i;
|
var i;
|
||||||
var callbackCount = 0;
|
var callbackCount = 0;
|
||||||
var firstErr;
|
var firstErr;
|
||||||
|
|
@ -319,7 +319,8 @@ BR.Routing = L.Routing.extend({
|
||||||
this._loadingTrailerGroup._map = null;
|
this._loadingTrailerGroup._map = null;
|
||||||
|
|
||||||
for (i = 0; latLngs && i < latLngs.length; i++) {
|
for (i = 0; latLngs && i < latLngs.length; i++) {
|
||||||
this.addWaypoint(latLngs[i], this._waypoints._last, null, callback);
|
const beeline = beelineFlags && i < beelineFlags.length ? beelineFlags[i] : null;
|
||||||
|
this.addWaypoint(latLngs[i], beeline, this._waypoints._last, null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._loadingTrailerGroup._map = this._map;
|
this._loadingTrailerGroup._map = this._map;
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,15 @@ L.BRouter = L.Class.extend({
|
||||||
L.setOptions(this, options);
|
L.setOptions(this, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
getUrlParams: function (latLngs, pois, circlego, format) {
|
getUrlParams: function (latLngs, beelineFlags, pois, circlego, format) {
|
||||||
params = {};
|
params = {};
|
||||||
if (this._getLonLatsString(latLngs) != null) params.lonlats = this._getLonLatsString(latLngs);
|
if (this._getLonLatsString(latLngs) != null) params.lonlats = this._getLonLatsString(latLngs);
|
||||||
|
|
||||||
|
if (beelineFlags && beelineFlags.length > 0) {
|
||||||
|
const beelineString = this._getBeelineString(beelineFlags);
|
||||||
|
if (beelineString.length > 0) params.straight = beelineString;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.options.nogos && this._getNogosString(this.options.nogos).length > 0)
|
if (this.options.nogos && this._getNogosString(this.options.nogos).length > 0)
|
||||||
params.nogos = this._getNogosString(this.options.nogos);
|
params.nogos = this._getNogosString(this.options.nogos);
|
||||||
|
|
||||||
|
|
@ -84,6 +89,9 @@ L.BRouter = L.Class.extend({
|
||||||
if (params.lonlats) {
|
if (params.lonlats) {
|
||||||
opts.lonlats = this._parseLonLats(params.lonlats);
|
opts.lonlats = this._parseLonLats(params.lonlats);
|
||||||
}
|
}
|
||||||
|
if (params.straight) {
|
||||||
|
opts.beelineFlags = this._parseBeelines(params.straight);
|
||||||
|
}
|
||||||
if (params.nogos) {
|
if (params.nogos) {
|
||||||
opts.nogos = this._parseNogos(params.nogos);
|
opts.nogos = this._parseNogos(params.nogos);
|
||||||
}
|
}
|
||||||
|
|
@ -117,11 +125,12 @@ L.BRouter = L.Class.extend({
|
||||||
return opts;
|
return opts;
|
||||||
},
|
},
|
||||||
|
|
||||||
getUrl: function (latLngs, pois, circlego, format, trackname, exportWaypoints) {
|
getUrl: function (latLngs, beelineFlags, pois, circlego, format, trackname, exportWaypoints) {
|
||||||
var urlParams = this.getUrlParams(latLngs, pois, circlego, format);
|
var urlParams = this.getUrlParams(latLngs, beelineFlags, pois, circlego, format);
|
||||||
var args = [];
|
var args = [];
|
||||||
if (urlParams.lonlats != null && urlParams.lonlats.length > 0)
|
if (urlParams.lonlats != null && urlParams.lonlats.length > 0)
|
||||||
args.push(L.Util.template('lonlats={lonlats}', urlParams));
|
args.push(L.Util.template('lonlats={lonlats}', urlParams));
|
||||||
|
if (urlParams.straight != null) args.push(L.Util.template('straight={straight}', urlParams));
|
||||||
if (urlParams.pois != null && urlParams.pois.length > 0) args.push(L.Util.template('pois={pois}', urlParams));
|
if (urlParams.pois != null && urlParams.pois.length > 0) args.push(L.Util.template('pois={pois}', urlParams));
|
||||||
if (urlParams.circlego != null) args.push(L.Util.template('ringgo={circlego}', urlParams));
|
if (urlParams.circlego != null) args.push(L.Util.template('ringgo={circlego}', urlParams));
|
||||||
if (urlParams.nogos != null) args.push(L.Util.template('nogos={nogos}', urlParams));
|
if (urlParams.nogos != null) args.push(L.Util.template('nogos={nogos}', urlParams));
|
||||||
|
|
@ -144,7 +153,7 @@ L.BRouter = L.Class.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
getRoute: function (latLngs, cb) {
|
getRoute: function (latLngs, cb) {
|
||||||
var url = this.getUrl(latLngs, null, null, 'geojson'),
|
var url = this.getUrl(latLngs, null, null, null, 'geojson'),
|
||||||
xhr = new XMLHttpRequest();
|
xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
|
|
@ -305,6 +314,22 @@ L.BRouter = L.Class.extend({
|
||||||
return lonlats;
|
return lonlats;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getBeelineString: function (beelineFlags) {
|
||||||
|
var s = '';
|
||||||
|
for (var i = 0; i < beelineFlags.length; i++) {
|
||||||
|
s += beelineFlags[i] ? '1' : '0';
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
},
|
||||||
|
|
||||||
|
_parseBeelines: function (s) {
|
||||||
|
const beelineFlags = [];
|
||||||
|
for (const c of s) {
|
||||||
|
beelineFlags.push(!!+c);
|
||||||
|
}
|
||||||
|
return beelineFlags;
|
||||||
|
},
|
||||||
|
|
||||||
_getLonLatsNameString: function (latLngNames) {
|
_getLonLatsNameString: function (latLngNames) {
|
||||||
var s = '';
|
var s = '';
|
||||||
for (var i = 0; i < latLngNames.length; i++) {
|
for (var i = 0; i < latLngNames.length; i++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue