$(function(){ var map = new GMap2(document.getElementById('map')); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); var bounds = new GLatLngBounds(); var geo = new GClientGeocoder(); var reasons=[]; reasons[G_GEO_SUCCESS] = "Successful retrieval of geo code"; reasons[G_GEO_MISSING_ADDRESS] = "Please enter the address."; reasons[G_GEO_UNKNOWN_ADDRESS] = "The address entered was not found."; reasons[G_GEO_UNAVAILABLE_ADDRESS]= "The address entered is not available."; reasons[G_GEO_BAD_KEY] = "System error (Google:Bad API Key). Please contact your system administrator."; reasons[G_GEO_TOO_MANY_QUERIES] = "The servers is experiencing high load. Please try again later."; reasons[G_GEO_SERVER_ERROR] = "System error (Google:Server error). Please contact your system administrator."; localmapInitialize(); var criteriaSearch; // Reload the map reload(); // To Initialize parameters and event handlers function localmapInitialize() { setSearchActive(); GEvent.addListener(map, "dragend", function() { if (isSearchActive()) return; searchBound(); }); GEvent.addListener(map, "zoomend", function() { if (isSearchActive()) return; searchBound(); }); } // Flag to Indicate that search is in progress function setSearchActive() { criteriaSearch=true; } // Flag to Indicate that search has completed function setSearchInactive() { // Timeout specified to take care of Asynchronous conditions setTimeout(function(){ criteriaSearch=false; }, 500 ); } // Flag to check if search is active function isSearchActive() { return criteriaSearch } // Reload the map function reload() { $.getJSON("pages/mapServicesList.jsp?action=list", function(json) { setSearchActive(); if (json.Locations.length > 0) { for (i=0; i American Red Cross "; var icon=""; var city= location.city.toLowerCase().replace(/\b\w/g, function(match){return match.toUpperCase();}); var shelterName= location.name.toLowerCase().replace(/\b\w/g, function(match){return match.toUpperCase();}); var address1= location.addr1.toLowerCase().replace(/\b\w/g, function(match){return match.toUpperCase();}); var locationCapacity = (location.capacity == 0)? "N/A":""+location.capacity; var spacesForRightAlign = "                     " var text = icon+"

"+shelterName+"
"+address1+"
"+city+" ,"+location.state+" "+location.zip+"

"+"Shelter Capacity : "+ locationCapacity +"
"+"Current Residents : "+location.population+"

"+ spacesForRightAlign+ donation_link; var marker = createMarker(point,text, "img/red_cross_shelter3.png"); map.addOverlay(marker); bounds.extend(marker.getPoint()); $("
  • ") .html(""+shelterName+"") .click(function(){ marker.openInfoWindow(text); }) .appendTo("#list"); } // Links to show the address function showAddress(address,geocode) { var htmlText = getInfoHtml(address); $("
  • ") .html(""+address+"") .click(function(){ clearAll(); var htmlText = getInfoHtml(address); storeMyLocation(htmlText,geocode); searchPoint(geocode); }) .appendTo("#suggest"); } // Format the HTML for the info window function getInfoHtml(address) { //var donation_link="" + "American Red Cross "; var donation_link=""; var icon=""; var spacesForRightAlign = "                     " var text = icon+"

    "+address+""+ spacesForRightAlign+ donation_link; return text; } // Place the marker but do not center the map to that location function placeMarkerStatic(htmlText,geocode) { var point = new GLatLng(geocode[1],geocode[0]); var marker = createMarker(point,htmlText, "img/home.png"); map.addOverlay(marker); } // Place the marker and center the map to that location function placeMarker(htmlText,geocode) { var point = new GLatLng(geocode[1],geocode[0]); var marker = createMarker(point,htmlText, "img/home.png"); map.addOverlay(marker); bounds.extend(marker.getPoint()); map.setCenter(point,7); marker.openInfoWindow(htmlText); } // Center and Zoom to desired level function zoomToBounds() { map.setCenter(bounds.getCenter()); map.setZoom(map.getBoundsZoomLevel(bounds)-1); } $("#search-loc").submit(function(){ geoEncode(); return false; }); // Read the address search criteria and process function geoEncode() { var address = $("#search-loc input[name=address]").val(); geo.getLocations(address, function (result){ setSearchActive(); if (result.Status.code == G_GEO_SUCCESS) { // ===== If there was more than one result, "ask did you mean" on them all ===== if (result.Placemark.length > 1) { $("#suggest").html("Did you mean:"); // Loop through the results $("#search-loc .error").html("Multiple Address found").fadeIn(); for (var i=0; iOpen Red Cross shelters displayed:"); } // Perform search based on a geocode function searchPoint(geocode) { var data = $("#search-loc :input").serializeArray(); data[data.length] = { name: "lng", value: geocode[0] }; data[data.length] = { name: "lat", value: geocode[1] }; gotoMyLocation(); $.post($("#search-loc").attr('action'), data, function(json){ $("#search-loc .error").fadeOut(); if (json.status == "fail") { $("#search-loc .error").html(json.message).fadeIn(); } //alert ("Radius: json.status: "+ json.status); if (json.status == "success") { if (json.Locations.length > 0) { for (i=0; i 0) { for (i=0; i