function addMarkers()
{
mySelect = document.getElementById('selection');
Flowery_Branch = [];Buford = [];Lula = [];Oakwood = [];Watkinsville = [];mySelect.options[mySelect.options.length] = new Option("Buford schools",'all=Buford');
mySelect.options[mySelect.options.length] = new Option("Flowery Branch schools",'all=Flowery_Branch');
mySelect.options[mySelect.options.length] = new Option("Lula schools",'all=Lula');
mySelect.options[mySelect.options.length] = new Option("Oakwood schools",'all=Oakwood');
mySelect.options[mySelect.options.length] = new Option("Watkinsville schools",'all=Watkinsville');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Flowery_Branch[Flowery_Branch.length] = createMarker(new GPoint(-83.89557648,34.19156265),"
",iconBl);
mySelect.options[mySelect.options.length] = new Option("C. W. Davis Middle School",'Flowery_Branch=' + Flowery_Branch.length);
Flowery_Branch[Flowery_Branch.length] = createMarker(new GPoint(-83.83988953,34.17472839),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Chestnut Mountain Elementary School",'Flowery_Branch=' + Flowery_Branch.length);
Flowery_Branch[Flowery_Branch.length] = createMarker(new GPoint(-83.92469788,34.20025253),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Flowery Branch Elementary School",'Flowery_Branch=' + Flowery_Branch.length);
Flowery_Branch[Flowery_Branch.length] = createMarker(new GPoint(-83.89840698,34.18692780),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Flowery Branch High School",'Flowery_Branch=' + Flowery_Branch.length);
Buford[Buford.length] = createMarker(new GPoint(-83.94168091,34.13443756),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Friendship Elementary School",'Buford=' + Buford.length);
Lula[Lula.length] = createMarker(new GPoint(-83.66322327,34.39080048),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Lula Elementary School",'Lula=' + Lula.length);
Flowery_Branch[Flowery_Branch.length] = createMarker(new GPoint(-83.88756561,34.19577789),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Martin Elementary School",'Flowery_Branch=' + Flowery_Branch.length);
Oakwood[Oakwood.length] = createMarker(new GPoint(-83.88156128,34.22461319),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Oakwood Elementary School",'Oakwood=' + Oakwood.length);
Watkinsville[Watkinsville.length] = createMarker(new GPoint(-83.53042603,33.87583542),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Rocky Branch Elementary School",'Watkinsville=' + Watkinsville.length);
Flowery_Branch[Flowery_Branch.length] = createMarker(new GPoint(-83.88815308,34.14693451),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Spout Springs Elementary School",'Flowery_Branch=' + Flowery_Branch.length);
Oakwood[Oakwood.length] = createMarker(new GPoint(-83.90961456,34.21732330),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("West Hall High School",'Oakwood=' + Oakwood.length);
Oakwood[Oakwood.length] = createMarker(new GPoint(-83.90882874,34.21889877),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("West Hall Middle School",'Oakwood=' + Oakwood.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(Buford);
map.removeOverlays(Flowery_Branch);
map.removeOverlays(Lula);
map.removeOverlays(Oakwood);
map.removeOverlays(Watkinsville);
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(Flowery_Branch);map.removeOverlays(Buford);
map.removeOverlays(Flowery_Branch);
map.removeOverlays(Lula);
map.removeOverlays(Oakwood);
map.removeOverlays(Watkinsville);
map.addOverlays(Buford);
centerByArray(Buford, false, false);
cntMarker += Buford.length;
map.addOverlays(Flowery_Branch);
centerByArray(Flowery_Branch, false, false);
cntMarker += Flowery_Branch.length;
map.addOverlays(Lula);
centerByArray(Lula, false, false);
cntMarker += Lula.length;
map.addOverlays(Oakwood);
centerByArray(Oakwood, false, false);
cntMarker += Oakwood.length;
map.addOverlays(Watkinsville);
centerByArray(Watkinsville, false, false);
cntMarker += Watkinsville.length;
centerByArray(Flowery_Branch,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');
}
}