LE SEDI

Trova la struttura più vicina

${loc.name}

${loc.address}
${phonesHTML}
`;} function buildList(){ const list=document.getElementById('list'); list.innerHTML=''; LOCATIONS.forEach((l,i)=>{const c=el(cardTemplate(l,i)); c.addEventListener('click',()=>focusMarker(i)); c.addEventListener('keypress',e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault(); focusMarker(i);}}); list.appendChild(c); }); } function focusMarker(i){ const m=state.markers[i]; if(!m) return; state.map.panTo(m.getPosition()); state.map.setZoom(Math.max(state.map.getZoom(),16)); google.maps.event.trigger(m,'click'); } function setMarker(loc,latLng,i){ const marker=new google.maps.Marker({position:latLng,map:state.map,icon:{url:ICON_SVG,scaledSize:new google.maps.Size(28,28),anchor:new google.maps.Point(14,28)},title:loc.name}); marker.addListener('click',()=>{ state.infowin.setContent(`
${loc.name}
${loc.address}
Indicazioni ›
`); state.infowin.open(state.map,marker); }); state.markers[i]=marker; if(i===0 && !state.firstCentered){ state.map.setCenter(latLng); state.map.setZoom(16); state.firstCentered=true; } } function geocodeAll(){ const cacheKey='geo_cache_medcenter_v1'; let cache={}; try{cache=JSON.parse(localStorage.getItem(cacheKey)||'{}')}catch(e){} LOCATIONS.forEach((loc,i)=>{ const cached=cache[loc.address]; if(cached){ const g=new google.maps.LatLng(cached.lat,cached.lng); setMarker(loc,g,i); }else{ setTimeout(()=>{ state.geocoder.geocode({address:loc.address},(res,status)=>{ if(status==='OK' && res[0]){ const g=res[0].geometry.location; cache[loc.address]={lat:g.lat(),lng:g.lng()}; localStorage.setItem(cacheKey,JSON.stringify(cache)); setMarker(loc,g,i); } }); }, i*150); } }); } window.initMap=function(){ state.map=new google.maps.Map(document.getElementById('map'),{ center:{lat:40.93,lng:14.15}, zoom:16, gestureHandling:'greedy', // rotellina + pinch scrollwheel:true, // rotellina abilitata mapTypeControl:false, streetViewControl:false, styles:[{"featureType":"poi","stylers":[{"visibility":"off"}]},{"featureType":"transit","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"water","stylers":[{"saturation":-10}]},{"featureType":"road","stylers":[{"saturation":-20}]},{"featureType":"administrative.locality","stylers":[{"visibility":"simplified"}]}] }); state.infowin=new google.maps.InfoWindow(); state.geocoder=new google.maps.Geocoder(); buildList(); geocodeAll(); }; })();