- var centerLatitude = 42.365338;
- var centerLongitude = -71.0568232;
- var startZoom = 10;
- var map;
- var do_refresh = true;
- function init() {
- if (GBrowserIsCompatible()) {
- map = new GMap2(document.getElementById("map"));
- map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
- map.addControl(new GLargeMapControl());
- map.addControl(new GScaleControl());
- map.addControl(new GMapTypeControl());
- GEvent.addListener(map,'zoomend',function(oldLevel, newLevel) {
- // zooming requires this: remove the existing points
- map.clearOverlays();
- updateMarkers();
- });
- GEvent.addListener(map,'moveend',function() {
- updateMarkers();
- });
- setTimeout(updateMarkers, 1000, true);
- }
- }
- function createMarker(gpoint,infoWinStr) {
- var marker = new GMarker(gpoint);
- GEvent.addListener(marker, 'click', function() {
- // var markerHTML = (gpoint.lat() + ", " + gpoint.lng());
- do_refresh = false;
- marker.openExtInfoWindow(
- map,
- "simple_example_window",
- infoWinStr,
- {beakOffset: 3}
- );
- //GEvent.trigger(marker,'click');
- setTimeout(function() {
- do_refresh = true;
- }, 5000);
- });
- return marker;
- }
- function updateMarkers() {
- if (!do_refresh) return;
- //create the boundary for the data
- var clusterer = new Clusterer(map);
- var bounds = map.getBounds();
- var southWest = bounds.getSouthWest();
- var northEast = bounds.getNorthEast();
- var url = '/rep_jay/fc_in_bounds?ne=' + northEast.toUrlValue() +
- '&sw=' + southWest.toUrlValue();
- // GLog.writeUrl(url);
- //retrieve the points using Ajax
- var request = GXmlHttp.create();
- request.open('GET', url, true);
- request.onreadystatechange = function() {
- if (request.readyState == 4) {
- if (request.status != 200) {
- GLog.write("status: " + (request.status || "?"));
- } else {
- var data = request.responseText;
- var edata = eval("(" + data + ")");
- //remove the existing points
- map.clearOverlays();
- var points = edata.result;
- //create each point from the list
- for (var i = 0; i < points.length; i++) {
- var gp = new GLatLng(points[i].latitude + (Math.random()-.5)/10000, points[i].longitude + (Math.random()-.5)/10000);
- 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>');
- clusterer.AddMarker(marker, donors);
- }
- }
- }
- }
- request.send(null);
- }
- window.onload = init;
- window.onunload = function() {
- // unloaded = true;
- GUnload();
- };