function addMarkers() { mySelect = document.getElementById('selection'); Albertson = [];Beulaville = [];Rose_Hill = [];Chinquapin = [];Kenansville = [];Warsaw = [];Calypso = [];Wallace = [];Teachey = [];mySelect.options[mySelect.options.length] = new Option("Albertson schools",'all=Albertson'); mySelect.options[mySelect.options.length] = new Option("Beulaville schools",'all=Beulaville'); mySelect.options[mySelect.options.length] = new Option("Calypso schools",'all=Calypso'); mySelect.options[mySelect.options.length] = new Option("Chinquapin schools",'all=Chinquapin'); mySelect.options[mySelect.options.length] = new Option("Kenansville schools",'all=Kenansville'); mySelect.options[mySelect.options.length] = new Option("Rose Hill schools",'all=Rose_Hill'); mySelect.options[mySelect.options.length] = new Option("Teachey schools",'all=Teachey'); mySelect.options[mySelect.options.length] = new Option("Wallace schools",'all=Wallace'); mySelect.options[mySelect.options.length] = new Option("Warsaw schools",'all=Warsaw'); mySelect.options[mySelect.options.length] = new Option("---------------------------",''); Albertson[Albertson.length] = createMarker(new GPoint(-77.81849670,35.10844040),"
",iconRd); mySelect.options[mySelect.options.length] = new Option("B F Grady Elementary School",'Albertson=' + Albertson.length); Beulaville[Beulaville.length] = createMarker(new GPoint(-77.77349700,34.92412000),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Beulaville Elementary School",'Beulaville=' + Beulaville.length); Rose_Hill[Rose_Hill.length] = createMarker(new GPoint(-78.02321400,34.82870500),"",iconBl); mySelect.options[mySelect.options.length] = new Option("Charity Middle School",'Rose_Hill=' + Rose_Hill.length); Chinquapin[Chinquapin.length] = createMarker(new GPoint(-77.81198120,34.82617569),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Chinquapin Elementary School",'Chinquapin=' + Chinquapin.length); Kenansville[Kenansville.length] = createMarker(new GPoint(-77.94979858,34.97370148),"",iconBl); mySelect.options[mySelect.options.length] = new Option("E E Smith Middle School",'Kenansville=' + Kenansville.length); Beulaville[Beulaville.length] = createMarker(new GPoint(-77.76090240,34.92660141),"",iconGr); mySelect.options[mySelect.options.length] = new Option("East Duplin High School",'Beulaville=' + Beulaville.length); Warsaw[Warsaw.length] = createMarker(new GPoint(-78.09149170,34.99937057),"",iconGr); mySelect.options[mySelect.options.length] = new Option("James Kenan High School",'Warsaw=' + Warsaw.length); Kenansville[Kenansville.length] = createMarker(new GPoint(-77.94979858,34.97370148),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Kenansville Elementary School",'Kenansville=' + Kenansville.length); Calypso[Calypso.length] = createMarker(new GPoint(-78.10520172,35.15430069),"",iconRd); mySelect.options[mySelect.options.length] = new Option("North Duplin Elementary School",'Calypso=' + Calypso.length); Calypso[Calypso.length] = createMarker(new GPoint(-78.10520172,35.15430069),"",iconGr); mySelect.options[mySelect.options.length] = new Option("North Duplin Junior Senior High School",'Calypso=' + Calypso.length); Rose_Hill[Rose_Hill.length] = createMarker(new GPoint(-78.03209686,34.82450104),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Rose Hill-magnolia Elementary School",'Rose_Hill=' + Rose_Hill.length); Wallace[Wallace.length] = createMarker(new GPoint(-77.99445343,34.73524857),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Wallace Elementary School",'Wallace=' + Wallace.length); Teachey[Teachey.length] = createMarker(new GPoint(-77.99883270,34.77063751),"",iconGr); mySelect.options[mySelect.options.length] = new Option("Wallace-rose Hill High School",'Teachey=' + Teachey.length); Warsaw[Warsaw.length] = createMarker(new GPoint(-78.07611847,34.99617767),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Warsaw Elementary School",'Warsaw=' + Warsaw.length); Warsaw[Warsaw.length] = createMarker(new GPoint(-78.09149170,34.99937057),"",iconBl); mySelect.options[mySelect.options.length] = new Option("Warsaw Middle School",'Warsaw=' + Warsaw.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(Albertson); map.removeOverlays(Beulaville); map.removeOverlays(Calypso); map.removeOverlays(Chinquapin); map.removeOverlays(Kenansville); map.removeOverlays(Rose_Hill); map.removeOverlays(Teachey); map.removeOverlays(Wallace); map.removeOverlays(Warsaw); 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(Albertson);map.removeOverlays(Albertson); map.removeOverlays(Beulaville); map.removeOverlays(Calypso); map.removeOverlays(Chinquapin); map.removeOverlays(Kenansville); map.removeOverlays(Rose_Hill); map.removeOverlays(Teachey); map.removeOverlays(Wallace); map.removeOverlays(Warsaw); map.addOverlays(Albertson); centerByArray(Albertson, false, false); cntMarker += Albertson.length; map.addOverlays(Beulaville); centerByArray(Beulaville, false, false); cntMarker += Beulaville.length; map.addOverlays(Calypso); centerByArray(Calypso, false, false); cntMarker += Calypso.length; map.addOverlays(Chinquapin); centerByArray(Chinquapin, false, false); cntMarker += Chinquapin.length; map.addOverlays(Kenansville); centerByArray(Kenansville, false, false); cntMarker += Kenansville.length; map.addOverlays(Rose_Hill); centerByArray(Rose_Hill, false, false); cntMarker += Rose_Hill.length; map.addOverlays(Teachey); centerByArray(Teachey, false, false); cntMarker += Teachey.length; map.addOverlays(Wallace); centerByArray(Wallace, false, false); cntMarker += Wallace.length; map.addOverlays(Warsaw); centerByArray(Warsaw, false, false); cntMarker += Warsaw.length; centerByArray(Albertson,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'); } }