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
|
|
@ -42,10 +42,15 @@ L.BRouter = L.Class.extend({
|
|||
L.setOptions(this, options);
|
||||
},
|
||||
|
||||
getUrlParams: function (latLngs, pois, circlego, format) {
|
||||
getUrlParams: function (latLngs, beelineFlags, pois, circlego, format) {
|
||||
params = {};
|
||||
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)
|
||||
params.nogos = this._getNogosString(this.options.nogos);
|
||||
|
||||
|
|
@ -84,6 +89,9 @@ L.BRouter = L.Class.extend({
|
|||
if (params.lonlats) {
|
||||
opts.lonlats = this._parseLonLats(params.lonlats);
|
||||
}
|
||||
if (params.straight) {
|
||||
opts.beelineFlags = this._parseBeelines(params.straight);
|
||||
}
|
||||
if (params.nogos) {
|
||||
opts.nogos = this._parseNogos(params.nogos);
|
||||
}
|
||||
|
|
@ -117,11 +125,12 @@ L.BRouter = L.Class.extend({
|
|||
return opts;
|
||||
},
|
||||
|
||||
getUrl: function (latLngs, pois, circlego, format, trackname, exportWaypoints) {
|
||||
var urlParams = this.getUrlParams(latLngs, pois, circlego, format);
|
||||
getUrl: function (latLngs, beelineFlags, pois, circlego, format, trackname, exportWaypoints) {
|
||||
var urlParams = this.getUrlParams(latLngs, beelineFlags, pois, circlego, format);
|
||||
var args = [];
|
||||
if (urlParams.lonlats != null && urlParams.lonlats.length > 0)
|
||||
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.circlego != null) args.push(L.Util.template('ringgo={circlego}', 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) {
|
||||
var url = this.getUrl(latLngs, null, null, 'geojson'),
|
||||
var url = this.getUrl(latLngs, null, null, null, 'geojson'),
|
||||
xhr = new XMLHttpRequest();
|
||||
|
||||
if (!url) {
|
||||
|
|
@ -305,6 +314,22 @@ L.BRouter = L.Class.extend({
|
|||
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) {
|
||||
var s = '';
|
||||
for (var i = 0; i < latLngNames.length; i++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue