function addMarkers()
{
mySelect = document.getElementById('selection');
Big_Island = [];Bedford = [];Lynchburg = [];Forest = [];Goodview = [];Huddleston = [];Moneta = [];Montvale = [];Goode = [];Thaxton = [];mySelect.options[mySelect.options.length] = new Option("Bedford schools",'all=Bedford');
mySelect.options[mySelect.options.length] = new Option("Big Island schools",'all=Big_Island');
mySelect.options[mySelect.options.length] = new Option("Forest schools",'all=Forest');
mySelect.options[mySelect.options.length] = new Option("Goode schools",'all=Goode');
mySelect.options[mySelect.options.length] = new Option("Goodview schools",'all=Goodview');
mySelect.options[mySelect.options.length] = new Option("Huddleston schools",'all=Huddleston');
mySelect.options[mySelect.options.length] = new Option("Lynchburg schools",'all=Lynchburg');
mySelect.options[mySelect.options.length] = new Option("Moneta schools",'all=Moneta');
mySelect.options[mySelect.options.length] = new Option("Montvale schools",'all=Montvale');
mySelect.options[mySelect.options.length] = new Option("Thaxton schools",'all=Thaxton');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Big_Island[Big_Island.length] = createMarker(new GPoint(-79.41448212,37.52931595),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Big Island Elementary School",'Big_Island=' + Big_Island.length);
Bedford[Bedford.length] = createMarker(new GPoint(-79.51790619,37.22480011),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Body Camp Elementary School",'Bedford=' + Bedford.length);
Lynchburg[Lynchburg.length] = createMarker(new GPoint(-79.26142120,37.45272446),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Boonsboro Elementary School",'Lynchburg=' + Lynchburg.length);
Forest[Forest.length] = createMarker(new GPoint(-79.30672455,37.37549210),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Forest Elementary School",'Forest=' + Forest.length);
Forest[Forest.length] = createMarker(new GPoint(-79.30862427,37.37086105),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Forest Middle School",'Forest=' + Forest.length);
Goodview[Goodview.length] = createMarker(new GPoint(-79.78403473,37.26427841),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Goodview Elementary School",'Goodview=' + Goodview.length);
Huddleston[Huddleston.length] = createMarker(new GPoint(-79.47098541,37.16350937),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Huddleston Elementary School",'Huddleston=' + Huddleston.length);
Forest[Forest.length] = createMarker(new GPoint(-79.30575562,37.37622070),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Jefferson Forest High School",'Forest=' + Forest.length);
Bedford[Bedford.length] = createMarker(new GPoint(-79.49872589,37.37213516),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Liberty High School",'Bedford=' + Bedford.length);
Moneta[Moneta.length] = createMarker(new GPoint(-79.61198425,37.18727112),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Moneta Elementary School",'Moneta=' + Moneta.length);
Montvale[Montvale.length] = createMarker(new GPoint(-79.70987701,37.37693405),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Montvale Elementary School",'Montvale=' + Montvale.length);
Forest[Forest.length] = createMarker(new GPoint(-79.30472565,37.30613708),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("New London Academy Elementary School",'Forest=' + Forest.length);
Goode[Goode.length] = createMarker(new GPoint(-79.43418121,37.36543655),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Otter River Elementary School",'Goode=' + Goode.length);
Moneta[Moneta.length] = createMarker(new GPoint(-79.62235260,37.24076462),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Staunton River High School",'Moneta=' + Moneta.length);
Moneta[Moneta.length] = createMarker(new GPoint(-79.62207794,37.24076462),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Staunton River Middle School",'Moneta=' + Moneta.length);
Goodview[Goodview.length] = createMarker(new GPoint(-79.78926849,37.27143860),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Stewartsville Elementary School",'Goodview=' + Goodview.length);
Thaxton[Thaxton.length] = createMarker(new GPoint(-79.60755920,37.35374069),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Thaxton Elementary School",'Thaxton=' + Thaxton.length);
Forest[Forest.length] = createMarker(new GPoint(-79.28626251,37.35832977),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Thomas Jefferson Elementary School",'Forest=' + Forest.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(Bedford);
map.removeOverlays(Big_Island);
map.removeOverlays(Forest);
map.removeOverlays(Goode);
map.removeOverlays(Goodview);
map.removeOverlays(Huddleston);
map.removeOverlays(Lynchburg);
map.removeOverlays(Moneta);
map.removeOverlays(Montvale);
map.removeOverlays(Thaxton);
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(Big_Island);map.removeOverlays(Bedford);
map.removeOverlays(Big_Island);
map.removeOverlays(Forest);
map.removeOverlays(Goode);
map.removeOverlays(Goodview);
map.removeOverlays(Huddleston);
map.removeOverlays(Lynchburg);
map.removeOverlays(Moneta);
map.removeOverlays(Montvale);
map.removeOverlays(Thaxton);
map.addOverlays(Bedford);
centerByArray(Bedford, false, false);
cntMarker += Bedford.length;
map.addOverlays(Big_Island);
centerByArray(Big_Island, false, false);
cntMarker += Big_Island.length;
map.addOverlays(Forest);
centerByArray(Forest, false, false);
cntMarker += Forest.length;
map.addOverlays(Goode);
centerByArray(Goode, false, false);
cntMarker += Goode.length;
map.addOverlays(Goodview);
centerByArray(Goodview, false, false);
cntMarker += Goodview.length;
map.addOverlays(Huddleston);
centerByArray(Huddleston, false, false);
cntMarker += Huddleston.length;
map.addOverlays(Lynchburg);
centerByArray(Lynchburg, false, false);
cntMarker += Lynchburg.length;
map.addOverlays(Moneta);
centerByArray(Moneta, false, false);
cntMarker += Moneta.length;
map.addOverlays(Montvale);
centerByArray(Montvale, false, false);
cntMarker += Montvale.length;
map.addOverlays(Thaxton);
centerByArray(Thaxton, false, false);
cntMarker += Thaxton.length;
centerByArray(Big_Island,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');
}
}