Google Street View Macro

Examples: NodeAmnesia
Howto: NodeMap
Download: GoogleStreetView.py

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - StreetView Macro
   4 """
   5 from MoinMoin import wikiutil
   6 import re, time
   7 _arg_lat = r'(,\s*lat=(?P<lat>\d+))?'
   8 _arg_lng = r'(,\s*lng=(?P<lng>\d+))?'
   9 _arg_yaw = r'(,\s*yaw=(?P<yaw>\d+))?'
  10 _arg_pitch = r'(,\s*pitch=(?P<pitch>\d+))?'
  11 _arg_zoom = r'(,\s*zoom=(?P<zoom>\d+))?' 
  12 _args_re_pattern = r'^(%s)?(%s)?(%s)?(%s)?(%s)?$' % (_arg_lat, _arg_lng, _arg_yaw, _arg_pitch, _arg_zoom)
  13 
  14 def execute(macro, text):
  15     request = macro.request
  16     formatter = macro.formatter
  17     _ = request.getText
  18     args_re = re.compile(_args_re_pattern)
  19     gkey = 'ABQIAAAA7rwZfsyEYZknlS0QWmZI4RQUexDMtc4eREioiWSpX_Y7fpoKghQhUCefr4eJwudYofs3YH9eyyZ3_g'
  20     gkey2 = 'ABQIAAAA7rwZfsyEYZknlS0QWmZI4RRyEbBFkcIcf1l0xXknIhElMWaAuBQ_2YFGNyOJB1ziI9lSzlpCIilgNw'
  21     #gkey = 'ABQIAAAA7rwZfsyEYZknlS0QWmZI4RQb5vo-4Bph0C_4e_e9IEgkaF03hxSX2F6kxStG0StGHPlKCc7vTMZJQQ'
  22     #gkey2 = 'ABQIAAAA7rwZfsyEYZknlS0QWmZI4RQb5vo-4Bph0C_4e_e9IEgkaF03hxSX2F6kxStG0StGHPlKCc7vTMZJQQ'
  23     
  24     if text is None:
  25         lat, lng, yaw, pitch, zoom =\
  26             45.5495012187901, -122.675131559372, 270, -10, 1
  27     else:
  28         #args = args_re.match(text)
  29         if not text:
  30              return ('<p><strong class="error">%s</strong></p>' % _('Invalid StreetView arguments "%s"!')) % (text,)
  31         else:
  32             macro_args = text.split(",") 
  33 	    try:
  34 	    	if macro_args[0].strip() != "":
  35 	   		lat = macro_args[0]
  36 	    	else:
  37 	    		lat = '45.5495012187901'
  38 	    except:
  39 	    	lat = '45.5495012187901' 
  40 	    try:
  41 	    	if macro_args[1].strip() != "":
  42 	        	lng = macro_args[1]
  43 	    	else:
  44 	    		lng = '-122.675131559372'
  45 	    except:
  46 	    	lng = '-122.675131559372'
  47 	    try:
  48 	    	if macro_args[2].strip() != "":
  49 	        	yaw = macro_args[2]
  50 	    	else:
  51 	    		yaw = '0'
  52 	    except:
  53 	    	yaw = '0'
  54 	    try:
  55 	    	if macro_args[3]:
  56 	        	pitch = macro_args[3]
  57 	    	else:
  58 	    		pitch = '0'
  59      	    except:
  60 	        pitch = '0'
  61 	    try:
  62 	    	if macro_args[4].strip() != "":
  63 	        	zoom = macro_args[4]
  64             	else:
  65 	    		zoom = '0'
  66 	    except:
  67 	    	zoom = '0'
  68 	    html = '''
  69 <script type="text/javascript">                                                                                                
  70     if( (window.location.href).indexOf("www.") == -1 ) {                                                                           
  71         writeScript("%s");                         
  72     } else {                                                                                                                       
  73         writeScript("%s");}                        
  74 function writeScript(key) {var ret='<'+'script src="http://maps.google.com/maps?file=api&v=2&key='+key+'"'+'type="text/javascript"><'+'/script>';document.write(ret);}
  75 </script>
  76     
  77 <script type="text/javascript">
  78 function addLoadEvent(func) {
  79       var oldonload = window.onload;
  80       if (typeof window.onload != 'function') {
  81         window.onload = func;
  82       }
  83       else {                     
  84         window.onload = function() {
  85             if (oldonload) {
  86                 oldonload();
  87                 }
  88             func();
  89             }
  90         }
  91       }
  92 addLoadEvent(function() {    
  93     var rand = Math.floor(Math.random()*101)
  94     document.getElementById("pano").id="pano" + rand;
  95     var myPano = new GStreetviewPanorama(document.getElementById("pano" + rand));
  96     coords = new GLatLng(%s,%s);
  97     myPOV = {yaw:%s,pitch:%s,zoom:%s};
  98     myPano.setLocationAndPOV(coords, myPOV);
  99 })    
 100 </script>
 101     <div name="pano" id="pano" style="width: 500px; height: 400px;">
 102     </div>
 103     ''' % (gkey, gkey2, lat, lng, yaw, pitch, zoom)
 104     return html
 105 

GoogleStreetView.py

Macros/GoogleStreetView (last edited 2008-11-11 21:00:50 by JasonMcArthur)