Attachment 'Gmap.py'

Download

   1 import md5
   2 """
   3 Gmap Macro
   4 by Gavin Kou<gavin.kou@itbbq.com>
   5 Output the JavaScript edition google map
   6 
   7 <<Gmap(latitude,longitude,zoomLevel=10,width=600,height=600,type=2, marker=None)>>
   8 
   9 <<Gmap(latitude,longtitude)>>
  10 
  11 type:
  12 
  13 0: ROADMAP
  14 1: SATELLITE
  15 2: HYBRID
  16 3: TERRAIN
  17 
  18 output sample:
  19 
  20 <script type="text/javascript"  src="http://maps.google.com/maps/api/js?sensor=false">
  21 </script>
  22 <script type="text/javascript" >
  23 function initGmap_534af8a7d18890ac0b692cfd5f9abbbb() {
  24 var latlng = new google.maps.LatLng(30.73239, 90.62073);
  25 var myOptions = {
  26 zoom: 10,
  27 center: latlng,
  28 mapTypeId: google.maps.MapTypeId.HYBRID
  29 };
  30 var map = new google.maps.Map(document.getElementById("534af8a7d18890ac0b692cfd5f9abbbb"), myOptions);
  31 }
  32 if (document.all) {
  33 window.attachEvent('onload', initGmap_534af8a7d18890ac0b692cfd5f9abbbb );
  34 } else {
  35 window.addEventListener('load', initGmap_534af8a7d18890ac0b692cfd5f9abbbb , false);
  36 </script>
  37 
  38 
  39 more information  please refer to
  40 http://code.google.com/intl/en/apis/maps/documentation/javascript/introduction.html
  41 
  42 """
  43 def macro_Gmap(macro, latitude,longitude,zoomLevel=10,width=600,height=600,type=2,marker=None):
  44     div_id = md5.new( "%s,%s"% ( latitude, longitude) ).hexdigest()
  45     gmap_js_function = "initGmap_%s " % (div_id )
  46     gmap_type = ['ROADMAP','SATELLITE','HYBRID','TERRAIN']
  47     if marker:
  48         marker_js = """
  49         var marker = new google.maps.Marker({
  50             position: latlng,
  51             map: map,
  52             title: %s
  53               }); """ % marker
  54     else:
  55         marker_js=""
  56         
  57     gmap_v3= """
  58     <script type="text/javascript"
  59     src="http://maps.google.com/maps/api/js?sensor=false">
  60     </script>
  61     <script type="text/javascript" defer="true" >
  62     function %(gmap_js_function)s(){
  63           var latlng = new google.maps.LatLng(%(latitude)s, %(longitude)s);
  64           var myOptions = {
  65           zoom: %(zoomLevel)s,
  66           center: latlng,
  67           mapTypeId: google.maps.MapTypeId.%(gmap_type)s
  68           };
  69           var map = new google.maps.Map(document.getElementById("%(div_id)s"), myOptions);
  70           %(marker_js)s
  71           }
  72 
  73           if (document.all) {
  74           window.attachEvent('onload', %(gmap_js_function)s);
  75           } else {
  76           window.addEventListener('load', %(gmap_js_function)s, false);
  77           }
  78 
  79         </script>
  80         <div id="%(div_id)s" style="width: %(width)spx; height: %(height)spx"></div>            
  81     """ % {'div_id':div_id,
  82            'gmap_type':gmap_type[type],
  83            'latitude':latitude,
  84            'longitude':longitude,
  85            'zoomLevel':zoomLevel,
  86            'width':width,
  87            'gmap_js_function': gmap_js_function,
  88            'height':height,
  89            'marker_js':marker_js}
  90     return gmap_v3

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-07-20 06:59:02, 2.7 KB) [[attachment:Gmap.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.