var map; var district = null; var events = new Array(); var removed = new Array(); //$(window).scroll(function(){ $('#th-map-container').css('top',$(window).scrollTop()); }); google.load('search', '1', { language: 'it' }); google.setOnLoadCallback(function () { var customSearchControl = new google.search.CustomSearchControl('016018451320600003173:geqiec8sile'); customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); customSearchControl.setSearchCompleteCallback(this, function () { searchComplete(null); $('#th-map-filter').css('display','none'); filterDistrict(null); removed = new Array(); }, null); customSearchControl.setNoResultsString("Nessun risultato trovato.") customSearchControl.draw('th-cse'); }, true); function filterDistrict(object) { var d = $(".districts"); for (var i = 0; i < d.length; i++) d[i].style.fontWeight = 'normal'; if (object != null){ object.style.fontWeight = 'bold'; district = object.id;}else district = null; } // FIXED FOR IE ISSUE (NOT EXIST) function getElementsByMultipleClass(searchClass, node, tag) { if (document.getElementsByMultipleClassName) { if (node == null) return document.getElementsByMultipleClassName(searchClass); else return node.getElementsByMultipleClassName(searchClass); } else { var classElements = new Array(); if (node == null) node = document; if (tag == null) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if (pattern.test(els[i].className)) { classElements[j] = els[i]; j++; } } return classElements; } } function TicinoHelpMotionMap(object) { document.getElementById('th-map-container').style.display = 'none'; //qui modificato inline document.getElementById('th-news').style.display = 'inline'; // per togliere i box dalla pagina dei risultati document.getElementById('info').style.display = 'none'; // per togliere i box dalla pagina dei risultati document.getElementById('sponsor').style.display = 'block'; if (object == null || object.src.indexOf('left') != -1) { document.getElementById('th-body-right').style.display = 'inline'; document.getElementById('th-map-tab').src = './images/map_right.jpg'; $("#th-map-container").animate({ right: "-20px" }, 1000, function () { document.getElementById('th-container').style.overflow = 'visible'; document.getElementById('th-body-left').style.width = '75%'; }); } else { document.getElementById('th-map-tab').src = './images/map_left.jpg'; document.getElementById('th-container').style.overflow = 'hidden'; $("#th-map-container").animate({ right: "-370px" }, 500); document.getElementById('th-body-left').style.width = '78%'; } } function searchComplete(district) { TicinoHelpMotionMap(null); document.getElementById('th-district').style.display = 'inline'; var list, list_url_short, index, sites, sites_url, search; search = document.getElementsByTagName("iframe")[0].src; search = search.substr(search.indexOf('q=') + 2, (search.indexOf('&') - search.indexOf('q=')) - 2); list_url_short = getElementsByMultipleClass("gs-visibleUrl gs-visibleUrl-short", getElementsByMultipleClass("gsc-resultsRoot gsc-tabData gsc-tabdActive")[0]); if (list_url_short == null) list_url_short = getElementsByMultipleClass("gs-visibleUrl gs-visibleUrl-short", results); list = getElementsByMultipleClass("gs-visibleUrl gs-visibleUrl-long", getElementsByMultipleClass("gsc-resultsRoot gsc-tabData gsc-tabdActive")[0]); if (list == null) list = getElementsByMultipleClass("gs-visibleUrl gs-visibleUrl-long", results); sites = ''; sites_url = ''; for (index = 0; index < list.length; ++index) { if (list[index].innerHTML) { sites += list[index].innerHTML + ','; sites_url += list_url_short[index].innerHTML + ','; } } $.get("./geoviz_request.php", { request: "results", sites: sites, sites_url: sites_url, search: search, district: district }, function (data) { initialize(data, district); }); } function initialize(data, district) { var mapDiv = document.getElementById('th-map'); map = new google.maps.Map(mapDiv, { mapTypeId: google.maps.MapTypeId.ROADMAP }); var districts = new Array("bellinzona", "blenio", "leventina", "locarno", "lugano", "mendrisio", "riviera", "vallemaggia"); for (var i = 0; i < 8; i++) { if (district == null || district == districts[i]) { var ctaLayer = new google.maps.KmlLayer('' + districts[i] + '_district.kml', { suppressInfoWindows: true }); ctaLayer.setMap(map); } } google.maps.event.addListenerOnce(map, 'tilesloaded', function () { var lat, lng, ind, url, lbl, label, color, list, index, tab, icon; var bounds = map.getBounds(); var results = new Array(); var inactive = new Array(); var labels = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J"); var tabs = new Array(); var colors = new Array(); var latlng = new Array(); // INIT TABS LABEL tabs["ambiente"] = "darkgrey"; tabs["sport_e_tempo_libero"] = "feedstergreen"; tabs["aziende"] = "pink"; tabs["pubblica_amministrazione"] = "brown"; tabs["scuola_ed_educazione"] = "purple"; tabs["associazioni"] = "yellow"; tabs["eventi_e_spettacoli"] = "paleblue"; tabs["turismo_e_trasporti"] = "green"; tabs["enogastronomia"] = "blue"; tabs["salute"] = "darkgreen"; tabs["cultura_e_religione"] = "orange"; tabs["news_e_informazione"] = "grey"; tabs["ticinohelp"] = "red"; // INIT COLORS colors["ambiente"] = "#7f7f7f"; colors["sport_e_tempo_libero"] = "#98cd00"; colors["aziende"] = "#fdabff"; colors["pubblica_amministrazione"] = "#cb9d7c"; colors["scuola_ed_educazione"] = "#c89bff"; colors["associazioni"] = "#ffed5c"; colors["eventi_e_spettacoli"] = "#bce3ff"; colors["turismo_e_trasporti"] = "#97ec7d"; colors["enogastronomia"] = "#6b98ff"; colors["salute"] = "#01bf00"; colors["cultura_e_religione"] = "#fd8d08"; colors["news_e_informazione"] = "#dadeea"; colors["ticinohelp"] = "#ff776b"; list = getElementsByMultipleClass("gs-visibleUrl gs-visibleUrl-short", getElementsByMultipleClass("gsc-resultsRoot gsc-tabData gsc-tabdActive")[0]); if (list == null) list = getElementsByMultipleClass("gs-visibleUrl gs-visibleUrl-short", results); // REMOVE OLD MARKER icon = $(".th-marker"); for (var i in icon) { if(typeof icon[i] == 'object'){ if(icon[i].parentNode) icon[i].parentNode.removeChild(icon[i]); } } // CLEAR BORDER COLOR inactive = getElementsByMultipleClass("gsc-tabHeader gsc-tabhInactive"); for (var i in inactive) { if (inactive[i].style) { inactive[i].style.borderTop = '0'; } } tab = getElementsByMultipleClass("gsc-tabHeader gsc-tabhActive")[0].innerHTML.replace(/ /g, '_').toLowerCase(); // ADD EVENT FOR TAB RELOAD PROBLEM if (events[tab] == null) { $(getElementsByMultipleClass("gsc-tabHeader gsc-tabhActive")[0]).click( function () { searchComplete(district); document.getElementById('th-map-filter').style.display = 'none'; filterDistrict(null); removed = new Array(); }); events[tab] = true; } // CHANGE BORDER COLOR getElementsByMultipleClass("gsc-tabHeader gsc-tabhActive")[0].style.borderTop = 'solid ' + colors[tab] + ' 2px'; results = data.split('|EOL|'); for (i = 0; i < (results.length) - 1; i++) { var results_data = new Array(); results_data = results[i].split('|'); ind = results_data[0]; lat = results_data[1]; lng = results_data[2]; url = results_data[3]; lbl = results_data[4]; if (ind == "") continue; for (index = 0; index < list.length; ++index) { if (lbl!=label && list[index].parentNode.lastChild.children[0]==null) { if (url != null && labels[index] == lbl) { var newdiv = document.createElement('div'); $(newdiv).addClass('th-marker'); var img = new Image(); img.setAttribute('src','./images/markers/'+tabs[tab]+'_Marker'+lbl+'.png'); img.setAttribute('id','gevent-'+lbl); img.setAttribute('alt',url); img.setAttribute('title',url); eval('img.onclick = function(){ '+lbl+'(); }'); if(removed[lbl]==true) $(img).addClass('transparency'); newdiv.appendChild(img); var img2 = new Image(); if(removed[lbl]==true) img2.setAttribute('src','./images/add.gif'); else img2.setAttribute('src','./images/remove.gif'); img2.setAttribute('id',lbl); img2.setAttribute('alt',url); img2.setAttribute('title',url); img2.onclick = function(){if(this.src.indexOf('remove')!=-1) removed[this.id] = true; else removed[this.id] = false; searchComplete(district);}; newdiv.appendChild(img2); list[index].parentNode.appendChild(newdiv); label = lbl; break; } } } if(removed[label]==true) continue; latlng.push(new google.maps.LatLng(lat, lng)); var location = new google.maps.LatLng(lat, lng); var image = './images/markers/'+tabs[tab]+'_Marker'+label+'.png'; var marker = new google.maps.Marker({ position: location, map: map, icon: image }); attachInfo(marker, lbl, ind.replace(/\\/g, '')); } var latlngbounds = new google.maps.LatLngBounds(); for (var i = 0; i < latlng.length; i++) { latlngbounds.extend(latlng[i]); } if (latlng.length == 0) { latlngbounds.extend(new google.maps.LatLng(45.9, 9.1)); latlngbounds.extend(new google.maps.LatLng(46.5, 8.5)); } // CENTERING MAP map.setCenter(latlngbounds.getCenter()); if (latlng.length != 1) { map.fitBounds(latlngbounds); } }); } function attachInfo(marker, label, text) { var infowindow = new google.maps.InfoWindow({ content: text, disableAutoPan: false }); google.maps.event.addDomListener(document.getElementById('gevent-'+label), 'mouseover', function() { infowindow.open(map, marker); }); google.maps.event.addDomListener(document.getElementById('gevent-'+label), 'mouseout', function() { infowindow.close(map, marker); }); google.maps.event.addListener(marker, 'mouseover', function () { infowindow.open(map, marker); }); google.maps.event.addListener(marker, 'mouseout', function () { infowindow.close(map, marker); }); }