Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 3.03 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. var centerLatitude = 42.365338;
  2. var centerLongitude = -71.0568232;
  3. var startZoom = 10;
  4. var map;
  5. var do_refresh = true;
  6.  
  7. function init() {
  8.     if (GBrowserIsCompatible()) {
  9.         map = new GMap2(document.getElementById("map"));
  10.         map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
  11.         map.addControl(new GLargeMapControl());
  12.         map.addControl(new GScaleControl());
  13.         map.addControl(new GMapTypeControl());
  14.         GEvent.addListener(map,'zoomend',function(oldLevel, newLevel) {
  15.             // zooming requires this: remove the existing points
  16.             map.clearOverlays();
  17.             updateMarkers();
  18.         });
  19.  
  20.         GEvent.addListener(map,'moveend',function() {
  21.             updateMarkers();
  22.         });
  23.         setTimeout(updateMarkers, 1000, true);
  24.     }
  25. }
  26.  
  27. function createMarker(gpoint,infoWinStr) {
  28.      var marker = new GMarker(gpoint);
  29.      GEvent.addListener(marker, 'click', function() {
  30.          // var markerHTML = (gpoint.lat() + ", " + gpoint.lng());
  31.           do_refresh = false;
  32.           marker.openExtInfoWindow(
  33.           map,
  34.           "simple_example_window",
  35.           infoWinStr,
  36.           {beakOffset: 3}
  37.             );
  38.           //GEvent.trigger(marker,'click');
  39.           setTimeout(function() {
  40.             do_refresh = true;
  41.           }, 5000);
  42.     });
  43.     return marker;
  44. }
  45.  
  46. function updateMarkers() {
  47.     if (!do_refresh) return;
  48.     //create the boundary for the data
  49.     var clusterer = new Clusterer(map);
  50.     var bounds = map.getBounds();
  51.     var southWest = bounds.getSouthWest();
  52.     var northEast = bounds.getNorthEast();
  53.     var url = '/rep_jay/fc_in_bounds?ne=' + northEast.toUrlValue() +
  54.                   '&sw=' + southWest.toUrlValue();
  55.        //  GLog.writeUrl(url);
  56.     //retrieve the points using Ajax
  57.     var request = GXmlHttp.create();
  58.     request.open('GET', url, true);
  59.     request.onreadystatechange = function() {
  60.          if (request.readyState == 4) {
  61.             if (request.status != 200) {
  62.               GLog.write("status: " + (request.status || "?"));
  63.             } else {
  64.                 var data = request.responseText;
  65.                 var edata = eval("(" + data + ")");
  66.  
  67.                 //remove the existing points
  68.                 map.clearOverlays();
  69.                 var points = edata.result;
  70.  
  71.                 //create each point from the list
  72.                 for (var i = 0; i < points.length; i++) {
  73.                     var gp = new GLatLng(points[i].latitude + (Math.random()-.5)/10000, points[i].longitude + (Math.random()-.5)/10000);
  74.                      var marker = createMarker(gp,'<div class="title">'+points[i]['first_name']+' '+points[i]['last_name']+'</div><div class="address">'+points[i]['address']+' <br> '+points[i]['date']+' '+points[i]['amount']+'</div>');
  75.                     clusterer.AddMarker(marker, donors);
  76.                 }
  77.             }
  78.          }
  79.     }
  80.     request.send(null);
  81. }
  82.  
  83. window.onload = init;
  84. window.onunload = function() {
  85.   // unloaded = true;
  86.   GUnload();
  87. };