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) {
|
||||
$('#stats-container').hide();
|
||||
$('#stats-info').show();
|
||||
this.shouldRestoreChart = $('#elevation-chart').hasClass('show');
|
||||
$('#elevation-chart').collapse('hide');
|
||||
return;
|
||||
}
|
||||
|
||||
$('#stats-container').show();
|
||||
$('#stats-info').hide();
|
||||
if (this.shouldRestoreChart === true) $('#elevation-chart').collapse('show');
|
||||
this.shouldRestoreChart = undefined;
|
||||
|
||||
var stats = this.calcStats(polyline, segments),
|
||||
length1 = L.Util.formatNum(stats.trackLength / 1000, 1).toLocaleString(),
|
||||
|
|
|
|||
|
|
@ -56,12 +56,13 @@ BR.Elevation = L.Control.Elevation.extend({
|
|||
},
|
||||
|
||||
initCollapse: function(map) {
|
||||
var self = this;
|
||||
var onHide = function() {
|
||||
$('#elevation-btn').removeClass('active');
|
||||
// we must fetch tiles that are located behind elevation-chart
|
||||
map._onResize();
|
||||
|
||||
if (this.id && BR.Util.localStorageAvailable()) {
|
||||
if (this.id && BR.Util.localStorageAvailable() && !self.shouldRestoreChart) {
|
||||
localStorage.removeItem(this.id);
|
||||
}
|
||||
};
|
||||
|
|
@ -78,7 +79,7 @@ BR.Elevation = L.Control.Elevation.extend({
|
|||
.on('shown.bs.collapse', onShow)
|
||||
.each(function() {
|
||||
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 (this.shouldRestoreChart === true) $('#elevation-chart').collapse('show');
|
||||
this.shouldRestoreChart = undefined;
|
||||
|
||||
this.addData(track.toGeoJSON(), layer);
|
||||
|
||||
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