{"id":16188,"date":"2025-05-26T13:13:52","date_gmt":"2025-05-26T13:13:52","guid":{"rendered":"https:\/\/brunoribadi.it\/?page_id=16188"},"modified":"2025-09-09T18:51:20","modified_gmt":"2025-09-09T16:51:20","slug":"find-us","status":"publish","type":"page","link":"https:\/\/brunoribadi.it\/it\/find-us\/","title":{"rendered":"DOVE SIAMO"},"content":{"rendered":"<div data-elementor-type=\"wp-page\" data-elementor-id=\"16188\" class=\"elementor elementor-16188\" data-elementor-post-type=\"page\">\n\t\t\t\t<div class=\"wd-negative-gap elementor-element elementor-element-673d70d e-flex e-con-boxed e-con e-parent\" data-id=\"673d70d\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-81d75d6 elementor-widget elementor-widget-html\" data-id=\"81d75d6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div id=\"store-locator\" style=\"width:100%;max-width:1200px;margin:auto\">\r\n  <div style=\"display:flex;gap:10px;align-items:center;margin:12px 0;flex-wrap:wrap\">\r\n    <div style=\"position:relative;flex:1;min-width:260px\">\r\n      <input id=\"cityInput\" list=\"cityList\" placeholder=\"Scegli o digita una citt\u00e0\u2026\"\r\n           style=\"width:100%;padding:12px 44px 12px 14px;border:1px solid #ddd;border-radius:12px;outline:none\">\r\n      <datalist id=\"cityList\"><\/datalist>\r\n      <button id=\"clearBtn\" type=\"button\" aria-label=\"clear\"\r\n              style=\"position:absolute;right:8px;top:50%;transform:translateY(-50%);border:0;background:#f5f5f5;padding:6px 10px;border-radius:8px;cursor:pointer\">\r\n        \u2715\r\n      <\/button>\r\n    <\/div>\r\n    <button id=\"applyBtn\" type=\"button\"\r\n            style=\"padding:12px 16px;border:1px solid #222;border-radius:12px;background:#222;color:#fff;cursor:pointer\">\r\n      Mostra negozi\r\n    <\/button>\r\n  <\/div>\r\n\r\n  <div id=\"map\" style=\"height:560px;border-radius:16px;\"><\/div>\r\n\r\n  <div id=\"resultsWrap\" style=\"display:none;margin-top:14px\">\r\n    <h3 style=\"margin:8px 0 6px;font-size:18px\">Negozi a <span id=\"cityName\"><\/span><\/h3>\r\n    <div id=\"results\"><\/div>\r\n  <\/div>\r\n<\/div>\r\n\r\n<script>\r\n(async () => {\r\n  const DATA_URL = \"https:\/\/brunoribadi.it\/wp-content\/uploads\/2025\/09\/stores_with_lat_lng.json\";\r\n\r\n  \/\/ Load data\r\n  const stores = await fetch(DATA_URL).then(r => r.json());\r\n\r\n  \/\/ Build unique city list\r\n  const citySet = new Set(stores.map(s => (s['citt\u00e0 '] || \"\").trim()).filter(Boolean));\r\n  const cities = [...citySet].sort((a,b)=> a.localeCompare(b, 'it'));\r\n\r\n  \/\/ Populate datalist\r\n  const dl = document.getElementById('cityList');\r\n  cities.forEach(c => { const o=document.createElement('option'); o.value=c; dl.appendChild(o); });\r\n\r\n  \/\/ Elements\r\n  const cityInput = document.getElementById('cityInput');\r\n  const applyBtn  = document.getElementById('applyBtn');\r\n  const clearBtn  = document.getElementById('clearBtn');\r\n  const resultsWrap = document.getElementById('resultsWrap');\r\n  const resultsEl   = document.getElementById('results');\r\n  const cityNameEl  = document.getElementById('cityName');\r\n\r\n  \/\/ Google Map\r\n  const ITALY_BOUNDS = {\r\n    north: 47.4, south: 35.3, west: 6.5, east: 18.8\r\n  };\r\n  const map = new google.maps.Map(document.getElementById('map'), {\r\n    center: { lat: 41.8719, lng: 12.5674 }, zoom: 6,\r\n    restriction: { latLngBounds: ITALY_BOUNDS, strictBounds: true },\r\n    mapTypeControl: false, streetViewControl: false\r\n  });\r\n\r\n  let markers = [];\r\n\r\n  function clearMarkers() {\r\n    markers.forEach(m => m.setMap(null));\r\n    markers = [];\r\n  }\r\n\r\n  \/\/ Function to show all stores\r\n  function showAllStores() {\r\n      showStores(stores, \"Italia\");\r\n  }\r\n\r\n  async function showStores(storesToShow, name) {\r\n    resultsEl.innerHTML = \"\";\r\n    cityNameEl.textContent = name;\r\n    resultsWrap.style.display = \"block\";\r\n    clearMarkers();\r\n\r\n    const bounds = new google.maps.LatLngBounds();\r\n\r\n    for (const s of storesToShow) {\r\n      const latlng = { lat: s.lat, lng: s.lng };\r\n      if (latlng.lat === null || latlng.lng === null) continue; \/\/ Skip if no lat\/lng\r\n\r\n      const marker = new google.maps.Marker({\r\n        position: latlng, map,\r\n        title: s['cliente']\r\n      });\r\n      const info = new google.maps.InfoWindow({\r\n        content: `<div style=\"font-weight:600\">${s['cliente']}<\/div>\r\n                   <div style=\"font-size:13px;color:#555\">${s['indirizzo']}, ${s['citt\u00e0 ']} (${s['provincia']})<\/div>`\r\n      });\r\n      marker.addListener('click', () => info.open({ anchor: marker, map }));\r\n      markers.push(marker);\r\n      bounds.extend(latlng);\r\n\r\n      \/\/ List row\r\n      const row = document.createElement('div');\r\n      row.style.cssText = \"padding:10px 8px;border-bottom:1px solid #eee;display:flex;justify-content:space-between;gap:8px;align-items:center\";\r\n      row.innerHTML = `\r\n        <div>\r\n          <div style=\"font-weight:600\">${s['cliente']}<\/div>\r\n          <div style=\"font-size:14px;color:#555\">${s['indirizzo']}, ${s['citt\u00e0 ']} (${s['provincia']})<\/div>\r\n        <\/div>\r\n        <a target=\"_blank\" rel=\"noopener\"\r\n           href=\"https:\/\/www.google.com\/maps\/dir\/?api=1&destination=${encodeURIComponent(`${s['indirizzo']}, ${s['citt\u00e0 ']}, ${s['stato']}`)}\"\r\n           style=\"text-decoration:none;border:1px solid #ddd;padding:6px 10px;border-radius:8px;font-size:14px\">\r\n            Itinerario\r\n        <\/a>\r\n      `;\r\n      row.addEventListener('mouseenter', () => { info.open({ anchor: marker, map }); });\r\n      resultsEl.appendChild(row);\r\n    }\r\n\r\n    if (!bounds.isEmpty()) {\r\n      map.fitBounds(bounds, 40);\r\n    } else {\r\n      \/\/ No geocoded points \u2192 keep city selected but center Italy\r\n      map.setCenter({ lat: 41.8719, lng: 12.5674 }); map.setZoom(6);\r\n    }\r\n  }\r\n\r\n  async function showCity(selectedCity) {\r\n    \/\/ validate city\r\n    const match = cities.find(c => c.toLowerCase() === (selectedCity||\"\").trim().toLowerCase());\r\n    if (!match) {\r\n        showAllStores();\r\n        return;\r\n    }\r\n\r\n    const cityStores = stores.filter(s => (s['citt\u00e0 '] || \"\").toLowerCase() === match.toLowerCase());\r\n    showStores(cityStores, match);\r\n  }\r\n\r\n  \/\/ Handlers\r\n  applyBtn.addEventListener('click', () => showCity(cityInput.value));\r\n  cityInput.addEventListener('keydown', (e) => { if (e.key === 'Enter') showCity(cityInput.value); });\r\n  clearBtn.addEventListener('click', () => {\r\n    cityInput.value = \"\";\r\n    showAllStores();\r\n  });\r\n\r\n  \/\/ Ready: Show all stores on initial load\r\n  showAllStores();\r\n})();\r\n<\/script>\r\n\r\n<script async defer\r\n  src=\"https:\/\/maps.googleapis.com\/maps\/api\/js?key=AIzaSyADIh1WDhQ-3NdTpsDgAsjAWdZbHmXsmxE&libraries=places\">\r\n<\/script>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"wd-negative-gap elementor-element elementor-element-97032cf e-flex e-con-boxed e-con e-parent\" data-id=\"97032cf\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>\u2715 Mostra negozi Negozi a<\/p>","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-16188","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/brunoribadi.it\/it\/wp-json\/wp\/v2\/pages\/16188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brunoribadi.it\/it\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/brunoribadi.it\/it\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/brunoribadi.it\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/brunoribadi.it\/it\/wp-json\/wp\/v2\/comments?post=16188"}],"version-history":[{"count":46,"href":"https:\/\/brunoribadi.it\/it\/wp-json\/wp\/v2\/pages\/16188\/revisions"}],"predecessor-version":[{"id":17064,"href":"https:\/\/brunoribadi.it\/it\/wp-json\/wp\/v2\/pages\/16188\/revisions\/17064"}],"wp:attachment":[{"href":"https:\/\/brunoribadi.it\/it\/wp-json\/wp\/v2\/media?parent=16188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}