471,337 Members | 851 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

convert python to javascript

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]
Dec 16 '07 #1
0 1409

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Edward C. Jones | last post: by
2 posts views Thread by Michael Foord | last post: by
reply views Thread by David Pratt | last post: by
2 posts views Thread by Eric CHAO | last post: by
8 posts views Thread by toanmh | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.