function addMarkers()
{
mySelect = document.getElementById('selection');
Axton = [];Bassett = [];Collinsville = [];Martinsville = [];Ridgeway = [];Fieldale = [];Spencer = [];Stanleytown = [];mySelect.options[mySelect.options.length] = new Option("Axton schools",'all=Axton');
mySelect.options[mySelect.options.length] = new Option("Bassett schools",'all=Bassett');
mySelect.options[mySelect.options.length] = new Option("Collinsville schools",'all=Collinsville');
mySelect.options[mySelect.options.length] = new Option("Fieldale schools",'all=Fieldale');
mySelect.options[mySelect.options.length] = new Option("Martinsville schools",'all=Martinsville');
mySelect.options[mySelect.options.length] = new Option("Ridgeway schools",'all=Ridgeway');
mySelect.options[mySelect.options.length] = new Option("Spencer schools",'all=Spencer');
mySelect.options[mySelect.options.length] = new Option("Stanleytown schools",'all=Stanleytown');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Axton[Axton.length] = createMarker(new GPoint(-79.71369171,36.66131973),"
",iconBl);
mySelect.options[mySelect.options.length] = new Option("Axton Middle School",'Axton=' + Axton.length);
Bassett[Bassett.length] = createMarker(new GPoint(-79.96107483,36.73575592),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Bassett High School",'Bassett=' + Bassett.length);
Bassett[Bassett.length] = createMarker(new GPoint(-79.99588013,36.76188660),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Bassett Middle School",'Bassett=' + Bassett.length);
Collinsville[Collinsville.length] = createMarker(new GPoint(-10.00000000,10.00000000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Breaking Barriers Alternative Ed/henry Co",'Collinsville=' + Collinsville.length);
Bassett[Bassett.length] = createMarker(new GPoint(-79.98213196,36.75643921),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Campbell Court Elementary School",'Bassett=' + Bassett.length);
Martinsville[Martinsville.length] = createMarker(new GPoint(-79.93990326,36.67226410),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Carver Middle School",'Martinsville=' + Martinsville.length);
Martinsville[Martinsville.length] = createMarker(new GPoint(-79.86786652,36.68605042),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Center For Community Learning",'Martinsville=' + Martinsville.length);
Collinsville[Collinsville.length] = createMarker(new GPoint(-79.90938568,36.71886444),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Collinsville Primary",'Collinsville=' + Collinsville.length);
Ridgeway[Ridgeway.length] = createMarker(new GPoint(-79.86105347,36.60680008),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Drewry Mason Middle School",'Ridgeway=' + Ridgeway.length);
Collinsville[Collinsville.length] = createMarker(new GPoint(-79.92308044,36.71173859),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Fieldale Collinsville High School",'Collinsville=' + Collinsville.length);
Fieldale[Fieldale.length] = createMarker(new GPoint(-79.95770264,36.70959854),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Fieldale Elementary School",'Fieldale=' + Fieldale.length);
Martinsville[Martinsville.length] = createMarker(new GPoint(-79.87342072,36.76510239),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Figsboro Elementary School",'Martinsville=' + Martinsville.length);
Collinsville[Collinsville.length] = createMarker(new GPoint(-79.91882324,36.70355988),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Henry Co/martinsville Reg Pgm",'Collinsville=' + Collinsville.length);
Axton[Axton.length] = createMarker(new GPoint(-79.73352814,36.61692810),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Irisburg Elementary School",'Axton=' + Axton.length);
Collinsville[Collinsville.length] = createMarker(new GPoint(-79.91136932,36.71822739),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("John Redd Smith Elementary School",'Collinsville=' + Collinsville.length);
Martinsville[Martinsville.length] = createMarker(new GPoint(-79.78330231,36.68562698),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Laurel Park High School",'Martinsville=' + Martinsville.length);
Ridgeway[Ridgeway.length] = createMarker(new GPoint(-79.89009857,36.60161591),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Magna Vista High School",'Ridgeway=' + Ridgeway.length);
Martinsville[Martinsville.length] = createMarker(new GPoint(-79.81132507,36.68602753),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Mt. Olivet Elementary School",'Martinsville=' + Martinsville.length);
Collinsville[Collinsville.length] = createMarker(new GPoint(-79.91410065,36.72700119),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Piedmont Gov Sch For Math/sci/tech",'Collinsville=' + Collinsville.length);
Martinsville[Martinsville.length] = createMarker(new GPoint(-79.87567902,36.63703918),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Rich Acres Elementary School",'Martinsville=' + Martinsville.length);
Ridgeway[Ridgeway.length] = createMarker(new GPoint(-79.86528015,36.57522202),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Ridgeway Elementary School",'Ridgeway=' + Ridgeway.length);
Bassett[Bassett.length] = createMarker(new GPoint(-80.05255890,36.71405029),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Sanville Elementary School",'Bassett=' + Bassett.length);
Spencer[Spencer.length] = createMarker(new GPoint(-80.01325989,36.61506653),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Spencer Penn Elementary School",'Spencer=' + Spencer.length);
Stanleytown[Stanleytown.length] = createMarker(new GPoint(-79.94203186,36.73616409),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Stanleytown Elementary School",'Stanleytown=' + Stanleytown.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(Axton);
map.removeOverlays(Bassett);
map.removeOverlays(Collinsville);
map.removeOverlays(Fieldale);
map.removeOverlays(Martinsville);
map.removeOverlays(Ridgeway);
map.removeOverlays(Spencer);
map.removeOverlays(Stanleytown);
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(Axton);map.removeOverlays(Axton);
map.removeOverlays(Bassett);
map.removeOverlays(Collinsville);
map.removeOverlays(Fieldale);
map.removeOverlays(Martinsville);
map.removeOverlays(Ridgeway);
map.removeOverlays(Spencer);
map.removeOverlays(Stanleytown);
map.addOverlays(Axton);
centerByArray(Axton, false, false);
cntMarker += Axton.length;
map.addOverlays(Bassett);
centerByArray(Bassett, false, false);
cntMarker += Bassett.length;
map.addOverlays(Collinsville);
centerByArray(Collinsville, false, false);
cntMarker += Collinsville.length;
map.addOverlays(Fieldale);
centerByArray(Fieldale, false, false);
cntMarker += Fieldale.length;
map.addOverlays(Martinsville);
centerByArray(Martinsville, false, false);
cntMarker += Martinsville.length;
map.addOverlays(Ridgeway);
centerByArray(Ridgeway, false, false);
cntMarker += Ridgeway.length;
map.addOverlays(Spencer);
centerByArray(Spencer, false, false);
cntMarker += Spencer.length;
map.addOverlays(Stanleytown);
centerByArray(Stanleytown, false, false);
cntMarker += Stanleytown.length;
centerByArray(Axton,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');
}
}