var geocode, marker, markers= new Array(), infowindow= new google.maps.InfoWindow({AutoPan:false}), lat ="43.141078", lng ="10.107422", zoom= 7; function initialize() { var myOptions = { center: new google.maps.LatLng(lat,lng), zoom: zoom, scrollwheel:false, streetViewControl:false, panControl:false, zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL, position: google.maps.ControlPosition.RIGHT_TOP }, mapTypeId: google.maps.MapTypeId.ROADMAP }; if (document.getElementById("Gmap_hotel")!=null) { var map = new google.maps.Map(document.getElementById("Gmap_hotel"), myOptions); marcatori(map); } } function baloon(map, marker){ var html_baloon = document.getElementById("esempio_popup").innerHTML; var tpl_bal = html_baloon.replace(/(\[\$nome_scheda\])/g, marker.title); tpl_bal = tpl_bal.replace(/(\[\$nome\_tipologia\])/g, marker.categoria); tpl_bal = tpl_bal.replace(/(\[\$indirizzo\])/g, marker.indirizzo); tpl_bal = tpl_bal.replace(/(\[\$descrizione\])/g, marker.descrizione); tpl_bal = tpl_bal.replace(/(\[\$url_booking\])/g, marker.url); tpl_bal = tpl_bal.replace(/(\[\$provincia\])/g, marker.provincia); google.maps.event.addListener(marker, 'click', function() { if (!infowindow) { infowindow = new google.maps.InfoWindow(); } infowindow.setContent(tpl_bal); infowindow.open(map,this); }) } function marcatori(map){ var bounds = new google.maps.LatLngBounds(); var macro; for(var i=0; i <= myObj.length-1;i++){ if(myObj[i].recommended=="y"){ ic= "/images/pin_recommended.png"; }else{ ic= "/images/pin.png"; } if(typeof myObj[i].macrocategorie[0] != "undefined"){ macro = myObj[i].macrocategorie[0].id_macrocategoria; }else{ macro= 0; } // console.log(macro) var markStatus; if(myObj[i].recommended!="y"){ markStatus=false; }else{ markStatus=true; } marker= new google.maps.Marker({ position: new google.maps.LatLng(myObj[i].lat,myObj[i].lng), map: map, title:myObj[i].nome_scheda, categoria: myObj[i].nome_categoria, id_categoria:myObj[i].id_categoria, indirizzo: myObj[i].indirizzo, descrizione: myObj[i].descrizione, url: myObj[i].url, macrocat: macro, recommended: myObj[i].recommended, id_provincia: myObj[i].id_provincia, provincia: myObj[i].provincia, id_citta:myObj[i].id_citta, visible: markStatus, icon:ic }); markers[i]=marker; baloon(map, marker); bounds.extend(marker.position); } if( myObj.length == 1 && myObj[0].map_lat && myObj[0].map_lng && myObj[0].zoom){ map.setCenter( new google.maps.LatLng(myObj[0].map_lat, myObj[0].map_lng)); map.setZoom(parseInt(myObj[0].zoom)); } if( myObj.length > 1){ map.fitBounds(bounds); } } function marker_switch(type, check_reccomended){ //console.log(type) var i, a, setting, tipo_key, val_key, is_checked, item = new Array(), mark_cat, mark_rec, mark_macrocat, mark_citta, have_true= new Array(), have_true_macrocat, have_true_provincia, have_true_citta, have_true_reccomended, have_true_id_cat; /* abilito/disabilito i marcatori */ for (m=0; m <= markers.length-1;m++){ mark_cat =markers[m]["id_categoria"]; mark_rec =markers[m]["recommended"]; mark_prov =markers[m]["id_provincia"]; mark_citta =markers[m]["id_citta"]; mark_macrocat=markers[m]["macrocat"]; have_true_macrocat=false; have_true_id_cat=false; have_true_provincia=false; have_true_citta=false; markers[m].setVisible(false); for( i = 0; i <= type.length -1; i++ ){ if(type[i][0]["id"] == "id_categoria" && type[i][0]["checked"] == true){ // console.log(type[i][0]) if(type[i][0]["valore"]==mark_cat){ have_true_id_cat=true; } } if(type[i][0]["id"] == "id_provincia" && type[i][0]["checked"] == true){ // console.log(type[i][0]) if(type[i][0]["valore"]==mark_prov || type[i][0]["valore"] == 0){ have_true_provincia=true; } } if(type[i][0]["id"] == "id_citta" && type[i][0]["checked"] == true){ // console.log(type[i][0]) if(type[i][0]["valore"]==mark_citta || type[i][0]["valore"] == 0){ have_true_citta=true; } } if(type[i][0]["id"] == "macrocat" && type[i][0]["checked"] == true){ // console.log(type[i][0]) if(type[i][0]["valore"]==mark_macrocat || mark_macrocat==0){ have_true_macrocat=true; } } } /* */ have_true = eval(have_true_id_cat && have_true_macrocat && have_true_provincia && have_true_citta); if(check_reccomended==1){ //console.log(markers[m]["title"],"\n-----------------------------------\n") if(mark_rec=="y" && have_true == true){ // console.log(have_true) markers[m].setVisible(true) }else if(mark_rec=="y" && have_true != true){ markers[m].setVisible(false) // console.log(false) } }else{ if(have_true == true){ markers[m].setVisible(true) // console.log(true) } } } } window.onload = function(){initialize()};