hey all,
found this nice snippet of code to convert between 2 google map tile types, from satellite to map images. My problem is that the code is written in python, a language I cannot fully read. Would be most thankful is someone could rewrite this code to javascript, so I can use it for my project. thx and hopefully i ones can return the favour
http://mt2.google.com/mt?n=w2.5&x=20&y=49&zoom=10 (map)
http://kh.google.com/kh?v=3&t=tqtsqrqt (satellite)
Here's the conversion routine between x,y,zoom and quadtree
[PHP]
def quadtree(x,y, zoom):
out = []
m = {(0,0):'q', (0,1):'t', (1,0):'r', (1,1):'s'}
for i in range(17-zoom):
x, rx = divmod(x, 2)
y, ry = divmod(y, 2)
out.insert(0, m[(rx,ry)])
return 't' + ''.join(out)
[/PHP]
Then to convert back
[PHP]
def xyzoom(quad):
x, y, z = 0, 0, 17
m = {'q':(0,0), 't':(0,1), 'r':(1,0), 's':(1,1)}
for c in quad[1:]:
x = x*2 + m[c][0]
y = y*2 + m[c][1]
z -= 1
return x, y, z
[/PHP]
Using them
[PHP]
>>> quadtree(20,49,10)
'tqtsqrqt'
>>> xyzoom('tqtsqrqt')
(20, 49, 10)
>>> sat_url = 'http://kh.google.com/kh?v=3&t=' + quadtree(20,49,10)[/PHP]