5

This is with reference to Google Tile Map or Bing Maps. Is it possible to get Tile Count, Tile X, Tile Y details without specifying zoom Level (or LevelOfDetails) with any kind of internal calculations?

Client will give just Coordinates P1 and P2 and ask for a Tile Map and Bound Box, etc.

Shilpa

Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
Shilpa Silk
  • 29
  • 1
  • 3
  • 6

3 Answers3

16

Each tile is 256 pixels by 256 pixels.

Zoom level 0 is 1 tile. (1 x 1)

Zoom level 1 is 4 tiles. (2 x 2)

Zoom level 2 is 16 tiles. (4 x 4)

Zoom level 3 is 64 tiles. (8 x 8)

Zoom level 4 is 256 tiles (16 x 16)

The x and y counts are doubled for each zoom level. Per 88ad's comment, the formula for the number of tiles is (2^zoom x 2^zoom).

I hope you can do the rest of the math through zoom level 18. To save space, ocean tiles aren't stored. They're created as a response to the request.

At zoom level 3, the tiles are numbered from 0 to 7 in the x direction (longitude) and numbered from 0 to 7 in the y direction (latitude).

The tiles start on the American side of near the International Date Line (longitude -180 or +180). The tile 0,0 starts at about latitude 70 north.

See the Wikipedia article Mercator Projection for more details about how a sphere is mapped to a plane. The calculations for converting longitude and latitude to x and y coordinates are in the Wikipedia article.

You can map any point on the Mercator Projection to a tile set. A tile set is the set of tiles at a zoom level. You have to know the zoom level to know which tile set to access and to calculate which tile in the tile set to retrieve and display.

This blog post, Google Mapping, gives the formula for converting (latitude, longitude, zoom) to (x, y, zoom), where x and y represent the tile from the zoom set.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
4

You may want to check out wiki of OSM tilenames. They are almost the same as google tiles except of y axis direction. Description with a lot of code examples is here: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames

Gleb Zykov
  • 145
  • 3
  • 1
    +1. Can't believe this resource was available and I spent the better part of the night searching eventually writing my own code for the job. Life as a coder... – Alex Essilfie Jul 25 '13 at 15:52
1

If you have a bounding box, you can use this python function for finding zoom level (or similar function in your programming language choice):

def level_dic():
    '''
    http://wiki.openstreetmap.org/wiki/Zoom_levels
    '''
    data = {0: 360.0,
        1: 180.0,
        2: 90.0,
        3: 45.0,
        4: 22.5,
        5: 11.25,
        6: 5.625,
        7: 2.813,
        8: 1.406,
        9: 0.703,
        10: 0.352,
        11: 0.176,
        12: 0.088,
        13: 0.044,
        14: 0.022,
        15: 0.011,
        16: 0.005,
        17: 0.003,
        18: 0.001,
        19: 0.0005}

    return data


def getzoom(self):
    data = level_dic()  # our presets
    a, b, c, d = bbox
    r = 3
    dne = abs(round(float(c) - float(a), r))  # ne: North East point
    mylist = [round(i, r) for i in data.values()] + [dne]
    new = sorted(mylist, reverse=True)
    return new.index(dne)

I used this reference. The rest is simple. You need to use Slippy_map_tilenames.

Farshid Ashouri
  • 16,143
  • 7
  • 52
  • 66
  • Instead of using a `dict`, you could use a `list` instead and simplify the list comprehension: `[round(i, r) for i in data] + [dne]` – beatgammit Dec 03 '14 at 16:17