function addMarkers(){
mySelect = document.getElementById('selection');
Braintree = [];Danvers = [];Jamaica_Plain = [];Swansea = [];Worcester = [];Lenox = [];mySelect.options[mySelect.options.length] = new Option("Braintree schools",'all=Braintree');
mySelect.options[mySelect.options.length] = new Option("Danvers schools",'all=Danvers');
mySelect.options[mySelect.options.length] = new Option("Jamaica Plain schools",'all=Jamaica_Plain');
mySelect.options[mySelect.options.length] = new Option("Lenox schools",'all=Lenox');
mySelect.options[mySelect.options.length] = new Option("Swansea schools",'all=Swansea');
mySelect.options[mySelect.options.length] = new Option("Worcester schools",'all=Worcester');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Braintree[Braintree.length] = createMarker(new GPoint(-71.00301500,42.22981400),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Cardinal Cushing Centers",'Braintree=' + Braintree.length);
Danvers[Danvers.length] = createMarker(new GPoint(-70.92196300,42.56153000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Inst Family Life & Learn",'Danvers=' + Danvers.length);
Jamaica_Plain[Jamaica_Plain.length] = createMarker(new GPoint(-71.11270000,42.31050000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Language And Cognitive Develop",'Jamaica_Plain=' + Jamaica_Plain.length);
Swansea[Swansea.length] = createMarker(new GPoint(-71.18263700,41.74956100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Merdowrige",'Swansea=' + Swansea.length);
Worcester[Worcester.length] = createMarker(new GPoint(-71.79674900,42.25116300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Mary Elementary School",'Worcester=' + Worcester.length);
Lenox[Lenox.length] = createMarker(new GPoint(-73.27470000,42.35900000),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Valleyhead Inc",'Lenox=' + Lenox.length);
map.removeOverlays(Braintree);
map.removeOverlays(Danvers);
map.removeOverlays(Jamaica_Plain);
map.removeOverlays(Lenox);
map.removeOverlays(Swansea);
map.removeOverlays(Worcester);
setTimeout(function(){map.addOverlays(Braintree)},1000);
setTimeout(function(){map.addOverlays(Danvers)},1000);
setTimeout(function(){map.addOverlays(Jamaica_Plain)},1000);
setTimeout(function(){map.addOverlays(Lenox)},1000);
setTimeout(function(){map.addOverlays(Swansea)},1000);
setTimeout(function(){map.addOverlays(Worcester)},1000);
maxLng = -70.92196300;
maxLat = 42.56153000;
minLng = -73.27470000;
minLat = 41.74956100;
reCenterMap();
} // 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,11);
/*
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(Braintree);
map.removeOverlays(Danvers);
map.removeOverlays(Jamaica_Plain);
map.removeOverlays(Lenox);
map.removeOverlays(Swansea);
map.removeOverlays(Worcester);
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(Braintree);map.removeOverlays(Braintree);
map.removeOverlays(Danvers);
map.removeOverlays(Jamaica_Plain);
map.removeOverlays(Lenox);
map.removeOverlays(Swansea);
map.removeOverlays(Worcester);
map.addOverlays(Braintree);
centerByArray(Braintree, false, false);
cntMarker += Braintree.length;
map.addOverlays(Danvers);
centerByArray(Danvers, false, false);
cntMarker += Danvers.length;
map.addOverlays(Jamaica_Plain);
centerByArray(Jamaica_Plain, false, false);
cntMarker += Jamaica_Plain.length;
map.addOverlays(Lenox);
centerByArray(Lenox, false, false);
cntMarker += Lenox.length;
map.addOverlays(Swansea);
centerByArray(Swansea, false, false);
cntMarker += Swansea.length;
map.addOverlays(Worcester);
centerByArray(Worcester, false, false);
cntMarker += Worcester.length;
centerByArray(Braintree,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///12933,13085,13110,13514,13451,12933,13110,13451,13390,/all');
//window.open('/map.php?type=2&schools=12933,13085,13110,13514,13451,12933,13110,13451,13390,&school_level=&radius=&zipcode=&school_type_search=&school_type_code=');
}
}
function createMarker(point, label, icon)
{
var marker = new GMarker(point, icon);
var html = label;
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
return marker;
}