I want to get the total number of tiles needed to be loaded currently.
The reason is to have a smooth loading bar for the map. I know about the demo at openlayers, but for me, that bar jumps all over the place (goes back and forth) because many times tileloadstart
is called after some tiles have loaded already. That causes the max to change and brings the bar back.
So is there a way (even if it's customizing OL) to get the total number of tiles (the final number of total tileloadstart
calls) at the time of calling?
Asked
Active
Viewed 454 times
2

KayleMaster
- 331
- 2
- 13
-
1By no means a complete answer, but if you have the current zoom level and extent of the map, it should definitely be possible to calculate the number of tiles yourself. Probably you'd have to find the size of a single tile for each zoom level, and then check how many tiles are needed for the current extent of the map. – Michael Kunst Oct 01 '18 at 15:07
-
@MichaelKunst That's ... exactly what I needed! For some reason I didn't think of this. If you make this into an answer I'll mark it as solved. (and maybe in the future I can edit your comment with the solution - or contribute to OL) – KayleMaster Oct 02 '18 at 10:04
-
1Don't think I really have enough for an answer. But when you got it running it would be great if you could add it as an answer yourself, showing what you actually had to to :-) – Michael Kunst Oct 04 '18 at 14:36
-
Good idea, thanks! – KayleMaster Oct 04 '18 at 19:42
-
@KayleMaster Did you ever come up with a good way of doing this calculation? – djhoese Aug 04 '20 at 17:05
-
@djhoese Unfortunately, no. The work warranted wasn't worth the expected result and I had more important stuff to do at my job (I'd really like to do this though). – KayleMaster Aug 30 '20 at 12:25
1 Answers
2
Sorry to dig up an old question, but I was stuck on that matter today and found an easy solution. This issue is not really covered throughout the web, so I'll post a function that counts tiles whithout having to load them beforehands. It is based on the forEachTileCoord(extent, zoom, callback)
method of a TileGrid.
function getTileCount(map, tileGrid) {
let size = map.getSize();
let view = map.getView();
let extent = view.calculateExtent(size);
let zoom = view.getZoom();
let count = 0;
tileGrid.forEachTileCoord(extent, zoom, function() {
++count;
});
return count
}

BFlat
- 174
- 11