var mapimage = "includes/imgs/gmap.png"; var ajaxurl = "includes/ajax/ajax_serve.php"; // url of the ajax server var iconpath = "includes/imgs/icon/"; // url of icon folder (most found at http://labs.google.com/ridefinder/images/ var thumbnailurl = "thumbnail.php"; // url of thumbnail.php file var homeurl = "index.php"; // path of the main map site var map = null; // google map object var timeoutholder = null; // timeouts - wait between keypresses var timeoutholder2 = null; //timeouts - wait between clicks var infoWindows = []; // array to hold the contents of the markers var gmarkers = []; // array to hold markers var groundOverlay = null; // holds image that is overlayed over the tiles function onLoad() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); var pointCenter = new GLatLng(32.2829422129357, -106.747756004334); map.setCenter(pointCenter, 17, G_NORMAL_MAP); /* var pointSW = new GLatLng(32.269925, -106.762181); var pointNE = new GLatLng(32.286226, -106.737478); */ var pointSW = new GLatLng(32.269825, -106.762015); var pointNE = new GLatLng(32.28618, -106.737542); var mapBounds = new GLatLngBounds(pointSW, pointNE); groundOverlay = new GGroundOverlay(mapimage, mapBounds); map.addOverlay(groundOverlay); // To improve performance for panning, we want to hide the NMSU image and then show it again when we stop. GEvent.addListener(map,"dragstart", function(){layerToggle(false)}); GEvent.addListener(map,"movestart", function(){layerToggle(false)}); GEvent.addListener(map,"zoomstart", function(){layerToggle(false)}); GEvent.addListener(map,"dragend", function(){layerToggle(true)}); GEvent.addListener(map,"moveend", function(){layerToggle(true)}); GEvent.addListener(map,"zoomend", function(){layerToggle(true)}); map.addControl(new GMapTypeControl()); map.addControl(new GSmallMapControl()); // add additional zoom options map.enableDoubleClickZoom(); map.enableContinuousZoom(); map.enableScrollWheelZoom(); // add listener for when user clicks the map GEvent.addListener(map, 'click', setMarker); } else document.getElementById("map").innerHTML = "We are sorry, but your browser is not compatible with NMSU maps."; } // Shows/hides the NMSU map image when panning is involved. function layerToggle(show) { if (show == true) groundOverlay.show(); else groundOverlay.hide(); } function setMarker(overlay, point) { if (overlay == null) { var lat = point.lat(); var lng = point.lng(); var overlays = getOverlays(); for (var i in overlays) { if (overlays[i].type == 'click') { removeMarker(overlays[i]); break; } } var cm = new createMarker('click0', 'click', lat, lng, "mm_20_orange.png"); cm.writeMarker(); document.getElementById("coords").value = lat + ", " + lng; } } // add a marker to the map function createMarker(id, type, lat, lng, iconurl) { this.id = id; this.type = type; this.lat = lat; this.lng = lng; this.iconurl = iconurl; var point = new GLatLng(this.lat, this.lng); var icon = new GIcon(); if (this.iconurl != "") icon.image = iconpath + this.iconurl; else icon.image = iconpath + "mm_20_red.png"; icon.shadow = iconpath + "mm_20_shadow.png"; // icon.iconSize = new GSize(12, 20); icon.shadowSize = new GSize(22, 20); icon.iconAnchor = new GPoint(6, 20); var marker = new GMarker(point, icon); this.writeMarker = function() { var index = this.id; marker.type = this.type; // classes, build, perma, etc marker.id = index; // build0, bulid1, etc map.addOverlay(marker); gmarkers[index] = marker; }; } // remove marker from the map function removeMarker(overlay) { gmarkers[overlay.id] = ''; // BUGBUG: using null totally breaks the app, no idea why GEvent.clearListeners(overlay, "click"); map.removeOverlay(overlay); } // return all markers on the map function getOverlays() { return gmarkers; } // Try to free up some memory when the page exits function onUnload() { var overlays = getOverlays(); for (var i in overlays) removeMarker(overlays[i]); GUnload(); }