function addMarkers()
{
mySelect = document.getElementById('selection');
Mechanicsburg = [];Urbana = [];Saint_Paris = [];Rosewood = [];North_Lewisburg = [];mySelect.options[mySelect.options.length] = new Option("Mechanicsburg schools",'all=Mechanicsburg');
mySelect.options[mySelect.options.length] = new Option("North Lewisburg schools",'all=North_Lewisburg');
mySelect.options[mySelect.options.length] = new Option("Rosewood schools",'all=Rosewood');
mySelect.options[mySelect.options.length] = new Option("Saint Paris schools",'all=Saint_Paris');
mySelect.options[mySelect.options.length] = new Option("Urbana schools",'all=Urbana');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Mechanicsburg[Mechanicsburg.length] = createMarker(new GPoint(-83.55846405,40.07573700),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Dohron Wilson Elementary School",'Mechanicsburg=' + Mechanicsburg.length);
Urbana[Urbana.length] = createMarker(new GPoint(-83.73963928,40.11186218),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("East Elementary School",'Urbana=' + Urbana.length);
Saint_Paris[Saint_Paris.length] = createMarker(new GPoint(-83.95362091,40.12771606),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Graham Digital Academy",'Saint_Paris=' + Saint_Paris.length);
Saint_Paris[Saint_Paris.length] = createMarker(new GPoint(-83.90864563,40.12131119),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Graham High School",'Saint_Paris=' + Saint_Paris.length);
Saint_Paris[Saint_Paris.length] = createMarker(new GPoint(-83.94386292,40.12613297),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Graham Middle School",'Saint_Paris=' + Saint_Paris.length);
Rosewood[Rosewood.length] = createMarker(new GPoint(-83.95618439,40.21882248),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Graham North Elementary School",'Rosewood=' + Rosewood.length);
Saint_Paris[Saint_Paris.length] = createMarker(new GPoint(-83.96334076,40.08082962),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Graham South Elementary School",'Saint_Paris=' + Saint_Paris.length);
Urbana[Urbana.length] = createMarker(new GPoint(-83.73585510,40.06687927),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Local Intermediate Elementary School",'Urbana=' + Urbana.length);
Mechanicsburg[Mechanicsburg.length] = createMarker(new GPoint(-83.55846405,40.07573700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Mechanicsburg High School",'Mechanicsburg=' + Mechanicsburg.length);
Urbana[Urbana.length] = createMarker(new GPoint(-83.75634766,40.11478806),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("North Elementary School",'Urbana=' + Urbana.length);
Urbana[Urbana.length] = createMarker(new GPoint(-83.75331879,40.09925842),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("South Elementary School",'Urbana=' + Urbana.length);
North_Lewisburg[North_Lewisburg.length] = createMarker(new GPoint(-83.58798218,40.18023682),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Triad Elementary School",'North_Lewisburg=' + North_Lewisburg.length);
North_Lewisburg[North_Lewisburg.length] = createMarker(new GPoint(-83.59841156,40.17511368),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Triad High School",'North_Lewisburg=' + North_Lewisburg.length);
North_Lewisburg[North_Lewisburg.length] = createMarker(new GPoint(-83.58731079,40.17996216),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Triad Middle School",'North_Lewisburg=' + North_Lewisburg.length);
Urbana[Urbana.length] = createMarker(new GPoint(-83.74435425,40.11497879),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Urbana Community School",'Urbana=' + Urbana.length);
Urbana[Urbana.length] = createMarker(new GPoint(-83.74399567,40.11211777),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Urbana High School",'Urbana=' + Urbana.length);
Urbana[Urbana.length] = createMarker(new GPoint(-83.74399567,40.11211777),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Urbana Junior High School",'Urbana=' + Urbana.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(Mechanicsburg);
map.removeOverlays(North_Lewisburg);
map.removeOverlays(Rosewood);
map.removeOverlays(Saint_Paris);
map.removeOverlays(Urbana);
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(Mechanicsburg);map.removeOverlays(Mechanicsburg);
map.removeOverlays(North_Lewisburg);
map.removeOverlays(Rosewood);
map.removeOverlays(Saint_Paris);
map.removeOverlays(Urbana);
map.addOverlays(Mechanicsburg);
centerByArray(Mechanicsburg, false, false);
cntMarker += Mechanicsburg.length;
map.addOverlays(North_Lewisburg);
centerByArray(North_Lewisburg, false, false);
cntMarker += North_Lewisburg.length;
map.addOverlays(Rosewood);
centerByArray(Rosewood, false, false);
cntMarker += Rosewood.length;
map.addOverlays(Saint_Paris);
centerByArray(Saint_Paris, false, false);
cntMarker += Saint_Paris.length;
map.addOverlays(Urbana);
centerByArray(Urbana, false, false);
cntMarker += Urbana.length;
centerByArray(Mechanicsburg,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');
}
}