function addMarkers()
{
mySelect = document.getElementById('selection');
Fincastle = [];Buchanan = [];Cloverdale = [];Blue_Ridge = [];Eagle_Rock = [];Troutville = [];Daleville = [];Roanoke = [];mySelect.options[mySelect.options.length] = new Option("Blue Ridge schools",'all=Blue_Ridge');
mySelect.options[mySelect.options.length] = new Option("Buchanan schools",'all=Buchanan');
mySelect.options[mySelect.options.length] = new Option("Cloverdale schools",'all=Cloverdale');
mySelect.options[mySelect.options.length] = new Option("Daleville schools",'all=Daleville');
mySelect.options[mySelect.options.length] = new Option("Eagle Rock schools",'all=Eagle_Rock');
mySelect.options[mySelect.options.length] = new Option("Fincastle schools",'all=Fincastle');
mySelect.options[mySelect.options.length] = new Option("Roanoke schools",'all=Roanoke');
mySelect.options[mySelect.options.length] = new Option("Troutville schools",'all=Troutville');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Fincastle[Fincastle.length] = createMarker(new GPoint(-79.86303711,37.50588989),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Botetourt Tech Educ Center",'Fincastle=' + Fincastle.length);
Fincastle[Fincastle.length] = createMarker(new GPoint(-79.87149811,37.50301743),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Breckinridge Elementary School",'Fincastle=' + Fincastle.length);
Buchanan[Buchanan.length] = createMarker(new GPoint(-79.70336914,37.51139069),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Buchanan Elementary School",'Buchanan=' + Buchanan.length);
Fincastle[Fincastle.length] = createMarker(new GPoint(-79.86232758,37.50733566),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Central Academy Middle School",'Fincastle=' + Fincastle.length);
Cloverdale[Cloverdale.length] = createMarker(new GPoint(-79.90345764,37.36642838),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Cloverdale Elementary School",'Cloverdale=' + Cloverdale.length);
Blue_Ridge[Blue_Ridge.length] = createMarker(new GPoint(-79.81647491,37.35723495),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Colonial Elementary School",'Blue_Ridge=' + Blue_Ridge.length);
Eagle_Rock[Eagle_Rock.length] = createMarker(new GPoint(-79.81066132,37.65555191),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Eagle Rock Elementary School",'Eagle_Rock=' + Eagle_Rock.length);
Troutville[Troutville.length] = createMarker(new GPoint(-79.93023682,37.42869568),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Greenfield Elementary School",'Troutville=' + Troutville.length);
Buchanan[Buchanan.length] = createMarker(new GPoint(-79.72823334,37.54809189),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("James River High School",'Buchanan=' + Buchanan.length);
Daleville[Daleville.length] = createMarker(new GPoint(-79.91397095,37.40526199),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Lord Botetourt High School",'Daleville=' + Daleville.length);
Cloverdale[Cloverdale.length] = createMarker(new GPoint(-79.90184021,37.35775375),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Read Mountain Middle School",'Cloverdale=' + Cloverdale.length);
Roanoke[Roanoke.length] = createMarker(new GPoint(-79.85910900,37.33629100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Roanoke Valley Juvenile Detention Home",'Roanoke=' + Roanoke.length);
Troutville[Troutville.length] = createMarker(new GPoint(-79.84626770,37.44143295),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Troutville Elementary School",'Troutville=' + Troutville.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(Blue_Ridge);
map.removeOverlays(Buchanan);
map.removeOverlays(Cloverdale);
map.removeOverlays(Daleville);
map.removeOverlays(Eagle_Rock);
map.removeOverlays(Fincastle);
map.removeOverlays(Roanoke);
map.removeOverlays(Troutville);
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(Fincastle);map.removeOverlays(Blue_Ridge);
map.removeOverlays(Buchanan);
map.removeOverlays(Cloverdale);
map.removeOverlays(Daleville);
map.removeOverlays(Eagle_Rock);
map.removeOverlays(Fincastle);
map.removeOverlays(Roanoke);
map.removeOverlays(Troutville);
map.addOverlays(Blue_Ridge);
centerByArray(Blue_Ridge, false, false);
cntMarker += Blue_Ridge.length;
map.addOverlays(Buchanan);
centerByArray(Buchanan, false, false);
cntMarker += Buchanan.length;
map.addOverlays(Cloverdale);
centerByArray(Cloverdale, false, false);
cntMarker += Cloverdale.length;
map.addOverlays(Daleville);
centerByArray(Daleville, false, false);
cntMarker += Daleville.length;
map.addOverlays(Eagle_Rock);
centerByArray(Eagle_Rock, false, false);
cntMarker += Eagle_Rock.length;
map.addOverlays(Fincastle);
centerByArray(Fincastle, false, false);
cntMarker += Fincastle.length;
map.addOverlays(Roanoke);
centerByArray(Roanoke, false, false);
cntMarker += Roanoke.length;
map.addOverlays(Troutville);
centerByArray(Troutville, false, false);
cntMarker += Troutville.length;
centerByArray(Fincastle,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');
}
}