function addMarkers()
{
mySelect = document.getElementById('selection');
Wilton = [];New_Sharon = [];Farmington = [];Jay = [];Kingfield = [];Strong = [];Phillips = [];Rangeley = [];Stratton = [];Weld = [];mySelect.options[mySelect.options.length] = new Option("Farmington schools",'all=Farmington');
mySelect.options[mySelect.options.length] = new Option("Jay schools",'all=Jay');
mySelect.options[mySelect.options.length] = new Option("Kingfield schools",'all=Kingfield');
mySelect.options[mySelect.options.length] = new Option("New Sharon schools",'all=New_Sharon');
mySelect.options[mySelect.options.length] = new Option("Phillips schools",'all=Phillips');
mySelect.options[mySelect.options.length] = new Option("Rangeley schools",'all=Rangeley');
mySelect.options[mySelect.options.length] = new Option("Stratton schools",'all=Stratton');
mySelect.options[mySelect.options.length] = new Option("Strong schools",'all=Strong');
mySelect.options[mySelect.options.length] = new Option("Weld schools",'all=Weld');
mySelect.options[mySelect.options.length] = new Option("Wilton schools",'all=Wilton');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Wilton[Wilton.length] = createMarker(new GPoint(-70.22526550,44.59217834),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Academy Hill School",'Wilton=' + Wilton.length);
New_Sharon[New_Sharon.length] = createMarker(new GPoint(-70.03549957,44.61371994),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Cape Cod Hill Elementary School",'New_Sharon=' + New_Sharon.length);
Farmington[Farmington.length] = createMarker(new GPoint(-70.14350128,44.66529846),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Cascade Brook School",'Farmington=' + Farmington.length);
Wilton[Wilton.length] = createMarker(new GPoint(-70.22734070,44.59334183),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Gerald D Cushing School",'Wilton=' + Wilton.length);
Jay[Jay.length] = createMarker(new GPoint(-70.20130157,44.49428558),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Jay Elementary School",'Jay=' + Jay.length);
Jay[Jay.length] = createMarker(new GPoint(-70.20204163,44.49422073),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Jay High School",'Jay=' + Jay.length);
Jay[Jay.length] = createMarker(new GPoint(-70.20204163,44.49422073),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Jay Middle School",'Jay=' + Jay.length);
Farmington[Farmington.length] = createMarker(new GPoint(-70.13012695,44.63761902),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Ken Foster Regional Applied Technical Center",'Farmington=' + Farmington.length);
Kingfield[Kingfield.length] = createMarker(new GPoint(-70.24320221,45.03850174),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Kingfield Elementary School",'Kingfield=' + Kingfield.length);
Strong[Strong.length] = createMarker(new GPoint(-70.21849823,44.83829880),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Mt Abram Regional High School",'Strong=' + Strong.length);
Farmington[Farmington.length] = createMarker(new GPoint(-70.12950897,44.63970947),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Mt Blue High School",'Farmington=' + Farmington.length);
Farmington[Farmington.length] = createMarker(new GPoint(-70.14018250,44.67202759),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Mt Blue Middle School",'Farmington=' + Farmington.length);
Phillips[Phillips.length] = createMarker(new GPoint(-70.36730194,44.83160019),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Phillips Middle School",'Phillips=' + Phillips.length);
Phillips[Phillips.length] = createMarker(new GPoint(-70.34422302,44.82255936),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Phillips Primary School",'Phillips=' + Phillips.length);
Rangeley[Rangeley.length] = createMarker(new GPoint(-70.64163208,44.96575165),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Rangeley Lakes Regional School",'Rangeley=' + Rangeley.length);
Stratton[Stratton.length] = createMarker(new GPoint(-70.43566895,45.14239120),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Stratton Elementary School",'Stratton=' + Stratton.length);
Strong[Strong.length] = createMarker(new GPoint(-70.21871948,44.81428146),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Strong Elementary School",'Strong=' + Strong.length);
Farmington[Farmington.length] = createMarker(new GPoint(-70.14391327,44.66899872),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("W G Mallett School",'Farmington=' + Farmington.length);
Weld[Weld.length] = createMarker(new GPoint(-70.41777039,44.69738388),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Weld Elementary School",'Weld=' + Weld.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(Farmington);
map.removeOverlays(Jay);
map.removeOverlays(Kingfield);
map.removeOverlays(New_Sharon);
map.removeOverlays(Phillips);
map.removeOverlays(Rangeley);
map.removeOverlays(Stratton);
map.removeOverlays(Strong);
map.removeOverlays(Weld);
map.removeOverlays(Wilton);
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(Wilton);map.removeOverlays(Farmington);
map.removeOverlays(Jay);
map.removeOverlays(Kingfield);
map.removeOverlays(New_Sharon);
map.removeOverlays(Phillips);
map.removeOverlays(Rangeley);
map.removeOverlays(Stratton);
map.removeOverlays(Strong);
map.removeOverlays(Weld);
map.removeOverlays(Wilton);
map.addOverlays(Farmington);
centerByArray(Farmington, false, false);
cntMarker += Farmington.length;
map.addOverlays(Jay);
centerByArray(Jay, false, false);
cntMarker += Jay.length;
map.addOverlays(Kingfield);
centerByArray(Kingfield, false, false);
cntMarker += Kingfield.length;
map.addOverlays(New_Sharon);
centerByArray(New_Sharon, false, false);
cntMarker += New_Sharon.length;
map.addOverlays(Phillips);
centerByArray(Phillips, false, false);
cntMarker += Phillips.length;
map.addOverlays(Rangeley);
centerByArray(Rangeley, false, false);
cntMarker += Rangeley.length;
map.addOverlays(Stratton);
centerByArray(Stratton, false, false);
cntMarker += Stratton.length;
map.addOverlays(Strong);
centerByArray(Strong, false, false);
cntMarker += Strong.length;
map.addOverlays(Weld);
centerByArray(Weld, false, false);
cntMarker += Weld.length;
map.addOverlays(Wilton);
centerByArray(Wilton, false, false);
cntMarker += Wilton.length;
centerByArray(Wilton,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');
}
}