function addMarkers() { mySelect = document.getElementById('selection'); Biscoe = [];Candor = [];Mount_Gilead = [];Troy = [];Star = [];mySelect.options[mySelect.options.length] = new Option("Biscoe schools",'all=Biscoe'); mySelect.options[mySelect.options.length] = new Option("Candor schools",'all=Candor'); mySelect.options[mySelect.options.length] = new Option("Mount Gilead schools",'all=Mount_Gilead'); mySelect.options[mySelect.options.length] = new Option("Star schools",'all=Star'); mySelect.options[mySelect.options.length] = new Option("Troy schools",'all=Troy'); mySelect.options[mySelect.options.length] = new Option("---------------------------",''); Biscoe[Biscoe.length] = createMarker(new GPoint(-79.76679993,35.34420013),"
",iconGr); mySelect.options[mySelect.options.length] = new Option("Anchor School",'Biscoe=' + Biscoe.length); Candor[Candor.length] = createMarker(new GPoint(-79.74576569,35.29050064),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Candor Elementary School",'Candor=' + Candor.length); Biscoe[Biscoe.length] = createMarker(new GPoint(-79.77938400,35.35979500),"",iconBl); mySelect.options[mySelect.options.length] = new Option("East Middle School",'Biscoe=' + Biscoe.length); Biscoe[Biscoe.length] = createMarker(new GPoint(-79.79299927,35.35620117),"",iconGr); mySelect.options[mySelect.options.length] = new Option("East Montgomery High School",'Biscoe=' + Biscoe.length); Mount_Gilead[Mount_Gilead.length] = createMarker(new GPoint(-80.00659943,35.22679901),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Mount Gilead Elementary School",'Mount_Gilead=' + Mount_Gilead.length); Troy[Troy.length] = createMarker(new GPoint(-79.87677765,35.36650085),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Page Street Elementary School",'Troy=' + Troy.length); Star[Star.length] = createMarker(new GPoint(-79.78403473,35.39774323),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Star-biscoe Elementary School",'Star=' + Star.length); Troy[Troy.length] = createMarker(new GPoint(-79.89109039,35.36214447),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Troy Elementary School",'Troy=' + Troy.length); Mount_Gilead[Mount_Gilead.length] = createMarker(new GPoint(-80.00272369,35.21466827),"",iconBl); mySelect.options[mySelect.options.length] = new Option("West Middle School",'Mount_Gilead=' + Mount_Gilead.length); Mount_Gilead[Mount_Gilead.length] = createMarker(new GPoint(-79.96105957,35.29649353),"",iconGr); mySelect.options[mySelect.options.length] = new Option("West Montgomery High School",'Mount_Gilead=' + Mount_Gilead.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(Biscoe); map.removeOverlays(Candor); map.removeOverlays(Mount_Gilead); map.removeOverlays(Star); map.removeOverlays(Troy); 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(Biscoe);map.removeOverlays(Biscoe); map.removeOverlays(Candor); map.removeOverlays(Mount_Gilead); map.removeOverlays(Star); map.removeOverlays(Troy); map.addOverlays(Biscoe); centerByArray(Biscoe, false, false); cntMarker += Biscoe.length; map.addOverlays(Candor); centerByArray(Candor, false, false); cntMarker += Candor.length; map.addOverlays(Mount_Gilead); centerByArray(Mount_Gilead, false, false); cntMarker += Mount_Gilead.length; map.addOverlays(Star); centerByArray(Star, false, false); cntMarker += Star.length; map.addOverlays(Troy); centerByArray(Troy, false, false); cntMarker += Troy.length; centerByArray(Biscoe,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'); } }