function addMarkers()
{
mySelect = document.getElementById('selection');
Morganton = [];Drexel = [];Connelly_Springs = [];Icard = [];Valdese = [];Hildebran = [];Hickory = [];Rutherford_College = [];mySelect.options[mySelect.options.length] = new Option("Connelly Springs schools",'all=Connelly_Springs');
mySelect.options[mySelect.options.length] = new Option("Drexel schools",'all=Drexel');
mySelect.options[mySelect.options.length] = new Option("Hickory schools",'all=Hickory');
mySelect.options[mySelect.options.length] = new Option("Hildebran schools",'all=Hildebran');
mySelect.options[mySelect.options.length] = new Option("Icard schools",'all=Icard');
mySelect.options[mySelect.options.length] = new Option("Morganton schools",'all=Morganton');
mySelect.options[mySelect.options.length] = new Option("Rutherford College schools",'all=Rutherford_College');
mySelect.options[mySelect.options.length] = new Option("Valdese schools",'all=Valdese');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Morganton[Morganton.length] = createMarker(new GPoint(-81.68476105,35.73997498),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Burke Alternate",'Morganton=' + Morganton.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.67170715,35.81684875),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Chesterfield Elementary School",'Morganton=' + Morganton.length);
Drexel[Drexel.length] = createMarker(new GPoint(-81.60440063,35.75770187),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Drexel Primary",'Drexel=' + Drexel.length);
Drexel[Drexel.length] = createMarker(new GPoint(-81.60440063,35.75770187),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Drexel/hallyburton Elementary School",'Drexel=' + Drexel.length);
Connelly_Springs[Connelly_Springs.length] = createMarker(new GPoint(-81.48082733,35.71903992),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("East Burke High School",'Connelly_Springs=' + Connelly_Springs.length);
Icard[Icard.length] = createMarker(new GPoint(-81.47080231,35.72719955),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("East Burke Middle School",'Icard=' + Icard.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.70081329,35.73174286),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Forest Hill Elementary School",'Morganton=' + Morganton.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.72278595,35.74296188),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Freedom High School",'Morganton=' + Morganton.length);
Connelly_Springs[Connelly_Springs.length] = createMarker(new GPoint(-81.50550079,35.70399857),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("George Hildebrand Elementary School",'Connelly_Springs=' + Connelly_Springs.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.77867126,35.72639847),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Glen Alpine Elementary School",'Morganton=' + Morganton.length);
Valdese[Valdese.length] = createMarker(new GPoint(-81.58266449,35.75891113),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Heritage Middle School",'Valdese=' + Valdese.length);
Hildebran[Hildebran.length] = createMarker(new GPoint(-81.42209625,35.71620178),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Hildebran Elementary School",'Hildebran=' + Hildebran.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.67508698,35.75432205),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Hillcrest Elementary School",'Morganton=' + Morganton.length);
Icard[Icard.length] = createMarker(new GPoint(-81.47080231,35.72719955),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Icard Elementary School",'Icard=' + Icard.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.67188263,35.70939255),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Liberty Middle School",'Morganton=' + Morganton.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.70059204,35.75336838),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Mountain View Elementary School",'Morganton=' + Morganton.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.71489716,35.73460007),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Mull Elementary School",'Morganton=' + Morganton.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.68499756,35.74520111),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("New Dimensions School",'Morganton=' + Morganton.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.67192078,35.70962906),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("North Liberty",'Morganton=' + Morganton.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.68499756,35.74520111),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Oak Hill Elementary School",'Morganton=' + Morganton.length);
Hickory[Hickory.length] = createMarker(new GPoint(-81.42726135,35.75159836),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Ray Childers Elementary School",'Hickory=' + Hickory.length);
Rutherford_College[Rutherford_College.length] = createMarker(new GPoint(-81.52749634,35.75469971),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Rutherford College Elementary School",'Rutherford_College=' + Rutherford_College.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.70083618,35.69615173),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Salem Elementary School",'Morganton=' + Morganton.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.71489716,35.73460007),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Table Rock Middle School",'Morganton=' + Morganton.length);
Valdese[Valdese.length] = createMarker(new GPoint(-81.56507111,35.74544144),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Valdese Elementary School",'Valdese=' + Valdese.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.76857758,35.71834946),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("W A Young Elementary School",'Morganton=' + Morganton.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.71499634,35.73440170),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Walter R Johnson Middle School",'Morganton=' + Morganton.length);
Morganton[Morganton.length] = createMarker(new GPoint(-81.68771362,35.73321915),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Wtn Nc School For Deaf",'Morganton=' + Morganton.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(Connelly_Springs);
map.removeOverlays(Drexel);
map.removeOverlays(Hickory);
map.removeOverlays(Hildebran);
map.removeOverlays(Icard);
map.removeOverlays(Morganton);
map.removeOverlays(Rutherford_College);
map.removeOverlays(Valdese);
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(Morganton);map.removeOverlays(Connelly_Springs);
map.removeOverlays(Drexel);
map.removeOverlays(Hickory);
map.removeOverlays(Hildebran);
map.removeOverlays(Icard);
map.removeOverlays(Morganton);
map.removeOverlays(Rutherford_College);
map.removeOverlays(Valdese);
map.addOverlays(Connelly_Springs);
centerByArray(Connelly_Springs, false, false);
cntMarker += Connelly_Springs.length;
map.addOverlays(Drexel);
centerByArray(Drexel, false, false);
cntMarker += Drexel.length;
map.addOverlays(Hickory);
centerByArray(Hickory, false, false);
cntMarker += Hickory.length;
map.addOverlays(Hildebran);
centerByArray(Hildebran, false, false);
cntMarker += Hildebran.length;
map.addOverlays(Icard);
centerByArray(Icard, false, false);
cntMarker += Icard.length;
map.addOverlays(Morganton);
centerByArray(Morganton, false, false);
cntMarker += Morganton.length;
map.addOverlays(Rutherford_College);
centerByArray(Rutherford_College, false, false);
cntMarker += Rutherford_College.length;
map.addOverlays(Valdese);
centerByArray(Valdese, false, false);
cntMarker += Valdese.length;
centerByArray(Morganton,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');
}
}