Skip to content

Commit

Permalink
Merge pull request #10 from iamtekson/patch-1
Browse files Browse the repository at this point in the history
close #9
Thanks for contribution
  • Loading branch information
techjb committed Jun 14, 2023
2 parents 96daed0 + 41fd536 commit 8c35632
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/MVTSource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Created by Jesús Barrio on 04/2021
* Created by Jesús Barrio on 04/2021
*/

class MVTSource {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -107,6 +109,7 @@ class MVTSource {
}

tileContext = this._createTileContext(coord, zoom, ownerDocument);
this.loadedTilesLen = 0;
this._xhrRequest(tileContext);
return tileContext;
}
Expand Down Expand Up @@ -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.tileLoaded().then((a) => {
return a;
})
);
}, 100);
}
});
}

_setTileDrawn(tileContext) {
if (!this._cache) return;
Expand Down Expand Up @@ -502,4 +527,4 @@ class MVTSource {
this.redrawAllTiles();
}
}
}
}

0 comments on commit 8c35632

Please sign in to comment.