1

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){
        console.log('ready!');
    }
});
tileWms.on('tileloadstart, function(e){
    tileColl.push(e.tile);
}
tileWms.on('tileloadend, function(e){
 tileColl.remove(e.tile);
}

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?

2

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.

  • It looks like the API did indeed change and break this method in v4 - this doesn't work in v4.6.5. – Gareth Jones Jan 29 '19 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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