Don't update TrackAnalysis when tab is hidden

- add missing show/hide methods called by sidebar and maintain active state
- rename inconsistent tab id
This commit is contained in:
Norbert Renner 2020-06-30 21:35:51 +02:00
parent 5ad12a7c68
commit 4892c2a1db
2 changed files with 28 additions and 2 deletions

View file

@ -791,7 +791,7 @@
</li> </li>
<li> <li>
<a <a
href="#tab_statistics" href="#tab_analysis"
role="tab" role="tab"
data-i18n="[title]sidebar.tab-tooltip" data-i18n="[title]sidebar.tab-tooltip"
data-i18n-options='{ data-i18n-options='{
@ -995,7 +995,7 @@
<div id="itinerary" class="flexcolumn flexgrow"></div> <div id="itinerary" class="flexcolumn flexgrow"></div>
</div> </div>
<div class="leaflet-sidebar-pane" id="tab_statistics"> <div class="leaflet-sidebar-pane" id="tab_analysis">
<h1 class="leaflet-sidebar-header"> <h1 class="leaflet-sidebar-header">
<span data-i18n="sidebar.analysis.title">Analysis</span> <span data-i18n="sidebar.analysis.title">Analysis</span>
<span class="leaflet-sidebar-close"><i class="fa fa-caret-right"></i></span> <span class="leaflet-sidebar-close"><i class="fa fa-caret-right"></i></span>

View file

@ -50,6 +50,28 @@ BR.TrackAnalysis = L.Class.extend({
*/ */
trackPolyline: null, trackPolyline: null,
/**
* true when tab is shown, false when hidden
*
* @type {boolean}
*/
active: false,
/**
* Called by BR.Sidebar when tab is activated
*/
show: function() {
this.active = true;
this.options.requestUpdate(this);
},
/**
* Called by BR.Sidebar when tab is deactivated
*/
hide: function() {
this.active = false;
},
/** /**
* Everytime the track changes this method is called: * Everytime the track changes this method is called:
* *
@ -63,6 +85,10 @@ BR.TrackAnalysis = L.Class.extend({
* @param {Array} segments * @param {Array} segments
*/ */
update: function(polyline, segments) { update: function(polyline, segments) {
if (!this.active) {
return;
}
if (segments.length === 0) { if (segments.length === 0) {
$('#track_statistics').html(''); $('#track_statistics').html('');
return; return;