1
2 """
3 MoinMoin - GetStreetView Macro
4 Tool to get lat, lng, yaw, pitch and zoom for GoogleStreetView macro.
5 ver 1.2
6 by JasonMcArthur <jason@denied.to>
7 1.4 - removed some nasty, added reverse geo and update on zoom.
8 1.2 - no timeOut() on stats output so user can select it.
9
10 """
11
12 def execute(macro,text):
13 gkey = 'ABQIAAAA7rwZfsyEYZknlS0QWmZI4RQb5vo-4Bph0C_4e_e9IEgkaF03hxSX2F6kxStG0StGHPlKCc7vTMZJQQ'
14 gkey2 = 'ABQIAAAA7rwZfsyEYZknlS0QWmZI4RQb5vo-4Bph0C_4e_e9IEgkaF03hxSX2F6kxStG0StGHPlKCc7vTMZJQQ'
15 math = '%'
16 html = '''
17 <script type="text/javascript">
18 // set proper key for www. and wiki. subdomains.
19 if( (window.location.href).indexOf("www.") == -1 ) {
20 writeScript("%s");
21 } else {
22 writeScript("%s");}
23 function writeScript(key) {var ret='<'+'script src="http://maps.google.com/maps?file=api&v=2.x&key='+key+'"'+'type="text/javascript"><'+'/script>';document.write(ret);}
24 </script>
25 <script type="text/javascript">
26 var map;
27 var myPano;
28 var panoClient;
29 var nextPanoId;
30 var center = new GLatLng(45.52310,-122.67133);
31
32 function initMap() {
33 panoClient = new GStreetviewClient();
34 // setup and configure map
35 map = new GMap2(document.getElementById("mapDiv"));
36 map.setMapType(G_HYBRID_MAP);
37 map.addControl(new GScaleControl());
38 map.addControl(new GMapTypeControl());
39 map.addControl(new GSmallMapControl());
40 map.setCenter(center, 15);
41 map.enableContinuousZoom();
42 map.enableScrollWheelZoom();
43
44 // setup draggable and rotating guy icon
45 var guyIcon = new GIcon(G_DEFAULT_ICON);
46 guyIcon.image = "http://maps.google.com/intl/en_us/mapfiles/cb/man_arrow-0.png";
47 guyIcon.transparent = "http://maps.google.com/intl/en_us/mapfiles/cb/man-pick.png";
48 guyIcon.imageMap = [
49 26,13, 30,14, 32,28, 27,28, 28,36, 18,35, 18,27, 16,26,
50 16,20, 16,14, 19,13, 22,8
51 ];
52 guyIcon.iconSize = new GSize(49, 52);
53 guyIcon.iconAnchor = new GPoint(25, 35); // near base of guy's feet
54 guyIcon.infoWindowAnchor = new GPoint(25, 5); // top of guy's head
55
56 marker = new GMarker(center, {icon: guyIcon, draggable: true});
57 map.addOverlay(marker);
58 lastMarkerLocation = center;
59 GEvent.addListener(marker, "dragend", onDragEnd);
60 GEvent.addListener(marker, "click", showPanoData);
61
62 // update streetview client when location is selected on map
63 GEvent.addListener(map, "click", function(overlay,latlng) {
64 panoClient.getNearestPanorama(latlng, showPanoData);
65 marker.setLatLng(latlng);
66 });
67
68 // setup and configure streetview client
69 var POV = {yaw:0,pitch:-5};
70 panoClient = new GStreetviewClient();
71 myPano = new GStreetviewPanorama(document.getElementById("pano"));
72 myPano.setLocationAndPOV(center, POV);
73 GEvent.addListener(myPano, "error", handleNoFlash);
74 panoClient.getNearestPanorama(center, showPanoData);
75 GEvent.addListener(myPano, "yawchanged", showStats);
76 GEvent.addListener(myPano, "yawchanged", onYawChange);
77 GEvent.addListener(myPano, "zoomchanged", showStats);
78 // update map as user moves locations in the streetview client
79 GEvent.addListener(myPano, "initialized", function(call) {
80 var center = call.latlng;
81 map.setCenter(center);
82 marker.setLatLng(center);
83 panoClient.getNearestPanorama(center, showPanoData);
84 });
85 showStats();
86 }
87
88 function showPanoData(panoData) {
89 // get and fill out infowindow
90 if (panoData.code != 200) {
91 GLog.write('showPanoData: Server rejected with code: ' + panoData.code);
92 return;
93 }
94 myPano.setLocationAndPOV(panoData.location.latlng);
95 GEvent.addListener(myPano, "newpano", onNewLocation);
96 showStats();
97 }
98
99 function showStats() {
100 // return POV and coords
101 var geocoder = null;
102 geocoder = new GClientGeocoder();
103 var stats = "";
104 var pov = myPano.getPOV();
105 estats = "<<GoogleStreetView" + marker.getLatLng() + "," + pov.yaw + "," + pov.pitch + "," + pov.zoom;
106 stats = estats.replace(/( |\))/g, "");
107 document.getElementById("statDiv").innerHTML = stats + ")>>";
108 point = marker.getLatLng();
109 // Reverse Geocoder
110 geocoder.getLocations(point, function(addresses) {
111 if(addresses.Status.code != 200) {
112 document.getElementById("statDesc").innerHTML = "<br />No address found";
113 } else {
114 address = addresses.Placemark[0];
115 var myHtml = address.address;
116 document.getElementById("statDesc").innerHTML = "<br />" + myHtml;
117 }
118 });
119 }
120
121 function next() {
122 // Get the next panoId
123 panoClient.getPanoramaById(nextPanoId, showPanoData, showStats);
124 }
125
126 function onYawChange(newYaw) {
127 var GUY_NUM_ICONS = 16;
128 var GUY_ANGULAR_RES = 360/GUY_NUM_ICONS;
129 if (newYaw < 0) {
130 newYaw += 360;
131 }
132 guyImageNum = Math.round(newYaw/GUY_ANGULAR_RES) %s GUY_NUM_ICONS;
133 guyImageUrl = "http://maps.google.com/intl/en_us/mapfiles/cb/man_arrow-" + guyImageNum + ".png";
134 //guyImageUrl = "http://maps.google.com/intl/en_us/mapfiles/cb/man_arrow-16,14.png";
135 marker.setImage(guyImageUrl);
136 }
137
138 function onNewLocation(lat, lng) {
139 var center = new GLatLng(lat, lng);
140 marker.setLatLng(center);
141 showStats();
142 }
143
144 function onDragEnd() {
145 var center = marker.getLatLng();
146 if (myPano) {
147 panoClient.getNearestPanorama(center, onResponse);
148 showStats();
149 }
150 }
151
152 function onResponse(response) {
153 if (response.code != 200) {
154 marker.setLatLng(lastMarkerLocation);
155 } else {
156 var center = new GLatLng(response.Location.lat, response.Location.lng);
157 marker.setLatLng(center);
158 lastMarkerLocation = center;
159 panoClient.getNearestPanorama(center, showPanoData);
160 myPano.setLocationAndPOV(marker.getLatLng(), null)
161 showStats();
162 }
163 }
164
165 function handleNoFlash(errorCode) {
166 if (errorCode == FLASH_UNAVAILABLE) {
167 alert("Error: Flash doesn't appear to be supported by your browser");
168 return;
169 }
170 }
171 </script>
172 <script type="text/javascript">
173 window.onload = initMap
174 window.onunload=GUnload
175 </script>
176 <span id="statDiv" style=""></span>
177 <span id="statDesc" style=""></span>
178 <span id="statLink"></span>
179 <div id="pano" style="width:350px;height:350px;border:1px solid #000;float:left;"></div>
180 <div id="mapDiv" style="width350px;height:350px;border:1px solid #000;margin-left:355px;"></div>
181 ''' % (gkey, gkey2, math)
182 return html
183