function addMarkers()
{
mySelect = document.getElementById('selection');
Staunton = [];Swoope = [];Waynesboro = [];Churchville = [];Craigsville = [];Fort_Defiance = [];Stuarts_Draft = [];Mount_Solon = [];Fishersville = [];Verona = [];mySelect.options[mySelect.options.length] = new Option("Churchville schools",'all=Churchville');
mySelect.options[mySelect.options.length] = new Option("Craigsville schools",'all=Craigsville');
mySelect.options[mySelect.options.length] = new Option("Fishersville schools",'all=Fishersville');
mySelect.options[mySelect.options.length] = new Option("Fort Defiance schools",'all=Fort_Defiance');
mySelect.options[mySelect.options.length] = new Option("Mount Solon schools",'all=Mount_Solon');
mySelect.options[mySelect.options.length] = new Option("Staunton schools",'all=Staunton');
mySelect.options[mySelect.options.length] = new Option("Stuarts Draft schools",'all=Stuarts_Draft');
mySelect.options[mySelect.options.length] = new Option("Swoope schools",'all=Swoope');
mySelect.options[mySelect.options.length] = new Option("Verona schools",'all=Verona');
mySelect.options[mySelect.options.length] = new Option("Waynesboro schools",'all=Waynesboro');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Staunton[Staunton.length] = createMarker(new GPoint(-79.12275696,38.14976501),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Beverley Manor Elementary School",'Staunton=' + Staunton.length);
Staunton[Staunton.length] = createMarker(new GPoint(-79.11972046,38.15035248),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Beverley Manor Middle School",'Staunton=' + Staunton.length);
Swoope[Swoope.length] = createMarker(new GPoint(-79.22129059,38.19230652),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Buffalo Gap High School",'Swoope=' + Swoope.length);
Waynesboro[Waynesboro.length] = createMarker(new GPoint(-78.87020874,38.12915421),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Cassell Elementary School",'Waynesboro=' + Waynesboro.length);
Churchville[Churchville.length] = createMarker(new GPoint(-79.15772247,38.22324753),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Churchville Elementary School",'Churchville=' + Churchville.length);
Craigsville[Craigsville.length] = createMarker(new GPoint(-79.38183594,38.08118820),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Craigsville Elementary School",'Craigsville=' + Craigsville.length);
Fort_Defiance[Fort_Defiance.length] = createMarker(new GPoint(-78.99510193,38.28129959),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Edward G. Clymore Elementary School",'Fort_Defiance=' + Fort_Defiance.length);
Fort_Defiance[Fort_Defiance.length] = createMarker(new GPoint(-78.99510193,38.28129959),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Ft. Defiance High School",'Fort_Defiance=' + Fort_Defiance.length);
Stuarts_Draft[Stuarts_Draft.length] = createMarker(new GPoint(-79.03297424,38.02345657),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Guy K. Stump Elementary School",'Stuarts_Draft=' + Stuarts_Draft.length);
Mount_Solon[Mount_Solon.length] = createMarker(new GPoint(-79.07965851,38.31533051),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("North River Elementary School",'Mount_Solon=' + Mount_Solon.length);
Staunton[Staunton.length] = createMarker(new GPoint(-79.13919830,38.03153610),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Riverheads Elementary School",'Staunton=' + Staunton.length);
Staunton[Staunton.length] = createMarker(new GPoint(-79.13922119,38.03153610),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Riverheads High School",'Staunton=' + Staunton.length);
Fort_Defiance[Fort_Defiance.length] = createMarker(new GPoint(-78.99510193,38.28129959),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("S. Gordon Stewart Middle School",'Fort_Defiance=' + Fort_Defiance.length);
Fishersville[Fishersville.length] = createMarker(new GPoint(-78.97015900,38.09959500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Shenandoah Valley Governor's School",'Fishersville=' + Fishersville.length);
Fishersville[Fishersville.length] = createMarker(new GPoint(-78.97389984,38.07117844),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Shenandoah Valley Reg",'Fishersville=' + Fishersville.length);
Stuarts_Draft[Stuarts_Draft.length] = createMarker(new GPoint(-79.03569794,38.04069901),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Stuarts Draft Elementary School",'Stuarts_Draft=' + Stuarts_Draft.length);
Stuarts_Draft[Stuarts_Draft.length] = createMarker(new GPoint(-79.01401520,38.04507065),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Stuarts Draft High School",'Stuarts_Draft=' + Stuarts_Draft.length);
Stuarts_Draft[Stuarts_Draft.length] = createMarker(new GPoint(-79.01261902,38.04430389),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Stuarts Draft Middle School",'Stuarts_Draft=' + Stuarts_Draft.length);
Fishersville[Fishersville.length] = createMarker(new GPoint(-78.98961700,38.11651100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Valley Vocational Tech Center",'Fishersville=' + Fishersville.length);
Verona[Verona.length] = createMarker(new GPoint(-78.99477386,38.22037506),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Verona Elementary School",'Verona=' + Verona.length);
Fishersville[Fishersville.length] = createMarker(new GPoint(-78.99201202,38.11130905),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Wilson Elementary School",'Fishersville=' + Fishersville.length);
Fishersville[Fishersville.length] = createMarker(new GPoint(-78.95354462,38.10925674),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Wilson Memorial High School",'Fishersville=' + Fishersville.length);
Fishersville[Fishersville.length] = createMarker(new GPoint(-10.00000000,10.00000000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Woodrow Wilson Rehab Center",'Fishersville=' + Fishersville.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(Churchville);
map.removeOverlays(Craigsville);
map.removeOverlays(Fishersville);
map.removeOverlays(Fort_Defiance);
map.removeOverlays(Mount_Solon);
map.removeOverlays(Staunton);
map.removeOverlays(Stuarts_Draft);
map.removeOverlays(Swoope);
map.removeOverlays(Verona);
map.removeOverlays(Waynesboro);
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(Staunton);map.removeOverlays(Churchville);
map.removeOverlays(Craigsville);
map.removeOverlays(Fishersville);
map.removeOverlays(Fort_Defiance);
map.removeOverlays(Mount_Solon);
map.removeOverlays(Staunton);
map.removeOverlays(Stuarts_Draft);
map.removeOverlays(Swoope);
map.removeOverlays(Verona);
map.removeOverlays(Waynesboro);
map.addOverlays(Churchville);
centerByArray(Churchville, false, false);
cntMarker += Churchville.length;
map.addOverlays(Craigsville);
centerByArray(Craigsville, false, false);
cntMarker += Craigsville.length;
map.addOverlays(Fishersville);
centerByArray(Fishersville, false, false);
cntMarker += Fishersville.length;
map.addOverlays(Fort_Defiance);
centerByArray(Fort_Defiance, false, false);
cntMarker += Fort_Defiance.length;
map.addOverlays(Mount_Solon);
centerByArray(Mount_Solon, false, false);
cntMarker += Mount_Solon.length;
map.addOverlays(Staunton);
centerByArray(Staunton, false, false);
cntMarker += Staunton.length;
map.addOverlays(Stuarts_Draft);
centerByArray(Stuarts_Draft, false, false);
cntMarker += Stuarts_Draft.length;
map.addOverlays(Swoope);
centerByArray(Swoope, false, false);
cntMarker += Swoope.length;
map.addOverlays(Verona);
centerByArray(Verona, false, false);
cntMarker += Verona.length;
map.addOverlays(Waynesboro);
centerByArray(Waynesboro, false, false);
cntMarker += Waynesboro.length;
centerByArray(Staunton,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');
}
}