function addMarkers()
{
mySelect = document.getElementById('selection');
Demorest = [];Baldwin = [];Clarkesville = [];Cornelia = [];Mount_Airy = [];mySelect.options[mySelect.options.length] = new Option("Baldwin schools",'all=Baldwin');
mySelect.options[mySelect.options.length] = new Option("Clarkesville schools",'all=Clarkesville');
mySelect.options[mySelect.options.length] = new Option("Cornelia schools",'all=Cornelia');
mySelect.options[mySelect.options.length] = new Option("Demorest schools",'all=Demorest');
mySelect.options[mySelect.options.length] = new Option("Mount Airy schools",'all=Mount_Airy');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Demorest[Demorest.length] = createMarker(new GPoint(-83.52648800,34.56270900),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("9th Grade Academy",'Demorest=' + Demorest.length);
Baldwin[Baldwin.length] = createMarker(new GPoint(-83.53976440,34.48940659),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Baldwin Elementary School",'Baldwin=' + Baldwin.length);
Clarkesville[Clarkesville.length] = createMarker(new GPoint(-83.53591919,34.61840057),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Chattachoochee Community Center",'Clarkesville=' + Clarkesville.length);
Clarkesville[Clarkesville.length] = createMarker(new GPoint(-83.52438354,34.61254883),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Clarkesville Elementary School",'Clarkesville=' + Clarkesville.length);
Cornelia[Cornelia.length] = createMarker(new GPoint(-83.53408051,34.51970673),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Cornelia Elementary School",'Cornelia=' + Cornelia.length);
Demorest[Demorest.length] = createMarker(new GPoint(-83.52569580,34.56196976),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Demorest Elementary School",'Demorest=' + Demorest.length);
Demorest[Demorest.length] = createMarker(new GPoint(-83.61270142,34.59952545),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Fairview Elementary School",'Demorest=' + Demorest.length);
Mount_Airy[Mount_Airy.length] = createMarker(new GPoint(-83.49604797,34.55683136),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Habersham Central High School",'Mount_Airy=' + Mount_Airy.length);
Mount_Airy[Mount_Airy.length] = createMarker(new GPoint(-83.44412994,34.57378006),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Hazel Grove Elementary School",'Mount_Airy=' + Mount_Airy.length);
Clarkesville[Clarkesville.length] = createMarker(new GPoint(-83.51117706,34.63790894),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("North Habersham Middle School",'Clarkesville=' + Clarkesville.length);
Cornelia[Cornelia.length] = createMarker(new GPoint(-83.55947100,34.53220500),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("South Elementary School",'Cornelia=' + Cornelia.length);
Cornelia[Cornelia.length] = createMarker(new GPoint(-83.57162476,34.52201462),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("South Habersham Middle School",'Cornelia=' + Cornelia.length);
Clarkesville[Clarkesville.length] = createMarker(new GPoint(-83.44390106,34.65737915),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Woodville Elementary School",'Clarkesville=' + Clarkesville.length);
} // End addStateMarkers JavaScript Function
// Takes an array of markers and centers/zooms map based on marker range
function centerByArray(myArray, recenter, newMaxMin)
{
if (newMaxMin == true)
reMaxMin(myArray);
for (var i = 0; i < myArray.length; i++)
{
var markLng = myArray[i].getPoint().x;
var markLat = myArray[i].getPoint().y;
if (markLat > maxLat) maxLat = markLat;
if (markLng > maxLng) maxLng = markLng;
if (markLat < minLat) minLat = markLat;
if (markLng < minLng) minLng = markLng;
}
if (recenter)
reCenterMap();
}
// Reinit max/mins
function reMaxMin(myArray)
{
maxLng = myArray[0].getPoint().x;
maxLat = myArray[0].getPoint().y;
minLng = myArray[0].getPoint().x;
minLat = myArray[0].getPoint().y;
}
// Recenter map based on global max/mins
function reCenterMap()
{
var bounds = new GLatLngBounds();
bounds.extend(new GLatLng(minLat, minLng));
bounds.extend(new GLatLng(maxLat, maxLng));
var center_lat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) / 2.0;
var center_lng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) / 2.0;
var center = new GLatLng(center_lat, center_lng);
var zoom = map.getBoundsZoomLevel(bounds);
map.setCenter(center,zoom);
//map.setCenter(center,10);
/*
var center = new GPoint( (maxLng + minLng)/2, (maxLat+minLat)/2 );
var delta = new GSize(maxLng - minLng, maxLat - minLat);
var minZoom = map.spec.getLowestZoomLevel(center, delta, map.viewSize);
if (minZoom < 4) minZoom = 4; // Lowest possible zoom is 4
map.centerAndZoom(center, minZoom);
*/
}
// Fires when drop down list of schools changes
function selectChange(selection)
{
var myVal = selection.options[selection.selectedIndex].value;
map.closeInfoWindow();
// Add entire array based on variable type
if (myVal.indexOf('all') != -1 && myVal != 'all')
{
var temp = myVal.split('=');
var showArray = temp[1];
// If Array is > X amount of markers, then open in a new page
if (eval(showArray).length > 20)
// New window depends on whether or not we're on the search page
if (location.href.indexOf('nearby_schools.php') == -1)
window.open(location.href + '/map/' + showArray);
else
window.open('/search////' + showArray);
map.removeOverlays(Baldwin);
map.removeOverlays(Clarkesville);
map.removeOverlays(Cornelia);
map.removeOverlays(Demorest);
map.removeOverlays(Mount_Airy);
map.addOverlays(eval(showArray));
centerByArray(eval(showArray), true, true); // Center and zoom on set of markers
}
// Add individual markers
if (myVal.indexOf('all') == -1 && myVal != 'all' && myVal.length)
{
var temp = myVal.split('=');
var myArray = temp[0];
var myIndex = parseInt(temp[1]) - 1;
document.getElementById('map').width = "750";
map.removeOverlay(eval(myArray)[myIndex]);
map.addOverlay(eval(myArray)[myIndex]);
GEvent.trigger(eval(myArray)[myIndex],'click');
}
// Show all markers
if (myVal == 'all')
{
cntMarker = 0;
reMaxMin(Demorest);map.removeOverlays(Baldwin);
map.removeOverlays(Clarkesville);
map.removeOverlays(Cornelia);
map.removeOverlays(Demorest);
map.removeOverlays(Mount_Airy);
map.addOverlays(Baldwin);
centerByArray(Baldwin, false, false);
cntMarker += Baldwin.length;
map.addOverlays(Clarkesville);
centerByArray(Clarkesville, false, false);
cntMarker += Clarkesville.length;
map.addOverlays(Cornelia);
centerByArray(Cornelia, false, false);
cntMarker += Cornelia.length;
map.addOverlays(Demorest);
centerByArray(Demorest, false, false);
cntMarker += Demorest.length;
map.addOverlays(Mount_Airy);
centerByArray(Mount_Airy, false, false);
cntMarker += Mount_Airy.length;
centerByArray(Demorest,true, false);
if (cntMarker > 20)
// New window depends on whether or not we're on the search page
if (location.href.indexOf('schools-by-distance') == -1)
window.open(location.href + '/map/all');
else
window.open('/search////all');
}
}