Merge pull request #497 from nrenner/68-sl-routing
Add straight line support to routing
This commit is contained in:
commit
e5ea9173ae
29 changed files with 950 additions and 113 deletions
|
|
@ -74,7 +74,15 @@ BR.Export = L.Class.extend({
|
|||
link.download = (name || 'brouter') + '.' + format;
|
||||
link.click();
|
||||
} 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');
|
||||
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||
var link = document.createElement('a');
|
||||
|
|
@ -284,8 +292,15 @@ BR.Export._concatTotalTrack = function (segments) {
|
|||
|
||||
let featureCoordinates = feature.geometry.coordinates;
|
||||
if (segmentIndex > 0) {
|
||||
// remove first segment coordinate, same as previous last
|
||||
featureCoordinates = featureCoordinates.slice(1);
|
||||
// remove duplicate coordinate: first segment coordinate same as previous last,
|
||||
// remove the one without ele value (e.g. beeline)
|
||||
const prevLast = coordinates[coordinates.length - 1];
|
||||
const first = featureCoordinates[0];
|
||||
if (prevLast.length < first.length) {
|
||||
coordinates.pop();
|
||||
} else {
|
||||
featureCoordinates = featureCoordinates.slice(1);
|
||||
}
|
||||
}
|
||||
coordinates = coordinates.concat(featureCoordinates);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,48 +38,41 @@ BR.Profile = L.Evented.extend({
|
|||
button.blur();
|
||||
},
|
||||
|
||||
update: function (options) {
|
||||
update: function (options, cb) {
|
||||
var profileName = options.profile,
|
||||
profileUrl,
|
||||
empty = !this.editor.getValue(),
|
||||
clean = this.editor.isClean();
|
||||
loading = false;
|
||||
|
||||
if (profileName && BR.conf.profilesUrl) {
|
||||
// only synchronize profile editor/parameters with selection if no manual changes in full editor,
|
||||
// else keep custom profile pinned - to prevent changes in another profile overwriting previous ones
|
||||
if (empty || clean) {
|
||||
this.profileName = profileName;
|
||||
if (!(profileName in this.cache)) {
|
||||
profileUrl = BR.conf.profilesUrl + profileName + '.brf';
|
||||
BR.Util.get(
|
||||
profileUrl,
|
||||
L.bind(function (err, profileText) {
|
||||
if (err) {
|
||||
console.warn('Error getting profile from "' + profileUrl + '": ' + err);
|
||||
return;
|
||||
}
|
||||
this.selectedProfileName = profileName;
|
||||
|
||||
this.cache[profileName] = profileText;
|
||||
if (!(profileName in this.cache)) {
|
||||
profileUrl = BR.conf.profilesUrl + profileName + '.brf';
|
||||
loading = true;
|
||||
BR.Util.get(
|
||||
profileUrl,
|
||||
L.bind(function (err, profileText) {
|
||||
if (err) {
|
||||
console.warn('Error getting profile from "' + profileUrl + '": ' + err);
|
||||
if (cb) cb();
|
||||
return;
|
||||
}
|
||||
|
||||
// don't set when option has changed while loading
|
||||
if (!this.profileName || this.profileName === profileName) {
|
||||
this._setValue(profileText);
|
||||
}
|
||||
}, this)
|
||||
);
|
||||
} else {
|
||||
this._setValue(this.cache[profileName]);
|
||||
}
|
||||
this.cache[profileName] = profileText;
|
||||
|
||||
if (!this.pinned.hidden) {
|
||||
this.pinned.hidden = true;
|
||||
}
|
||||
// don't set when option has changed while loading
|
||||
if (!this.profileName || this.selectedProfileName === profileName) {
|
||||
this._updateProfile(profileName, profileText);
|
||||
}
|
||||
if (cb) cb();
|
||||
}, this)
|
||||
);
|
||||
} else {
|
||||
if (this.pinned.hidden) {
|
||||
this.pinned.hidden = false;
|
||||
}
|
||||
this._updateProfile(profileName, this.cache[profileName]);
|
||||
}
|
||||
}
|
||||
|
||||
if (cb && !loading) cb();
|
||||
},
|
||||
|
||||
show: function () {
|
||||
|
|
@ -101,7 +94,7 @@ BR.Profile = L.Evented.extend({
|
|||
}
|
||||
}
|
||||
|
||||
const profileText = this._getProfileText();
|
||||
const profileText = this._getSelectedProfileText();
|
||||
if (!profileText) return value;
|
||||
|
||||
const regex = new RegExp(`assign\\s*${name}\\s*=?\\s*([\\w\\.]*)`);
|
||||
|
|
@ -188,6 +181,26 @@ BR.Profile = L.Evented.extend({
|
|||
});
|
||||
},
|
||||
|
||||
_updateProfile: function (profileName, profileText) {
|
||||
const empty = !this.editor.getValue();
|
||||
const clean = this.editor.isClean();
|
||||
|
||||
// only synchronize profile editor/parameters with selection if no manual changes in full editor,
|
||||
// else keep custom profile pinned - to prevent changes in another profile overwriting previous ones
|
||||
if (empty || clean) {
|
||||
this.profileName = profileName;
|
||||
this._setValue(profileText);
|
||||
|
||||
if (!this.pinned.hidden) {
|
||||
this.pinned.hidden = true;
|
||||
}
|
||||
} else {
|
||||
if (this.pinned.hidden) {
|
||||
this.pinned.hidden = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_setValue: function (profileText) {
|
||||
profileText = profileText || '';
|
||||
|
||||
|
|
@ -363,4 +376,8 @@ BR.Profile = L.Evented.extend({
|
|||
_getProfileText: function () {
|
||||
return this.editor.getValue();
|
||||
},
|
||||
|
||||
_getSelectedProfileText: function () {
|
||||
return this.cache[this.selectedProfileName] ?? this.editor.getValue();
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -496,9 +496,11 @@ BR.TrackAnalysis = L.Class.extend({
|
|||
}
|
||||
|
||||
return typeof parsed.tracktype === 'string' && parsed.tracktype === trackType;
|
||||
} else if (dataName === 'internal-unknown' && typeof parsed.highway !== 'string') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parsed.highway === dataName;
|
||||
return typeof parsed.highway === 'string' && parsed.highway === dataName;
|
||||
case 'surface':
|
||||
return this.singleWayTagMatchesData('surface', parsed, dataName);
|
||||
case 'smoothness':
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ BR.TrackStats = L.Class.extend({
|
|||
$('#stats-container').show();
|
||||
$('#stats-info').hide();
|
||||
|
||||
const hasBeeline = segments.filter((line) => line?._routing?.beeline).length > 0;
|
||||
document.getElementById('beeline-warning').hidden = !hasBeeline;
|
||||
|
||||
var stats = this.calcStats(polyline, segments),
|
||||
length1 = L.Util.formatNum(stats.trackLength / 1000, 1).toLocaleString(),
|
||||
length3 = L.Util.formatNum(stats.trackLength / 1000, 3).toLocaleString(undefined, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue