Is there a way to figure out if every tile of an ol.source.TileWMS is loaded?

My attempt so far is the following:

var tileColl = new ol.Collection()
tileColl.on('change:length, function(e){
     if(e.target.getLength === 0){
tileWms.on('tileloadstart, function(e){
tileWms.on('tileloadend, function(e){

Unfortunately, this fails because sometimes all tiles in the list are loaded before all tileloadstart-Events are fired -eventually the collection becomes empty. (Probably because the number of request send by the browser is limited)

I removed all interactions, so the user cannot move the view. I know I can solve the problem by using (for example) ol.source.ImageWMS but I prefer using ol.source.TileWMS because it has some visible progress when the tiles are loading.

Some ideas I had but could not make them work: Calculate the number of tiles that are to load, Figuring out the last tile which is to load.

Is there way to achieve this?

1 Answer 1


I guess I found a solution to get the number of tiles that are to load. I hope this is reliable.

var tg= (_tileWMS.getTileGrid()) ? ol.tilegrid.getForProjection(_view.getProjection()) : _tileWMS.getTileGrid(); //if you do not use default tileGrid var z = tg.getZForResolution(_view.getResolution()); var tileRange=tg.getTileRangeForExtentAndZ(_view.calculateExtent(_map.getSize()),z); var xTiles = tileRange['maxX']-tileRange['minX'] +1; var yTiles = tileRange['maxY']-tileRange['minY'] +1; _tilesToLoad = xTiles*yTiles;

Note that some of the used functions are not part of the documentation, so they might change them in a future release without any further hint.

  • 1
    It looks like the API did indeed change and break this method in v4 - this doesn't work in v4.6.5. Commented Jan 29, 2019 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.