function addMarkers()
{
mySelect = document.getElementById('selection');
Christiansburg = [];Riner = [];Radford = [];Blacksburg = [];Elliston = [];Shawsville = [];mySelect.options[mySelect.options.length] = new Option("Blacksburg schools",'all=Blacksburg');
mySelect.options[mySelect.options.length] = new Option("Christiansburg schools",'all=Christiansburg');
mySelect.options[mySelect.options.length] = new Option("Elliston schools",'all=Elliston');
mySelect.options[mySelect.options.length] = new Option("Radford schools",'all=Radford');
mySelect.options[mySelect.options.length] = new Option("Riner schools",'all=Riner');
mySelect.options[mySelect.options.length] = new Option("Shawsville schools",'all=Shawsville');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Christiansburg[Christiansburg.length] = createMarker(new GPoint(-10.00000000,10.00000000),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Altern Ed Prgm/behav Disord Youth/montgomery",'Christiansburg=' + Christiansburg.length);
Riner[Riner.length] = createMarker(new GPoint(-80.44157410,37.05932236),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Auburn Elementary School",'Riner=' + Riner.length);
Riner[Riner.length] = createMarker(new GPoint(-80.44148254,37.06279755),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Auburn High School",'Riner=' + Riner.length);
Riner[Riner.length] = createMarker(new GPoint(-80.44142151,37.06491470),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Auburn Middle School",'Riner=' + Riner.length);
Radford[Radford.length] = createMarker(new GPoint(-80.51037598,37.17096329),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Belview Elementary School",'Radford=' + Radford.length);
Blacksburg[Blacksburg.length] = createMarker(new GPoint(-80.41760254,37.24689865),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Blacksburg High School",'Blacksburg=' + Blacksburg.length);
Blacksburg[Blacksburg.length] = createMarker(new GPoint(-80.46186066,37.21586227),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Blacksburg Middle School",'Blacksburg=' + Blacksburg.length);
Christiansburg[Christiansburg.length] = createMarker(new GPoint(-80.41670227,37.13579941),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Christiansburg Elementary School",'Christiansburg=' + Christiansburg.length);
Christiansburg[Christiansburg.length] = createMarker(new GPoint(-80.41624451,37.14449310),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Christiansburg High School",'Christiansburg=' + Christiansburg.length);
Christiansburg[Christiansburg.length] = createMarker(new GPoint(-80.41217804,37.12849808),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Christiansburg Middle School",'Christiansburg=' + Christiansburg.length);
Christiansburg[Christiansburg.length] = createMarker(new GPoint(-80.41652679,37.13741684),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Christiansburg Primary",'Christiansburg=' + Christiansburg.length);
Elliston[Elliston.length] = createMarker(new GPoint(-80.23184967,37.21614838),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Eastern Montgomery High School",'Elliston=' + Elliston.length);
Elliston[Elliston.length] = createMarker(new GPoint(-80.21275330,37.22453690),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Elliston Lafayette Elementary School",'Elliston=' + Elliston.length);
Christiansburg[Christiansburg.length] = createMarker(new GPoint(-80.36621857,37.12522888),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Falling Branch Elementary School",'Christiansburg=' + Christiansburg.length);
Blacksburg[Blacksburg.length] = createMarker(new GPoint(-80.42668152,37.23668289),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Gilbert Linkous Elementary School",'Blacksburg=' + Blacksburg.length);
Blacksburg[Blacksburg.length] = createMarker(new GPoint(-80.41058350,37.23399734),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Harding Avenue Elementary School",'Blacksburg=' + Blacksburg.length);
Christiansburg[Christiansburg.length] = createMarker(new GPoint(-80.41537476,37.14517212),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Independence Secondary",'Christiansburg=' + Christiansburg.length);
Blacksburg[Blacksburg.length] = createMarker(new GPoint(-80.45565033,37.21750259),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Kipps Elementary School",'Blacksburg=' + Blacksburg.length);
Blacksburg[Blacksburg.length] = createMarker(new GPoint(-80.40764618,37.21451569),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Margaret Beeks Elementary School",'Blacksburg=' + Blacksburg.length);
Christiansburg[Christiansburg.length] = createMarker(new GPoint(-80.42345428,37.13516235),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("New River Valley Juv. Detention Center",'Christiansburg=' + Christiansburg.length);
Christiansburg[Christiansburg.length] = createMarker(new GPoint(-10.00000000,10.00000000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("New River Valley Juvenile Detention Home",'Christiansburg=' + Christiansburg.length);
Blacksburg[Blacksburg.length] = createMarker(new GPoint(-80.49077606,37.20924759),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Prices Fork Elementary School",'Blacksburg=' + Blacksburg.length);
Elliston[Elliston.length] = createMarker(new GPoint(-80.26619720,37.15169907),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Shawsville Elementary School",'Elliston=' + Elliston.length);
Shawsville[Shawsville.length] = createMarker(new GPoint(-80.26619720,37.15169907),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Shawsville Middle School",'Shawsville=' + Shawsville.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(Blacksburg);
map.removeOverlays(Christiansburg);
map.removeOverlays(Elliston);
map.removeOverlays(Radford);
map.removeOverlays(Riner);
map.removeOverlays(Shawsville);
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(Christiansburg);map.removeOverlays(Blacksburg);
map.removeOverlays(Christiansburg);
map.removeOverlays(Elliston);
map.removeOverlays(Radford);
map.removeOverlays(Riner);
map.removeOverlays(Shawsville);
map.addOverlays(Blacksburg);
centerByArray(Blacksburg, false, false);
cntMarker += Blacksburg.length;
map.addOverlays(Christiansburg);
centerByArray(Christiansburg, false, false);
cntMarker += Christiansburg.length;
map.addOverlays(Elliston);
centerByArray(Elliston, false, false);
cntMarker += Elliston.length;
map.addOverlays(Radford);
centerByArray(Radford, false, false);
cntMarker += Radford.length;
map.addOverlays(Riner);
centerByArray(Riner, false, false);
cntMarker += Riner.length;
map.addOverlays(Shawsville);
centerByArray(Shawsville, false, false);
cntMarker += Shawsville.length;
centerByArray(Christiansburg,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');
}
}