var map; var geocoder; var jahecarregat; var hanPassatUid; function load() { MM_preloadImages('http://labs.google.com/ridefinder/images/mm_20_shadow.png','http://labs.google.com/ridefinder/images/mm_20_green.png','http://labs.google.com/ridefinder/images/mm_20_red.png'); map = new GMap2(document.getElementById("map")); GEvent.addListener(map, "dragend", function() { carregaPois(document.geoposiciona.category[document.geoposiciona.category.selectedIndex].value); }); GEvent.addListener(map, "zoomend", function() { carregaPois(document.geoposiciona.category[document.geoposiciona.category.selectedIndex].value); // recarregaBanners(); }); map.setCenter(new GLatLng(41.610043,2.290830), 17); geocoder = new GClientGeocoder(); // Afegeixo els botons map.addControl(new GLargeMapControl ()); map.addControl(new GMapTypeControl()); carregaPois(document.geoposiciona.category[document.geoposiciona.category.selectedIndex].value); if (hanPassatUid == 1){mostraUid(nomempresa, desc_empresa, telefon, adreca, nompoblacio, barri, x, y);} } function recarregaBanners(){ if (jahecarregat == 1){ document.getElementById("bannerdalt").src = document.getElementById("bannerdalt").src; document.getElementById("bannerdreta1").src = document.getElementById("bannerdreta1").src; document.getElementById("bannerdreta2").src = document.getElementById("bannerdreta2").src; document.getElementById("bannerdreta3").src = document.getElementById("bannerdreta3").src; document.getElementById("bannerdreta4").src = document.getElementById("bannerdreta4").src; } jahecarregat = 1; } // addAddressToMap() is called when the geocoder returns an // answer. It adds a marker to the map with an open info window // showing the nicely formatted version of the address and the country code. function addAddressToMap(response) { carregaPois(document.geoposiciona.category[document.geoposiciona.category.selectedIndex].value); if (!response || response.Status.code != 200) { alert("Ho sento, no he trobat l'adreça " + document.geoposiciona.q.value + ". Prova-ho de nou."); } else { place = response.Placemark[0]; point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); var comunitat = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName; var provincia = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName; var poblacio = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName; var adreca = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName; var cp = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber; var geoxy = place.Point.coordinates; var puntet=new GIcon(); puntet.shadow="http://labs.google.com/ridefinder/images/mm_20_shadow.png"; puntet.iconSize=new GSize(12,20); puntet.shadowSize=new GSize(22,20); puntet.iconAnchor=new GPoint(6,20); puntet.infoWindowAnchor=new GPoint(6,1); puntet.infoShadowAnchor=new GPoint(13,13); puntet.image = "http://labs.google.com/ridefinder/images/mm_20_green.png"; var puntet_verd = new GIcon(puntet); marker = new GMarker(point, puntet_verd); map.addOverlay(marker); marker.openInfoWindowHtml('Hem trobat aquí:
' + adreca + '
' + cp + ', ' + poblacio + '
' + provincia + '
Latitud/Longitud:
' + geoxy); } } function mostraUid(nomempresa, desc_empresa, telefon, adreca, nompoblacio, barri, x, y){ carregaPois(document.geoposiciona.category[document.geoposiciona.category.selectedIndex].value); point = new GLatLng(y,x); document.geoposiciona.q.value = adreca + ", " + nompoblacio + ", Barcelona"; /* var comunitat = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName; var provincia = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName; var poblacio = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName; var adreca = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName; var cp = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber; var geoxy = place.Point.coordinates; */ var puntet=new GIcon(); puntet.shadow="http://labs.google.com/ridefinder/images/mm_20_shadow.png"; puntet.iconSize=new GSize(12,20); puntet.shadowSize=new GSize(22,20); puntet.iconAnchor=new GPoint(6,20); puntet.infoWindowAnchor=new GPoint(6,1); puntet.infoShadowAnchor=new GPoint(13,13); puntet.image = "http://labs.google.com/ridefinder/images/mm_20_red.png"; var puntet_vermell = new GIcon(puntet); marker = new GMarker(point, puntet_vermell); if (telefon == ""){telefon="n/a";} map.addOverlay(marker); marker.openInfoWindowHtml("
"+ nomempresa + "
" + desc_empresa + "
Tel: " + telefon + "
" + adreca + "
" + nompoblacio + " (" + barri + ")
"); } // showLocation() is called when you click on the Search button // in the form. It geocodes the address entered into the form // and adds a marker to the map at that location. function showLocation() { // recarregaBanners(); var address = document.geoposiciona.q.value; map.clearOverlays(); geocoder.getLocations(address, addAddressToMap); } // findLocation() is used to enter the sample addresses into the form. function findLocation(address) { document.geoposiciona.q.value = address; showLocation(); } function carregaPois(category){ map.clearOverlays(); var bounds = map.getBounds(); var zoomLevel = map.getZoom(); var bottom_down = bounds.getSouthWest(); var top_right = bounds.getNorthEast(); GDownloadUrl("/mapa/mostra_punts.php?bottom_down=" + bottom_down + "&top_right=" + top_right + "&category=" + category + "&zoom=" + zoomLevel, function(data) { var xml = GXml.parse(data); var markers = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng"))); var logoample = markers[i].getAttribute("logoample"); var logoalt = markers[i].getAttribute("logoalt"); var uid = markers[i].getAttribute("uid"); map.addOverlay(createMarker(point, uid, logoample, logoalt)); } }); } function createMarker(point, uid, logoample, logoalt) { var sitefoto; if (logoample != ""){ var baseIcon = new GIcon(); baseIcon.iconSize = new GSize(logoample,logoalt); baseIcon.iconAnchor = new GPoint(9, 34); baseIcon.infoWindowAnchor = new GPoint(9, 2); baseIcon.infoShadowAnchor = new GPoint(18, 25); var icon = new GIcon(baseIcon); icon.image = "http://www.badaweb.com/logos/mapa/" + uid + ".png"; var marker = new GMarker(point, icon); } else { var puntet=new GIcon(); puntet.shadow="http://labs.google.com/ridefinder/images/mm_20_shadow.png"; puntet.iconSize=new GSize(12,20); puntet.shadowSize=new GSize(22,20); puntet.iconAnchor=new GPoint(6,20); puntet.infoWindowAnchor=new GPoint(6,1); puntet.infoShadowAnchor=new GPoint(13,13); puntet.image = "http://labs.google.com/ridefinder/images/mm_20_red.png"; var puntet_vermell = new GIcon(puntet); var marker = new GMarker(point, puntet_vermell); } GEvent.addListener(marker, "click", function() { GDownloadUrl("/mapa/mostra_detall.php?uid=" + uid, function(data_detall) { var xml = GXml.parse(data_detall); var markers = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { var nomempresa = markers[i].getAttribute("nomempresa"); var adreca = markers[i].getAttribute("adreca"); var nompoblacio = markers[i].getAttribute("nompoblacio"); var desc_empresa = markers[i].getAttribute("desc_empresa"); var url = markers[i].getAttribute("url"); var telefon = markers[i].getAttribute("telefon"); var barri = markers[i].getAttribute("barri"); if (barri != ""){barri = " (" + barri + ")";} else {barri = "";} var foto = markers[i].getAttribute("foto"); var foto_ample = markers[i].getAttribute("foto_ample"); var foto_alt = markers[i].getAttribute("foto_alt"); if (foto != ""){sitefoto = "";} else{sitefoto = "";} if (url != ""){ var nomempresa = "" + nomempresa + ""; } marker.openInfoWindowHtml("
"+ nomempresa + "
" + desc_empresa + "
Tel: " + telefon + "
" + adreca + "
" + nompoblacio + barri + "
 " + sitefoto + "
"); } }); }); return marker; }