473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1574

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

Similar topics

0
by: Edward C. Jones | last post by:
Terence Parr, the inventer of ANTLR, gave his students a lab exercise: "They will take the python BNF specs from the distribution and the website (parser and lexer) and build a translator that...
2
by: Michael Foord | last post by:
Please pardon my ignorance on this one - but I'm not certain how the sign bt is treated in python bitwise operators. I've trying to convert a javascript DES encryption routine into python. ...
1
by: whimsica | last post by:
I'm investingating a c++ api, Panda3d.com, that has a python binding. I want to convert this api into an ACtiveX control so it will run on the web. When I do so I want to use Microsoft Script...
0
by: David Pratt | last post by:
Hi. I am putting together a database application on Zope. I have built a pager for my records (20 per page) but do not want the browser scroll bars to reset to the top of the browser each time the...
2
by: Eric CHAO | last post by:
I know py2exe can make an exe file. But python runtime dll is still there. How can I combine the dll file into the exe, just make one file? Thanks.
6
by: ogtheterror | last post by:
Hi I have a very limited understanding of Python and have given this the best shot i have but still have not been able to get it working. Is there anyone that knows how to get this into a .net...
4
by: hyperman7 | last post by:
I saved the code below to an external file which I called colorFader.js, and I'm calling it with: <script type="text/javascript" src="js/colorFader.js"></script> My path (above) is correct, so...
8
by: toanmh | last post by:
I have code to unwrap package. But i don'nt know python language. Please help me to convert this code to C# or Java. Thanks for help.! import re import base64 import zlib import sys #...
2
by: Alex Ivanov | last post by:
Hi everybody! I want automatically create many folders with the python files inside. Those python files I want to fill in with the text, which is python code. So I want to insert that code as a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.