Improve hiding elevation chart when empty
Consider additional cases: - flag got reset when deleting and adding first waypoint - don't show empty on load, postpone to update - don't store state when hidden because empty
This commit is contained in:
parent
b701a6f298
commit
2df1f617c9
2 changed files with 11 additions and 6 deletions
|
|
@ -3,15 +3,11 @@ BR.TrackStats = L.Class.extend({
|
||||||
if (segments.length == 0) {
|
if (segments.length == 0) {
|
||||||
$('#stats-container').hide();
|
$('#stats-container').hide();
|
||||||
$('#stats-info').show();
|
$('#stats-info').show();
|
||||||
this.shouldRestoreChart = $('#elevation-chart').hasClass('show');
|
|
||||||
$('#elevation-chart').collapse('hide');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#stats-container').show();
|
$('#stats-container').show();
|
||||||
$('#stats-info').hide();
|
$('#stats-info').hide();
|
||||||
if (this.shouldRestoreChart === true) $('#elevation-chart').collapse('show');
|
|
||||||
this.shouldRestoreChart = undefined;
|
|
||||||
|
|
||||||
var stats = this.calcStats(polyline, segments),
|
var stats = this.calcStats(polyline, segments),
|
||||||
length1 = L.Util.formatNum(stats.trackLength / 1000, 1).toLocaleString(),
|
length1 = L.Util.formatNum(stats.trackLength / 1000, 1).toLocaleString(),
|
||||||
|
|
|
||||||
|
|
@ -56,12 +56,13 @@ BR.Elevation = L.Control.Elevation.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initCollapse: function(map) {
|
initCollapse: function(map) {
|
||||||
|
var self = this;
|
||||||
var onHide = function() {
|
var onHide = function() {
|
||||||
$('#elevation-btn').removeClass('active');
|
$('#elevation-btn').removeClass('active');
|
||||||
// we must fetch tiles that are located behind elevation-chart
|
// we must fetch tiles that are located behind elevation-chart
|
||||||
map._onResize();
|
map._onResize();
|
||||||
|
|
||||||
if (this.id && BR.Util.localStorageAvailable()) {
|
if (this.id && BR.Util.localStorageAvailable() && !self.shouldRestoreChart) {
|
||||||
localStorage.removeItem(this.id);
|
localStorage.removeItem(this.id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -78,7 +79,7 @@ BR.Elevation = L.Control.Elevation.extend({
|
||||||
.on('shown.bs.collapse', onShow)
|
.on('shown.bs.collapse', onShow)
|
||||||
.each(function() {
|
.each(function() {
|
||||||
if (this.id && BR.Util.localStorageAvailable() && localStorage[this.id] === 'true') {
|
if (this.id && BR.Util.localStorageAvailable() && localStorage[this.id] === 'true') {
|
||||||
$(this).collapse('show');
|
self.shouldRestoreChart = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -93,9 +94,17 @@ BR.Elevation = L.Control.Elevation.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (track && track.getLatLngs().length > 0) {
|
if (track && track.getLatLngs().length > 0) {
|
||||||
|
if (this.shouldRestoreChart === true) $('#elevation-chart').collapse('show');
|
||||||
|
this.shouldRestoreChart = undefined;
|
||||||
|
|
||||||
this.addData(track.toGeoJSON(), layer);
|
this.addData(track.toGeoJSON(), layer);
|
||||||
|
|
||||||
layer.on('mouseout', this._hidePositionMarker.bind(this));
|
layer.on('mouseout', this._hidePositionMarker.bind(this));
|
||||||
|
} else {
|
||||||
|
if ($('#elevation-chart').hasClass('show')) {
|
||||||
|
this.shouldRestoreChart = true;
|
||||||
|
}
|
||||||
|
$('#elevation-chart').collapse('hide');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue