function addMarkers()
{
mySelect = document.getElementById('selection');
Saxe = [];Charlotte_Court_House = [];Keysville = [];Phenix = [];Charlotte_C_H = [];mySelect.options[mySelect.options.length] = new Option("Charlotte C H schools",'all=Charlotte_C_H');
mySelect.options[mySelect.options.length] = new Option("Charlotte Court House schools",'all=Charlotte_Court_House');
mySelect.options[mySelect.options.length] = new Option("Keysville schools",'all=Keysville');
mySelect.options[mySelect.options.length] = new Option("Phenix schools",'all=Phenix');
mySelect.options[mySelect.options.length] = new Option("Saxe schools",'all=Saxe');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Saxe[Saxe.length] = createMarker(new GPoint(-78.61430359,36.90417862),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Bacon District Elementary School",'Saxe=' + Saxe.length);
Charlotte_Court_House[Charlotte_Court_House.length] = createMarker(new GPoint(-78.65689850,37.07870102),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Central Middle School",'Charlotte_Court_House=' + Charlotte_Court_House.length);
Keysville[Keysville.length] = createMarker(new GPoint(-78.55291748,37.04323578),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Eureka Elementary School",'Keysville=' + Keysville.length);
Keysville[Keysville.length] = createMarker(new GPoint(-78.46175200,37.03867800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Gov Sch Global Economics/tech",'Keysville=' + Keysville.length);
Charlotte_Court_House[Charlotte_Court_House.length] = createMarker(new GPoint(-78.71713257,37.07562637),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("J. Murray Jeffress Elementary School",'Charlotte_Court_House=' + Charlotte_Court_House.length);
Phenix[Phenix.length] = createMarker(new GPoint(-78.79699707,37.08470154),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Phenix Elementary School",'Phenix=' + Phenix.length);
Charlotte_Court_House[Charlotte_Court_House.length] = createMarker(new GPoint(-78.65689850,37.07870102),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Pre-k/early Learning Center",'Charlotte_Court_House=' + Charlotte_Court_House.length);
Charlotte_C_H[Charlotte_C_H.length] = createMarker(new GPoint(-78.65689850,37.07870102),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Randolph Henry Senior High School",'Charlotte_C_H=' + Charlotte_C_H.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(Charlotte_C_H);
map.removeOverlays(Charlotte_Court_House);
map.removeOverlays(Keysville);
map.removeOverlays(Phenix);
map.removeOverlays(Saxe);
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(Saxe);map.removeOverlays(Charlotte_C_H);
map.removeOverlays(Charlotte_Court_House);
map.removeOverlays(Keysville);
map.removeOverlays(Phenix);
map.removeOverlays(Saxe);
map.addOverlays(Charlotte_C_H);
centerByArray(Charlotte_C_H, false, false);
cntMarker += Charlotte_C_H.length;
map.addOverlays(Charlotte_Court_House);
centerByArray(Charlotte_Court_House, false, false);
cntMarker += Charlotte_Court_House.length;
map.addOverlays(Keysville);
centerByArray(Keysville, false, false);
cntMarker += Keysville.length;
map.addOverlays(Phenix);
centerByArray(Phenix, false, false);
cntMarker += Phenix.length;
map.addOverlays(Saxe);
centerByArray(Saxe, false, false);
cntMarker += Saxe.length;
centerByArray(Saxe,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');
}
}