var map; var mgr; var icons = {}; var clicked = false; function showLatLng(lat,lon,zoom){ zoom = zoom || 14; map.setCenter(new GLatLng(lat,lon),zoom); } function GMap_MoveEnd() { var bounds = this.getBoundsLatLng(); var numOverlays = this.overlays.length; for(var i=0; i bounds.maxX || pnt.y > bounds.maxY ) this.removeOverlay(this.overlays[i]); numOverlays = this.overlays.length; } } function getIcon(images) { var icon = null; if (images) { // alert(images); if (icons[images[0]]) { icon = icons[images[0]]; } else { icon = new GIcon(); icon.image = "icons/" + images[0] + ".png"; var size = iconData[images[0]]; icon.iconSize = new GSize(size.width, size.height); icon.iconAnchor = new GPoint(13, size.height); icon.infoWindowAnchor = new GPoint(size.width >> 1, size.height >> 1); icon.shadow = "icons/" + images[1] + ".gif"; size = iconData[images[1]]; icon.shadowSize = new GSize(size.width, size.height); icons[images[0]] = icon; } } return icon; } function createMarker(point, title, icon, html, zoom) { var marker = new GMarker(point, {title: title, icon: icon}); GEvent.addListener(marker, "click", function() { clicked = true; if (map.getZoom()

"+place["name"]+"

"+place["addr"]+"

"; if (place["icon"][0]=="Microaudio"){ text+="Audiología."; } else if (place["icon"][0]=="Microaudio-Multiopticas") { text+="Servicios Ópticos y audiología."; } else if (place["icon"][0]=="Multiopticas") { text+="Servicios Ópticos."; } text+="

"; var zoom = place["zoom"]; map.setCenter(posn, 14); map.openInfoWindowHtml(posn,text); // var marker = createMarker(posn, place["name"],icon, text, zoom); // map.addOverlay(marker); // marker.openInfoWindow(text); // alert(text); } }); }); } function setupPlaces() { map.clearOverlays(); mgr = new GMarkerManager(map); placeLayer.each( function(layer){ var markers = []; layer.places.each( function(place) { var icon = getIcon(place["icon"]); var posn = new GLatLng(place["posn"][0], place["posn"][1]); // if (map.getBounds().contains(posn)) { var text = "

"+place["name"]+"

"+place["addr"]+"

"; if (place["icon"][0]=="Microaudio"){ text+="Audiología."; } else if (place["icon"][0]=="Microaudio-Multiopticas") { text+="Servicios ópticos y audiología."; } else if (place["icon"][0]=="Multiopticas") { text+="Servicios ópticos."; } text+="

"; var zoom = place["zoom"]; var marker = createMarker(posn, place["name"],icon, text, zoom); markers.push(marker); // } }); mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]); }); mgr.refresh(); } function load() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.addControl(new GScaleControl()); map.addControl(new GOverviewMapControl()); map.setCenter(new GLatLng(39.856777,-4.024475), 5 /*, G_HYBRID_MAP*/ ); map.enableDoubleClickZoom(); map.enableContinuousZoom(); map.enableScrollWheelZoom(); // GEvent.addListener(map, "moveend", function() {if (!clicked) {window.setTimeout(setupPlaces, 0);}}); // GEvent.addListener(map, "zoomend", function() {if (!clicked){window.setTimeout(setupPlaces, 0);}}); window.setTimeout(setupPlaces, 0); geocoder = new GClientGeocoder(); } Event.observe('searchLink', 'click', function(e){ searchData(); Event.stop(e);}, false); } function showAddress(address) { if (geocoder) { geocoder.getLatLng( address, function(point) { if (!point) { alert(address + " no encontrado"); } else { act("" + point.y + "," + point.x); map.setCenter(point, 17); var marker = new GMarker(point); map.addOverlay(marker); marker.openInfoWindowHtml(address); } } ); } } function act(text){ document.getElementById("longitud").innerHTML = "[" + text + "]"; } function searchData(){ $('searchLink').blur(); var url = 'searchLocations.php'; var target = 'searchResults'; var state = escape($F("state")); // todo: check state var zipCode = escape($F("zipCode")); // todo: check zipCode var pars = 'state='+state+'&zipCode='+zipCode; var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars, evalScripts: true}); return false; } Ajax.Responders.register({ onCreate: function() { $('searching').show(); }, onComplete: function() { $('searching').hide(); $('searchResults').scrollTop=0; $('searchResults').scrollLeft=0; } }); Event.observe(window, 'load', load, false); Event.observe(window, 'unload', GUnload, false);