1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 from __pyjamas__ import JS
16 from pyjamas.gmaps.Utils import dictToJs, createListenerMethods, listToJs
17
18
20 JS("return new $wnd['google']['maps']['Polygon'](@{{options}})")
21
23 """Accepts a dictionary of options. If necessary, transforms "paths" from
24 python list or encoded string to javascript array."""
25 if adict.has_key("paths"):
26 try:
27 if isinstance(adict["paths"], (list,tuple)):
28 adict["paths"] = listToJs(adict["paths"])
29 elif isinstance(adict["paths"], basestring):
30 adict["paths"] = decodePoly(adict["paths"])
31 except:
32 pass
33 return dictToJs(adict)
34
36 """Quickly decodes a gmaps api v2 encoded polyline... deprecated by google but still
37 a good over-the-wire compression format"""
38 JS("""
39 var i=-1,j=-1,k,l,q=@{{poly}}['match'](/[\_-\~]*[\?-\^]/g),w=0,x=0,y=0,z=1e-5;
40
41 @{{poly}}=[];
42
43 if (q) for (;;)
44 {
45 if (!q[++i]) break;
46 for (k=q[i]['length'],l=63,w=0;k--;l=95) w=(w<<5)+q[i]['charCodeAt'](k)-l;
47 y+=(w<<31>>31)^(w>>1);
48 if (!q[++i]) break;
49 for (k=q[i]['length'],l=63,w=0;k--;l=95) w=(w<<5)+q[i]['charCodeAt'](k)-l;
50 x+=(w<<31>>31)^(w>>1);
51 @{{poly}}[++j]=new $wnd['google']['maps']['LatLng'](y*z,x*z);
52 }
53 return @{{poly}}
54 """)
55