1 | ## Script (Python) "edit_js" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters= result=None, longlat=[] |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | |
---|
11 | lat = [] |
---|
12 | lon = [] |
---|
13 | map_center = (0,0) |
---|
14 | sMarker = "" |
---|
15 | sGlobVars = "var autoZoom=null, autoCenter=null;" |
---|
16 | |
---|
17 | if longlat: |
---|
18 | lat = [float(e.geoLocation[0]) for el in longlat.values() for e in el] |
---|
19 | lon = [float(e.geoLocation[1]) for el in longlat.values() for e in el] |
---|
20 | |
---|
21 | if lat and lon: |
---|
22 | sGlobVars = """ |
---|
23 | autoCenter = [%f, %f]; |
---|
24 | autoZoom = map3.getBoundsZoomLevel(new GLatLngBounds(new GLatLng(%f, %f), new GLatLng(%f, %f)));""" % ((min(lat)+max(lat))/2, (min(lon)+max(lon))/2, min(lat), min(lon), max(lat), max(lon)) |
---|
25 | |
---|
26 | if result: |
---|
27 | map_center = (float(result[0]), float(result[1])) |
---|
28 | sMarker = """ |
---|
29 | var point = new GLatLng(parseFloat(%f), parseFloat(%f)); |
---|
30 | var marker = new GMarker(point); |
---|
31 | map3.addOverlay(marker);""" % (map_center[0], map_center[1]) |
---|
32 | |
---|
33 | return """ |
---|
34 | <script src="http://maps.google.com/maps?file=api&v=2&key=%(key)s" type="text/javascript"></script> |
---|
35 | <script type="text/javascript"> |
---|
36 | //<![CDATA[ |
---|
37 | |
---|
38 | function onMapLoad() { |
---|
39 | if (GBrowserIsCompatible()) { |
---|
40 | var lat = document.getElementById("maplatitude"), |
---|
41 | lng = document.getElementById("maplongitude"), |
---|
42 | map3 = new GMap2(document.getElementById("mapView")); |
---|
43 | this.mp = map3; |
---|
44 | map3.addControl(new GLargeMapControl()); |
---|
45 | map3.addControl(new GMapTypeControl()); |
---|
46 | map3.addControl(new GOverviewMapControl()); |
---|
47 | map3.setCenter(new GLatLng(parseFloat(%(lat)f), parseFloat(%(lng)f)), 6, G_HYBRID_MAP); |
---|
48 | %(globvars)s |
---|
49 | %(marker)s |
---|
50 | |
---|
51 | function addMarker(lat, lng){ |
---|
52 | var point = new GLatLng(lat, lng); |
---|
53 | var marker = new GMarker(point) |
---|
54 | map3.addOverlay(marker); |
---|
55 | }; |
---|
56 | |
---|
57 | GEvent.addListener(map3, 'click', function(marker, point) { |
---|
58 | if (!marker){ |
---|
59 | map3.clearOverlays(); |
---|
60 | addMarker(point.y, point.x); |
---|
61 | lat.value = point.y; |
---|
62 | lng.value = point.x; |
---|
63 | } |
---|
64 | }); |
---|
65 | return {'widgetMap':map3, 'autoZoom':autoZoom, 'autoCenter':autoCenter}; |
---|
66 | } |
---|
67 | else { |
---|
68 | window.alert("Google maps aren't compatible with current Browser."); |
---|
69 | return null; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | var globMap = onMapLoad(); |
---|
74 | |
---|
75 | registerEventListener(window, 'unload', GUnload); |
---|
76 | |
---|
77 | //]]> |
---|
78 | </script> """ % { |
---|
79 | 'key' : context.getMapKey(), |
---|
80 | 'lat' : map_center[0], |
---|
81 | 'lng' : map_center[1], |
---|
82 | 'marker' : sMarker, |
---|
83 | 'globvars' : sGlobVars |
---|
84 | } |
---|