We have some layers that make use of a ol.source.XYZ
source. For the loading strategy we use ol.loadingstrategy.tile(new ol.tilegrid.createXYZ({}))
. We need to ensure that all tiles have been completely loaded in the map view before proceeding with other operations.
We have come across multiple articles regarding this and haven't found a 100% solution yet that will give us the solution we need. The logic returns true even when it's not the case. We've tried to make use of the tileloadstart, tileloadend, tileloaderror events as shown on the example page but this doesn't seem to always return the expected result.
The GIS Stack Exchange article here seemed promising because we could use the code listed below in conjunction with tileloadstart/tileloadend events but there are a number of the function calls that are only available in ol-debug.js and not the ol.js source code. Because of this the code pasted below does not work with ol.js. This code is just a copy from the referenced GIS Stack Exchange article.
function calculateNumberOfTiles(tileSource) {
var tg = (tileSource.getTileGrid()) ? tileSource.getTileGrid(): ol.tilegrid.getForProjection(map.getView().getProjection()),
z = tg.getZForResolution(map.getView().getResolution()),
tileRange = tg.getTileRangeForExtentAndZ(map.getView().calculateExtent(map.getSize()), z),
xTiles = tileRange['maxX'] - tileRange['minX'] + 1,
yTiles = tileRange['maxY'] - tileRange['minY'] + 1;
return xTiles * yTiles;
}
I have two questions, can anyone please provide any additional thoughts in what we may be missing? Thanks for your help.
- Why are the function calls available in ol-debug.js and not ol.js when they hang off of the prototype of tilegrid object?
- Any other suggestions how to tell all tiles are completely loaded in the map?