Guest

Untitled

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