Guest User

google marker loader

a guest
Nov 3rd, 2011
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  <script type="text/javascript">
  2.     //<![CDATA[
  3.  
  4.     if (GBrowserIsCompatible()) {
  5.       var side_bar_html = "";
  6.       var gmarkers = [];
  7.       var htmls = [];
  8.       var i = 0;
  9.  
  10.       // A function to create the marker and set up the event window
  11.       function createMarker(point,name,html) {
  12.         var marker = new GMarker(point);
  13.         GEvent.addListener(marker, "click", function() {
  14.           marker.openInfoWindowHtml(html);
  15.         });
  16.         gmarkers[i] = marker;
  17.         htmls[i] = html;
  18.         side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '<\/a><br>';
  19.         i++;
  20.         return marker;
  21.       }
  22.  
  23.  
  24.       // This function picks up the click and opens the corresponding info window
  25.       function myclick(i) {
  26.         gmarkers[i].openInfoWindowHtml(htmls[i]);
  27.       }
  28.  
  29.  
  30.       // create the map
  31.       var map = new GMap2(document.getElementById("map"));
  32.       map.addControl(new GLargeMapControl());
  33.       map.addControl(new GMapTypeControl());
  34.       map.setCenter(new GLatLng( 43.907787,-79.359741), 9);
  35.  
  36.  
  37.       // A function to read the data
  38.       function readMap(url) {
  39.         var url="map11.php?q="+url;
  40.         var request = GXmlHttp.create();
  41.         request.open("GET", url, true);
  42.         request.onreadystatechange = function() {
  43.           if (request.readyState == 4) {
  44.             var xmlDoc = request.responseXML;
  45.             // obtain the array of markers and loop through it
  46.             var markers = xmlDoc.documentElement.getElementsByTagName("marker");
  47.            
  48.             // hide the info window, otherwise it still stays open where the removed marker used to be
  49.             map.getInfoWindow().hide();
  50.            
  51.             map.clearOverlays();
  52.            
  53.             // empty the array
  54.             gmarkers = [];
  55.  
  56.             // reset the side_bar
  57.             side_bar_html="";
  58.          
  59.             for (var i = 0; i < markers.length; i++) {
  60.               // obtain the attribues of each marker
  61.               var lat = parseFloat(markers[i].getAttribute("lat"));
  62.               var lng = parseFloat(markers[i].getAttribute("lng"));
  63.               var point = new GLatLng(lat,lng);
  64.               var html = markers[i].getAttribute("html");
  65.               var label = markers[i].getAttribute("label");
  66.               // create the marker
  67.               var marker = createMarker(point,label,html);
  68.               map.addOverlay(marker);
  69.             }
  70.             // put the assembled side_bar_html contents into the side_bar div
  71.             document.getElementById("side_bar").innerHTML = side_bar_html;
  72.           }
  73.         }
  74.         request.send(null);
  75.       }
  76.      
  77.       // When initially loaded, use the data from "map11.php?q=a"
  78.       readMap("a");
  79.      
  80.     }
  81.  
  82.     else {
  83.       alert("Sorry, the Google Maps API is not compatible with this browser");
  84.     }
  85.  
  86.     // This Javascript is based on code provided by the
  87.     // Community Church Javascript Team
  88.     // http://www.bisphamchurch.org.uk/  
  89.     // http://econym.org.uk/gmap/
  90.  
  91.     //]]>
  92.     </script>
  93.  
Add Comment
Please, Sign In to add comment