From 0fd5d9cedafd6e4bc32fee227f7a86df12dedc8d Mon Sep 17 00:00:00 2001 From: Tek Kshetri <39838116+iamtekson@users.noreply.github.com> Date: Tue, 13 Jun 2023 15:19:34 -0600 Subject: [PATCH 1/2] close #9 --- src/MVTSource.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/MVTSource.js b/src/MVTSource.js index ecbc1e6..ce91898 100644 --- a/src/MVTSource.js +++ b/src/MVTSource.js @@ -1,5 +1,5 @@ /* - * Created by Jes�s Barrio on 04/2021 + * Created by Jesús Barrio on 04/2021 */ class MVTSource { @@ -57,6 +57,8 @@ class MVTSource { this._tilesDrawn = []; // List of tiles drawn (when cache enabled) this._visibleTiles = []; // tiles currently in the viewport this._selectedFeatures = []; // list of selected features + this.loadedTilesLen = 0; // total number of loaded tiles + if (options.selectedFeatures) { this.setSelectedFeatures(options.selectedFeatures); } @@ -107,6 +109,7 @@ class MVTSource { } tileContext = this._createTileContext(coord, zoom, ownerDocument); + this.loadedTilesLen = 0; this._xhrRequest(tileContext); return tileContext; } @@ -196,6 +199,28 @@ class MVTSource { var vectorTile = new VectorTile(pbf); this._drawVectorTile(vectorTile, tileContext); } + + tileLoaded() { + const lenVisibleTiles = Object.keys(this._visibleTiles).length; + let self = this; + + return new Promise(function (resolve, reject) { + let timer; + + if (lenVisibleTiles && lenVisibleTiles == self.loadedTilesLen) { + clearTimeout(timer); + resolve(true); + } else { + timer = setTimeout(() => { + resolve( + self.tileRendered().then((a) => { + return a; + }) + ); + }, 100); + } + }); + } _setTileDrawn(tileContext) { if (!this._cache) return; @@ -502,4 +527,4 @@ class MVTSource { this.redrawAllTiles(); } } -} \ No newline at end of file +} From 41fd5366f50ae9eb172472e41929bcb7d4a7b447 Mon Sep 17 00:00:00 2001 From: Tek Kshetri <39838116+iamtekson@users.noreply.github.com> Date: Tue, 13 Jun 2023 15:24:53 -0600 Subject: [PATCH 2/2] fix recursive function typo --- src/MVTSource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MVTSource.js b/src/MVTSource.js index ce91898..c4dd737 100644 --- a/src/MVTSource.js +++ b/src/MVTSource.js @@ -213,7 +213,7 @@ class MVTSource { } else { timer = setTimeout(() => { resolve( - self.tileRendered().then((a) => { + self.tileLoaded().then((a) => { return a; }) );