Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add straight line support to routing #497

Merged
merged 47 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
acf9c59
Initial take on supporting straight line segments
nrenner Apr 16, 2021
b4368c1
Toggle beeline mode and style beeline
nrenner Apr 29, 2021
6ea972b
Avoid accidental zooms while drawing beeline
nrenner Apr 30, 2021
b4fbae0
Add beeline button
nrenner May 5, 2021
2cd233f
Update Leaflet to 1.7.1
nrenner May 19, 2021
47f3a06
Improve route interactivity by using canvas
nrenner May 20, 2021
91108bc
Fix hidden routing marker still being interactive
nrenner May 20, 2021
84a69e0
Patch Leaflet drag offset bug
nrenner May 21, 2021
7c13476
Prevent trailer showing on beeline button clicks
nrenner May 21, 2021
9901acd
Update leaflet-routing to alpha.2
nrenner May 27, 2021
eb8492e
Fix loading trailer animation
nrenner Jun 3, 2021
cafb87c
Add basic beeline support by dummy feature
nrenner Jun 9, 2021
c3db03d
Keep ele when removing duplicates on concat
nrenner Jun 11, 2021
da2043f
Break after self-closing trkpt without ele (beeline)
nrenner Jun 12, 2021
f3d48dc
Add message headings to fix error in data tab
nrenner Jun 12, 2021
3c8be96
Support beelines in hash url (first stab)
nrenner Jun 19, 2021
044dab0
Encode beeline hash as indexes
nrenner Jun 23, 2021
39f3a10
Support beelines in data and analysis tabs (WIP)
nrenner Jun 25, 2021
f185d78
Support undefined highway tag for beelines
nrenner Jun 29, 2021
9f4a498
Support beelines on reverse
nrenner Jul 1, 2021
7118cc7
Show empty cells in data tab instead of 0
nrenner Jul 1, 2021
fe05081
Add beeline support to distance markers
nrenner Jul 2, 2021
af1a118
Initial client-side stats from BRouter StdPath.java
nrenner Oct 4, 2021
bd2e89e
Temporarily add transpiled BRouter CheapRuler
nrenner Oct 8, 2021
7c8c71a
Add stats track tests (failing)
nrenner Oct 14, 2021
025eb02
Fix stats tests by summarizing integer distances
nrenner Jan 20, 2022
6ee2b45
Update track.json
nrenner Jan 21, 2022
6db0ce8
Fix track.json source comment
nrenner Jan 28, 2022
9abf4b9
Calc stats for straight line
nrenner Feb 7, 2022
4d44153
Read time/energy calc variables from profile
nrenner Feb 15, 2022
7bbbffb
Get selected profile vars despite pinned custom
nrenner Feb 16, 2022
41a3b8f
Update leaflet-routing
nrenner Feb 17, 2022
30f8a88
Interpolate stats over consecutive beelines
nrenner Apr 1, 2022
2f8ddfa
Interpolate ascend stats
nrenner Apr 6, 2022
5dd801d
Interpolate cost by using max of neighbours
nrenner Apr 9, 2022
42d8b27
Add time and energy to messages
nrenner Apr 11, 2022
c122b31
Replace ??=, not supported by i18next-scanner
nrenner Apr 11, 2022
6a19b53
Add interpolated warning for stats with beeline
nrenner Apr 11, 2022
7f481b8
Pass estimated cost factor to kinematic calc
nrenner Apr 26, 2022
855dc81
Show gap in elevation graph for single beeline
nrenner May 2, 2022
72588f3
Only use Canvas for routing segments
nrenner May 4, 2022
2badd9f
Update leaflet-routing
nrenner May 5, 2022
049ba84
Update leaflet-routing (yarn.lock)
nrenner May 5, 2022
31916c2
Omit beelines in quality coding
nrenner May 6, 2022
d8e0e8e
Simplify response check, beeline has feature now
nrenner May 6, 2022
0087d31
Add beeline hint to segment tooltip
nrenner May 10, 2022
89dff44
Update leaflet-routing
nrenner May 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@
nodata: {
color: 'darkred',
},
beeline: {
weight: 5,
dashArray: [1, 10],
color: 'magenta',
opacity: BR.conf.defaultOpacity,
},
beelineTrailer: {
weight: 5,
dashArray: [1, 10],
opacity: 0.6,
color: 'magenta',
},
};

BR.conf.markerColors = {
Expand Down
16 changes: 16 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,22 @@ button.btn {
line-height: 30px;
}

button.activate-beeline-active,
button.deactivate-beeline-active {
transition-duration: 0.3s;
}
button.activate-beeline-active.disabled,
button.deactivate-beeline-active.disabled {
height: 0;
border-bottom-width: 0px;
}
.mdi.active {
fill: #2074b6;
}
.mdi {
width: 18px;
}

/* smaller tab height */
.nav > li > a {
padding: 2px 15px;
Expand Down
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,16 @@ <h1 class="leaflet-sidebar-header">
</div>
<div id="stats-container" class="flexrow flexgrow">
<ul id="stats">
<li id="beeline-warning" hidden>
<div class="text-muted small d-none d-md-block">&#8239;</div>
<p class="stats-label">
<abbr
class="fa fa-exclamation-triangle"
data-i18n="[title]footer.beeline-warning"
title="Warning: no data for straight lines, values interpolated"
></abbr>
</p>
</li>
<li>
<div class="text-muted small d-none d-md-block" data-i18n="footer.distance">Distance</div>
<p class="stats-label">
Expand Down
6 changes: 4 additions & 2 deletions js/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ BR.Map = {

var maxZoom = 19;

if (BR.Browser.touch) {
L.Draggable.prototype.options.clickTolerance = 10;
}

map = new L.Map('map', {
zoomControl: false, // add it manually so that we can translate it
worldCopyJump: true,
minZoom: 0,
maxZoom: maxZoom,
// fix for route drag on mobile (#285), until next Leaflet version released (> 1.6.0)
tap: false,
});

if (BR.Util.getResponsiveBreakpoint() >= '3md') {
Expand Down
21 changes: 18 additions & 3 deletions js/control/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
87 changes: 52 additions & 35 deletions js/control/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.cache[profileName] = profileText;

// 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.selectedProfileName = profileName;

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;
}

if (!this.pinned.hidden) {
this.pinned.hidden = true;
}
this.cache[profileName] = profileText;

// 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 () {
Expand All @@ -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\\.]*)`);
Expand Down Expand Up @@ -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 || '';

Expand Down Expand Up @@ -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();
},
});
4 changes: 3 additions & 1 deletion js/control/TrackAnalysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,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':
if (dataName === 'internal-unknown' && typeof parsed.surface !== 'string') {
return true;
Expand Down
3 changes: 3 additions & 0 deletions js/control/TrackStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
6 changes: 5 additions & 1 deletion js/format/Xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ BR.Xml = {
}
} else {
if (singleLineTagList.includes(tag)) {
singleLineTag = tag;
const closeIndex = xml.indexOf('>', match.index + 1);
const selfClosing = xml.charAt(closeIndex - 1) === '/';
if (!selfClosing) {
singleLineTag = tag;
}
}
let endIndex = match.index + 1;
lines.push(xml.substring(startIndex, endIndex));
Expand Down
Loading