home *** CD-ROM | disk | FTP | other *** search
/ Image Zone / ImageZone.iso / setup.exe / Graphics / html / js / ShowMap.js < prev   
Encoding:
Text File  |  2009-12-10  |  4.6 KB  |  134 lines

  1.     if (GBrowserIsCompatible()) {
  2.  
  3.         var docmap = document.getElementById("map");
  4.         var map = new GMap2(docmap);
  5.         var iFocused = -1;
  6.  
  7.         // ====== Restricting the range of Zoom Levels =====
  8.         // Get the list of map types      
  9.         var mt = map.getMapTypes();
  10.         // Overwrite the getMinimumResolution() and getMaximumResolution() methods
  11.         for (var i = 0; i < mt.length; i++) {
  12.             mt[i].getMinimumResolution = function() { return 2; }
  13.             //mt[i].getMaximumResolution = function() { return 11; }
  14.         }
  15.  
  16.         map.addControl(new GLargeMapControl());
  17.         map.addControl(new GMapTypeControl());
  18.  
  19.       // ==== It is necessary to make a setCenter call of some description before adding markers ====
  20.       // ==== At this point we dont know the real values ====
  21.       map.setCenter(new GLatLng(0,0),0);
  22.  
  23.       //window.alert(qsParm['file']);
  24.       var side_bar_html = "";
  25.       var gmarkers = [];
  26.       var htmls = [];
  27.       var i = 0;
  28.  
  29.  
  30.       function createMarker(point,name,html,focused) {
  31.           var gicon;
  32.           if (focused == 1)
  33.               gicon = new GIcon(G_DEFAULT_ICON, "images/icon_focused_photo.png");
  34.           else
  35.               gicon = new GIcon(G_DEFAULT_ICON, "images/icon_photo.png");
  36.           
  37.           gicon.iconSize = new GSize(18,17);
  38.           gicon.shadow = "images/icon_photo_shadow.png";
  39.           gicon.shadowSize = new GSize(28,17);
  40.           var marker = new GMarker(point, gicon);
  41.           GEvent.addListener(marker, "click", function() {
  42.           marker.openExtInfoWindow(
  43.           map,
  44.               "custom_info_window",
  45.               html,
  46.               { beakOffset: 3 }
  47.             ); 
  48.           });       
  49.         gmarkers[i] = marker;
  50.         htmls[i] = html;
  51.          i++;
  52.         return marker;
  53.       }
  54.  
  55.      
  56.       // ===== Start with an empty GLatLngBounds object =====     
  57.       var bounds = new GLatLngBounds();
  58.  
  59.  
  60.       function myclick(i) {
  61.  
  62.           // ===== determine the zoom level from the bounds =====
  63.           map.setZoom(map.getBoundsZoomLevel(bounds));
  64.  
  65.           // ===== determine the centre from the bounds ======
  66.           map.setCenter(bounds.getCenter());
  67.       
  68.             //          
  69.             gmarkers[i].openExtInfoWindow(
  70.             map,
  71.               "custom_info_window",
  72.               htmls[i],
  73.               { beakOffset: 3 }
  74.             );
  75.       }
  76.       
  77.       // Read the data from example.xml
  78.       var request = GXmlHttp.create();
  79.       var fullURL = parent.document.URL;
  80.       var infoXML = fullURL.substring(fullURL.indexOf('?') + 3, fullURL.length);
  81.       request.open("GET", infoXML, true);
  82.       request.onreadystatechange = function() {
  83.           if (request.readyState == 4) {
  84.               var xmlDoc = GXml.parse(request.responseText);
  85.               // obtain the array of markers and loop through it
  86.               var markers = xmlDoc.documentElement.getElementsByTagName("marker");
  87.  
  88.               for (var i = 0; i < markers.length; i++) {
  89.                   // obtain the attribues of each marker
  90.                   var lat = parseFloat(markers[i].getAttribute("lat"));
  91.                   var lng = parseFloat(markers[i].getAttribute("lng"));
  92.                   var point = new GLatLng(lat, lng);
  93.                   var html = markers[i].getAttribute("html");
  94.                   var label = markers[i].getAttribute("label");
  95.                   var focused = markers[i].getAttribute("focused");
  96.                   if (focused == 1)
  97.                       iFocused = i;
  98.                   // create the marker
  99.                   var marker = createMarker(point, label, html, focused);
  100.                   map.addOverlay(marker);
  101.  
  102.                   // ==== Each time a point is found, extent the bounds ato include it =====
  103.                   bounds.extend(point);
  104.               }
  105.  
  106.               //document.getElementById("side_bar").innerHTML = side_bar_html;
  107.  
  108.               // ===== determine the zoom level from the bounds =====
  109.               var zoomlevel = map.getBoundsZoomLevel(bounds);
  110.               if (zoomlevel > 9)
  111.                   zoomlevel = 9;
  112.               map.setZoom(zoomlevel);
  113.  
  114.               // ===== determine the centre from the bounds ======
  115.               map.setCenter(bounds.getCenter());
  116.  
  117.  
  118.           }
  119.       }
  120.       request.send(null);
  121.  
  122.       if (iFocused >= 0)
  123.         myclick(iFocused);
  124.     }
  125.     
  126.     // display a warning if the browser was not compatible
  127.     else {
  128.       alert("Sorry, the Google Maps API is not compatible with this browser");
  129.     }
  130.  
  131.  
  132.  
  133.  
  134.