function addMarkers() { mySelect = document.getElementById('selection'); Sangerville = [];Brownville = [];Cambridge = [];Parkman = [];Charleston = [];Greenville = [];Guilford = [];Milo = [];Monson = [];Dover_foxcroft = [];Shirley_Mills = [];Wellington = [];mySelect.options[mySelect.options.length] = new Option("Brownville schools",'all=Brownville'); mySelect.options[mySelect.options.length] = new Option("Cambridge schools",'all=Cambridge'); mySelect.options[mySelect.options.length] = new Option("Charleston schools",'all=Charleston'); mySelect.options[mySelect.options.length] = new Option("Dover foxcroft schools",'all=Dover_foxcroft'); mySelect.options[mySelect.options.length] = new Option("Greenville schools",'all=Greenville'); mySelect.options[mySelect.options.length] = new Option("Guilford schools",'all=Guilford'); mySelect.options[mySelect.options.length] = new Option("Milo schools",'all=Milo'); mySelect.options[mySelect.options.length] = new Option("Monson schools",'all=Monson'); mySelect.options[mySelect.options.length] = new Option("Parkman schools",'all=Parkman'); mySelect.options[mySelect.options.length] = new Option("Sangerville schools",'all=Sangerville'); mySelect.options[mySelect.options.length] = new Option("Shirley Mills schools",'all=Shirley_Mills'); mySelect.options[mySelect.options.length] = new Option("Wellington schools",'all=Wellington'); mySelect.options[mySelect.options.length] = new Option("---------------------------",''); Sangerville[Sangerville.length] = createMarker(new GPoint(-69.32099915,45.13430023),"
",iconRd); mySelect.options[mySelect.options.length] = new Option("Abbie Fowler School",'Sangerville=' + Sangerville.length); Brownville[Brownville.length] = createMarker(new GPoint(-69.04254913,45.32421494),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Brownville Elementary School",'Brownville=' + Brownville.length); Cambridge[Cambridge.length] = createMarker(new GPoint(-69.44979858,45.04040146),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Cambridge Elementary School",'Cambridge=' + Cambridge.length); Parkman[Parkman.length] = createMarker(new GPoint(-69.39389801,45.17679977),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Carroll L Mckusick School",'Parkman=' + Parkman.length); Charleston[Charleston.length] = createMarker(new GPoint(-69.05354309,45.08383942),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Charleston Elementary School",'Charleston=' + Charleston.length); Greenville[Greenville.length] = createMarker(new GPoint(-69.60025787,45.45949936),"",iconGr); mySelect.options[mySelect.options.length] = new Option("Greenville Middle/high School",'Greenville=' + Greenville.length); Guilford[Guilford.length] = createMarker(new GPoint(-69.40075684,45.17136765),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Guilford Primary School",'Guilford=' + Guilford.length); Milo[Milo.length] = createMarker(new GPoint(-68.97996521,45.25165558),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Milo Elementary School",'Milo=' + Milo.length); Monson[Monson.length] = createMarker(new GPoint(-69.50373077,45.28926468),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Monson Elementary School",'Monson=' + Monson.length); Dover_foxcroft[Dover_foxcroft.length] = createMarker(new GPoint(-69.22887421,45.19018173),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Morton Avenue Elementary School",'Dover_foxcroft=' + Dover_foxcroft.length); Greenville[Greenville.length] = createMarker(new GPoint(-69.60025787,45.45949936),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Nickerson Elementary School",'Greenville=' + Greenville.length); Milo[Milo.length] = createMarker(new GPoint(-68.99539948,45.25183868),"",iconGr); mySelect.options[mySelect.options.length] = new Option("Penquis Valley High School",'Milo=' + Milo.length); Milo[Milo.length] = createMarker(new GPoint(-68.99539948,45.25183868),"",iconBl); mySelect.options[mySelect.options.length] = new Option("Penquis Valley Middle School",'Milo=' + Milo.length); Guilford[Guilford.length] = createMarker(new GPoint(-69.37940216,45.16749954),"",iconGr); mySelect.options[mySelect.options.length] = new Option("Piscataquis Community High School",'Guilford=' + Guilford.length); Guilford[Guilford.length] = createMarker(new GPoint(-69.40679932,45.15489960),"",iconBl); mySelect.options[mySelect.options.length] = new Option("Piscataquis Community Middle School",'Guilford=' + Guilford.length); Dover_foxcroft[Dover_foxcroft.length] = createMarker(new GPoint(-69.22785950,45.19197464),"",iconBl); mySelect.options[mySelect.options.length] = new Option("Se Do Mo Cha Middle School",'Dover_foxcroft=' + Dover_foxcroft.length); Shirley_Mills[Shirley_Mills.length] = createMarker(new GPoint(-69.63369751,45.35319901),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Shirley Elementary School",'Shirley_Mills=' + Shirley_Mills.length); Wellington[Wellington.length] = createMarker(new GPoint(-69.62636566,45.03456497),"",iconRd); mySelect.options[mySelect.options.length] = new Option("Wellington Elementary School",'Wellington=' + Wellington.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(Brownville); map.removeOverlays(Cambridge); map.removeOverlays(Charleston); map.removeOverlays(Dover_foxcroft); map.removeOverlays(Greenville); map.removeOverlays(Guilford); map.removeOverlays(Milo); map.removeOverlays(Monson); map.removeOverlays(Parkman); map.removeOverlays(Sangerville); map.removeOverlays(Shirley_Mills); map.removeOverlays(Wellington); 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(Sangerville);map.removeOverlays(Brownville); map.removeOverlays(Cambridge); map.removeOverlays(Charleston); map.removeOverlays(Dover_foxcroft); map.removeOverlays(Greenville); map.removeOverlays(Guilford); map.removeOverlays(Milo); map.removeOverlays(Monson); map.removeOverlays(Parkman); map.removeOverlays(Sangerville); map.removeOverlays(Shirley_Mills); map.removeOverlays(Wellington); map.addOverlays(Brownville); centerByArray(Brownville, false, false); cntMarker += Brownville.length; map.addOverlays(Cambridge); centerByArray(Cambridge, false, false); cntMarker += Cambridge.length; map.addOverlays(Charleston); centerByArray(Charleston, false, false); cntMarker += Charleston.length; map.addOverlays(Dover_foxcroft); centerByArray(Dover_foxcroft, false, false); cntMarker += Dover_foxcroft.length; map.addOverlays(Greenville); centerByArray(Greenville, false, false); cntMarker += Greenville.length; map.addOverlays(Guilford); centerByArray(Guilford, false, false); cntMarker += Guilford.length; map.addOverlays(Milo); centerByArray(Milo, false, false); cntMarker += Milo.length; map.addOverlays(Monson); centerByArray(Monson, false, false); cntMarker += Monson.length; map.addOverlays(Parkman); centerByArray(Parkman, false, false); cntMarker += Parkman.length; map.addOverlays(Sangerville); centerByArray(Sangerville, false, false); cntMarker += Sangerville.length; map.addOverlays(Shirley_Mills); centerByArray(Shirley_Mills, false, false); cntMarker += Shirley_Mills.length; map.addOverlays(Wellington); centerByArray(Wellington, false, false); cntMarker += Wellington.length; centerByArray(Sangerville,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'); } }