Counting slippy map tiles

I would like to calculate approximately, how many tiles of given size would need to be rendered for a given bounding box and zoom level range in a given projection (always 3857).

For example, for:

• Tilesize: 256x256 pixels
• Longitude: 15-25°
• Latitude 10-20°
• Zoom levels 5-15

I know that number of tiles at zoom level nx = 4^x.

I think the procedure goes like this: add 1 tile for every level in which one tile is still enough to cover the entire bounding box. For every level further down, assume tiles scale based on the equation above.

Therefore my question is: How do I know the last zoom level on which I can cover the bounding box with 1 tile?

-

There is more than one approach to this problem. You could approach it by saying that you want to define the top level zoom as 1 x 1 tile (256 x 256 pixels) at the area you care about (which I take from your question is 10 degrees by 10 degrees, but it would be cleaner if you defined it in metres, since that is what you are using with EPSG:3857).

You could choose to use a Well Known Scale Set (see WMTS Appendix E).

You could choose to use TMS (like OpenStreetMap). See http://wiki.openstreetmap.org/wiki/Tile_Disk_Usage

-
the link you posted was helpful for me to have some idea. The area may very in the shape and size a lot, think bounding box for a certain country. They differ greatly. And yes, units are indeed meters, i just used degrees because you imagine the size of the area more easily – U2ros Sep 24 '12 at 12:47