function addMarkers()
{
mySelect = document.getElementById('selection');
Lucas = [];Glasgow = [];Cave_City = [];Hiseville = [];Park_City = [];mySelect.options[mySelect.options.length] = new Option("Cave City schools",'all=Cave_City');
mySelect.options[mySelect.options.length] = new Option("Glasgow schools",'all=Glasgow');
mySelect.options[mySelect.options.length] = new Option("Hiseville schools",'all=Hiseville');
mySelect.options[mySelect.options.length] = new Option("Lucas schools",'all=Lucas');
mySelect.options[mySelect.options.length] = new Option("Park City schools",'all=Park_City');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Lucas[Lucas.length] = createMarker(new GPoint(-86.04528046,36.84836197),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Austin Tracy Elementary School",'Lucas=' + Lucas.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.91350100,36.99541200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Barren Academy Of Virtual & Expanded Learni",'Glasgow=' + Glasgow.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.91016388,36.97267914),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Barren County Day Treatment Center",'Glasgow=' + Glasgow.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.92507172,36.97639847),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Barren County High School",'Glasgow=' + Glasgow.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.92859650,36.97729111),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Barren County Middle School",'Glasgow=' + Glasgow.length);
Cave_City[Cave_City.length] = createMarker(new GPoint(-85.94117737,37.14741516),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Caverna Elementary School",'Cave_City=' + Cave_City.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.90573120,36.99827576),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("E B Terry Elementary School",'Glasgow=' + Glasgow.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.87188300,36.99202600),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Eastern Elementary School",'Glasgow=' + Glasgow.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.89001465,37.00656509),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Glasgow High School",'Glasgow=' + Glasgow.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.88657379,37.00923538),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Glasgow Middle School",'Glasgow=' + Glasgow.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.91859436,37.00604248),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Happy Valley Elementary School",'Glasgow=' + Glasgow.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.88787000,37.01149100),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Highland Elementary School",'Glasgow=' + Glasgow.length);
Hiseville[Hiseville.length] = createMarker(new GPoint(-85.81871796,37.09884644),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Hiseville Elementary School",'Hiseville=' + Hiseville.length);
Park_City[Park_City.length] = createMarker(new GPoint(-86.04556274,37.10052109),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Park City Elementary School",'Park_City=' + Park_City.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.93716431,36.98479843),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Red Cross Elementary School",'Glasgow=' + Glasgow.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.92937469,36.98231506),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("South Green Elementary School",'Glasgow=' + Glasgow.length);
Glasgow[Glasgow.length] = createMarker(new GPoint(-85.84744263,36.88663101),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Temple Hill Elementary School",'Glasgow=' + Glasgow.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(Cave_City);
map.removeOverlays(Glasgow);
map.removeOverlays(Hiseville);
map.removeOverlays(Lucas);
map.removeOverlays(Park_City);
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(Lucas);map.removeOverlays(Cave_City);
map.removeOverlays(Glasgow);
map.removeOverlays(Hiseville);
map.removeOverlays(Lucas);
map.removeOverlays(Park_City);
map.addOverlays(Cave_City);
centerByArray(Cave_City, false, false);
cntMarker += Cave_City.length;
map.addOverlays(Glasgow);
centerByArray(Glasgow, false, false);
cntMarker += Glasgow.length;
map.addOverlays(Hiseville);
centerByArray(Hiseville, false, false);
cntMarker += Hiseville.length;
map.addOverlays(Lucas);
centerByArray(Lucas, false, false);
cntMarker += Lucas.length;
map.addOverlays(Park_City);
centerByArray(Park_City, false, false);
cntMarker += Park_City.length;
centerByArray(Lucas,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');
}
}