diff --git a/src/source/source_cache.js b/src/source/source_cache.js index 4082153d54f..dfebc986ee9 100644 --- a/src/source/source_cache.js +++ b/src/source/source_cache.js @@ -35,7 +35,7 @@ class SourceCache extends Evented { // for sources with mutable data, this event fires when the underlying data // to a source is changed. (i.e. GeoJSONSource#setData and ImageSource#serCoordinates) - if (this._sourceLoaded && e.dataType === "source" && e.sourceDataType === 'content') { + if (this._sourceLoaded && !this.paused && e.dataType === "source" && e.sourceDataType === 'content') { this.reload(); if (this.transform) { this.update(this.transform); @@ -97,6 +97,19 @@ class SourceCache extends Evented { return this._source; } + pause() { + this._paused = true; + } + + resume() { + if (!this._paused) return; + const shouldReload = this._shouldReloadOnResume; + this._paused = false; + this._shouldReloadOnResume = false; + if (shouldReload) this.reload(); + if (this.transform) this.update(this.transform); + } + _loadTile(tile, callback) { return this._source.loadTile(tile, callback); } @@ -139,6 +152,10 @@ class SourceCache extends Evented { } reload() { + if (this._paused) { + this._shouldReloadOnResume = true; + } + this._cache.reset(); for (const i in this._tiles) { this._reloadTile(i, 'reloading'); @@ -308,7 +325,8 @@ class SourceCache extends Evented { */ update(transform) { this.transform = transform; - if (!this._sourceLoaded) { return; } + if (!this._sourceLoaded || this._paused) { return; } + let i; let coord; let tile; @@ -507,6 +525,9 @@ class SourceCache extends Evented { * @private */ clearTiles() { + this._shouldReloadOnResume = false; + this._paused = false; + for (const id in this._tiles) this._removeTile(id); this._cache.reset(); diff --git a/src/style/style.js b/src/style/style.js index dce72ba2e3e..be1ccc957d8 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -465,7 +465,12 @@ class Style extends Evented { // https://github.com/mapbox/mapbox-gl-js/issues/3633 const removed = this._removedLayers[id]; delete this._removedLayers[id]; - this._updatedSources[layer.source] = removed.type !== layer.type ? 'clear' : 'reload'; + if (removed.type !== layer.type) { + this._updatedSources[layer.source] = 'clear'; + } else { + this._updatedSources[layer.source] = 'reload'; + this.sourceCaches[layer.source].pause(); + } } this._updateLayer(layer); @@ -507,6 +512,7 @@ class Style extends Evented { this._updatedSymbolOrder = true; if (layer.source && !this._updatedSources[layer.source]) { this._updatedSources[layer.source] = 'reload'; + this.sourceCaches[layer.source].pause(); } } } @@ -720,6 +726,7 @@ class Style extends Evented { this._updatedLayers[layer.id] = true; if (layer.source && !this._updatedSources[layer.source]) { this._updatedSources[layer.source] = 'reload'; + this.sourceCaches[layer.source].pause(); } this._changed = true; } @@ -845,6 +852,7 @@ class Style extends Evented { } _reloadSource(id) { + this.sourceCaches[id].resume(); this.sourceCaches[id].reload(); }