// JavaScript Document // defines the map container var map = null; // This determines how far the map will pan when the North, South, East, or West buttons are pressed. // It will scroll the screen by the percentage below * the current screen width or height. var panPercentage = 0.5; // This holds all of the points to be included in the default view. Google Maps can automatically // adjust the default view to include all of the points in this variable. var mapBounds; //////////////////////////// // // zoomIn() // // This zooms the map in by 1 level // It retrieves the current zoom level and subtracts 1 from it. // maximum zoom level is 17; minimum zoom level is 0 // //////////////////////////// function zoomIn() { map.setZoom(map.getZoom() + 1); } ////////////////////////////// // // zoomOut() // // This zooms the map out by 1 level // It retrieves the current zoom level and adds 1 to it. // maximum zoom level is 17; minimum zoom level is 0 // //////////////////////////// function zoomOut() { map.setZoom(map.getZoom() - 1); } ///////////////////////////// // // setMapType() // // This sets the display type of the map. The default map formats for standard Google Map are: // G_NORMAL_MAP // G_SATELLITE_MAP // G_HYBRID_MAP // One of these values needs to be passed into this function to set the map type. // Custom map types can be created and called through the Google Maps API. // //////////////////////////// function setMapType(mapType) { map.setMapType(mapType); } /////////////////////////// // // aroundTheWorldLngSpan() // // This function adjusts calculation of the visible longitudinal span when the view crosses the // +/-180 degree line. It insures that the width of the view (in degrees) is calculated correctly. // NE = the North-East corner of the span. // SW = the South-West corner of the span. // //////////////////////////// function aroundTheWorldLngSpan(NE,SW) { if (SW > NE) { NE = NE + 360; } return Math.abs(NE - SW); } //////////////////////////// // // aroundTheWorldLngPan() // // This function adjusts the calculation for the new view point when panning East or West across // the +/-180 degree line. It insures the map will pan correctly across this boundary. // //////////////////////////// function aroundTheWorldLngPan(lng) { if (lng < -180) { lng = lng + 360; } else if (lng > 180) { lng = lng - 360; } return lng; } //////////////////////////// // // limitNS(lat) // // This ensures that the map does not scroll beyond +/- 85 degrees latitudinally. // Using +/- 90 degrees as a limit creates a problem. The spherical coordinates // become so flattened out at the extreme norhtern and southern boundaries // it takes a lof of N-S movement to change 1 degree. (At least this what I'm assuming // the problem is.) // //////////////////////////// function limitNS(lat) { if (lat > 85) { lat = 85; } else if (lat < -85) { lat = -85; } return lat; } ////////////////////// // // lngSpan() // // This calculates the latitudinal span of the current view. // It takes into account calculating across the +/- 180 degree line. // //////////////////////////// function lngSpan() { var bounds = map.getBounds(); // the boundary coordinates for the current view var southWest = bounds.getSouthWest(); // the South-West corner of the boundary var northEast = bounds.getNorthEast(); // the North-East corner of the boundary return aroundTheWorldLngSpan(northEast.lng(), southWest.lng()); } ///////////////////// // // latSpan() // // This calculates the latitudinal span of the current view. // //////////////////////////// function latSpan() { var bounds = map.getBounds(); // the boundary coordinates for the current view var southWest = bounds.getSouthWest(); // the South-West corner of the boundary var northEast = bounds.getNorthEast(); // the North-East corner of the boundary return Math.abs(northEast.lat() - southWest.lat()); } /////////////////////// // // panWest() // // This function will pan the map West by a set % of the current visible width. // The percentage is set in the variable panPercentage. // It takes the current visible longitudinal span, multiplies it by panPercentage, and pans the map to the new longitudinal location // The pan will be smooth if the new location is in the current view. // // NOTE: When the map is zoomed nearly all the way out, the panWest() will actually appear to move East. // This is presumable because when Google Maps receives the new coordinates for the center, // It is actually shorter to pan to the East rather than to the West, even though the coordinates // given are to the West. // //////////////////////////// function panWest () { map.panTo(new GLatLng(map.getCenter().lat(), aroundTheWorldLngPan(map.getCenter().lng() - (lngSpan() * panPercentage)))); } ///////////////////////// // // panEast() // // This function will pan the map East by a set % of the current visible width. // The percentage is set in the variable panPercentage. // It takes the current visible longitudinal span, multiplies it by panPercentage, and pans the map to the new longitudinal location // The pan will be smooth if the new location is in the current view. // //////////////////////////// function panEast () { map.panTo(new GLatLng(map.getCenter().lat(), aroundTheWorldLngPan(map.getCenter().lng() + (lngSpan() * panPercentage)))); } //////////////////////////////// // // panNorth() // // This function will pan the map North by a set % of the current visible width. // The percentage is set in the variable panPercentage. // It takes the current visible latitudinal span, multiplies it by panPercentage, and pans the map to the new latitudinal location // The pan will be smooth if the new location is in the current view. // //////////////////////////// function panNorth () { map.panTo(new GLatLng(limitNS(map.getCenter().lat() + (latSpan() * panPercentage)), map.getCenter().lng())); } ////////////////////////////////// // // panSouth() // // This function will pan the map South by a set % of the current visible width. // The percentage is set in the variable panPercentage. // It takes the current visible latitudinal span, multiplies it by panPercentage, and pans the map to the new latitudinal location // The pan will be smooth if the new location is in the current view. // //////////////////////////// function panSouth () { map.panTo(new GLatLng(limitNS(map.getCenter().lat() - (latSpan() * panPercentage)), map.getCenter().lng())); } ///////////////////////////////// // // createMarker(point, index) // // This creates the information window for the pushpin. // ///////////////////////////////// function createMarker(point, infoWindow) { var marker = new GMarker(point); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml("" + infoWindow + ""); }); return marker; } /////////////////////////////// // // adjustView() // // This will adjust the view of the map to include all of the points in the bounds variable. // /////////////////////////////// function adjustView () { map.setZoom(map.getBoundsZoomLevel(mapBounds)); var clat = (mapBounds.getNorthEast().lat() + mapBounds.getSouthWest().lat()) /2; var clng = (mapBounds.getNorthEast().lng() + mapBounds.getSouthWest().lng()) /2; map.setCenter(new GLatLng(clat,clng)); } /////////////////////////////// // // showAddress(address, mapPointLabel) // // This translates a street address into a set of longitude and latitude points. It then // plots that point on the map. // // Currently it calls adjustView() after each point is plotted. This seems to be a lot of overhead // and I think I ought to be able to call it once after all the points have been mapped. When I // do that though it doesn't work. I'm not sure why yet. // /////////////////////////////// function showAddress(address, infoWindow) { geocoder = new GClientGeocoder(); geocoder.getLatLng( address, function(point) { if (!point) { alert(address + " not found"); } else { var marker = new GMarker(point); map.addOverlay(createMarker(point, infoWindow)); // adds the point to the set of points that need to be made visible in the current view mapBounds.extend(point); // adjusts the view to include all the points that are supposed to be visible adjustView(); } } ); } function showAddress3() { var map; var geocoder ; var address = document.myStateForm.address_fld.value ; alert('My Address = ' + address) ; alert('insdie 1') ; geocoder = new GClientGeocoder(); if (geocoder) { alert('insdie 2') ; geocoder.getLatLng( address, function(point) { if (!point) { alert(address + " not found"); } else { map.setCenter(point, 15); } } ); } }