function addMarkers()
{
mySelect = document.getElementById('selection');
Mechanicsville = [];Hanover = [];Beaverdam = [];Ashland = [];Montpelier = [];mySelect.options[mySelect.options.length] = new Option("Ashland schools",'all=Ashland');
mySelect.options[mySelect.options.length] = new Option("Beaverdam schools",'all=Beaverdam');
mySelect.options[mySelect.options.length] = new Option("Hanover schools",'all=Hanover');
mySelect.options[mySelect.options.length] = new Option("Mechanicsville schools",'all=Mechanicsville');
mySelect.options[mySelect.options.length] = new Option("Montpelier schools",'all=Montpelier');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.41150665,37.66376495),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Atlee High School",'Mechanicsville=' + Mechanicsville.length);
Hanover[Hanover.length] = createMarker(new GPoint(-77.32890320,37.76499939),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Barrett Juvenile Correctional Center",'Hanover=' + Hanover.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.29732513,37.62723541),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Battlefield Park Elementary School",'Mechanicsville=' + Mechanicsville.length);
Beaverdam[Beaverdam.length] = createMarker(new GPoint(-77.64179993,37.93383408),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Beaverdam Elementary School",'Beaverdam=' + Beaverdam.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.41268158,37.66550827),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Chickahominy Middle School",'Mechanicsville=' + Mechanicsville.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.32037354,37.59214783),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Cold Harbor Elementary School",'Mechanicsville=' + Mechanicsville.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.41000366,37.67046356),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Cool Spring Elementary School",'Mechanicsville=' + Mechanicsville.length);
Ashland[Ashland.length] = createMarker(new GPoint(-77.51103973,37.71464157),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Elmont Elementary School",'Ashland=' + Ashland.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.38227081,37.68791580),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Hanover High School",'Mechanicsville=' + Mechanicsville.length);
Ashland[Ashland.length] = createMarker(new GPoint(-77.48619080,37.75643539),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Henry Clay Elementary School",'Ashland=' + Ashland.length);
Hanover[Hanover.length] = createMarker(new GPoint(-77.32890320,37.76499939),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("John H Smyth Sch @ Hanover Juv",'Hanover=' + Hanover.length);
Ashland[Ashland.length] = createMarker(new GPoint(-77.46926880,37.77080536),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("John M. Gandy Elementary School",'Ashland=' + Ashland.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.33950806,37.61220169),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Lee Davis High School",'Mechanicsville=' + Mechanicsville.length);
Ashland[Ashland.length] = createMarker(new GPoint(-77.53034210,37.78487015),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Liberty Middle School",'Ashland=' + Ashland.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.37834167,37.61162186),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Mechanicsville Elementary School",'Mechanicsville=' + Mechanicsville.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.38210297,37.68716812),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Oak Knoll Middle School",'Mechanicsville=' + Mechanicsville.length);
Ashland[Ashland.length] = createMarker(new GPoint(-77.53266144,37.78646851),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Patrick Henry High School",'Ashland=' + Ashland.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.39023590,37.67729187),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Pearson's Corner Elementary School",'Mechanicsville=' + Mechanicsville.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.30751801,37.63866043),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Pole Green Elementary School",'Mechanicsville=' + Mechanicsville.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.34055328,37.66519547),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Rural Point Elementary School",'Mechanicsville=' + Mechanicsville.length);
Montpelier[Montpelier.length] = createMarker(new GPoint(-77.66117096,37.76200867),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("South Anna Elementary School",'Montpelier=' + Montpelier.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.34004211,37.61787415),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Stonewall Jackson Middle School",'Mechanicsville=' + Mechanicsville.length);
Mechanicsville[Mechanicsville.length] = createMarker(new GPoint(-77.38471985,37.64530182),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Washington Henry Elementary School",'Mechanicsville=' + Mechanicsville.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(Ashland);
map.removeOverlays(Beaverdam);
map.removeOverlays(Hanover);
map.removeOverlays(Mechanicsville);
map.removeOverlays(Montpelier);
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(Mechanicsville);map.removeOverlays(Ashland);
map.removeOverlays(Beaverdam);
map.removeOverlays(Hanover);
map.removeOverlays(Mechanicsville);
map.removeOverlays(Montpelier);
map.addOverlays(Ashland);
centerByArray(Ashland, false, false);
cntMarker += Ashland.length;
map.addOverlays(Beaverdam);
centerByArray(Beaverdam, false, false);
cntMarker += Beaverdam.length;
map.addOverlays(Hanover);
centerByArray(Hanover, false, false);
cntMarker += Hanover.length;
map.addOverlays(Mechanicsville);
centerByArray(Mechanicsville, false, false);
cntMarker += Mechanicsville.length;
map.addOverlays(Montpelier);
centerByArray(Montpelier, false, false);
cntMarker += Montpelier.length;
centerByArray(Mechanicsville,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');
}
}