Где купить?


Sklepy…
(function(){ const API=window.location.origin+/wp-json/bebetto/v1/sklepy; let ALL=[],filtered=[],activeId=null,markers={},userLat=null,userLng=null,userMarker=null; const map=L.map(bb-map,{zoomControl:true}).setView([52.0,19.3],6); L.tileLayer(https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png,{attribution:,maxZoom:19}).addTo(map); function mkIcon(a){const f=a?#008f77:#00b295,s=a?30:24,h=a?39:31,k=a?15:12;return L.divIcon({html:,className:,iconSize:[s,h],iconAnchor:[k,h],popupAnchor:[0,-h]})} function hav(a,b,c,d){const R=6371,dL=(c-a)*Math.PI/180,dl=(d-b)*Math.PI/180,x=Math.sin(dL/2)**2+Math.cos(a * Math.PI/180)*Math.cos(c*Math.PI/180)*Math.sin(dl/2)**2;return R*2*Math.atan2 (Math.sqrt(x),Math.sqrt(1-x))} function fd(km){return km<1?Мэт.round(km*1000)+ m:km<10?км.toFixed(1)+ km:Math.round(km)+ km} function ph(d){const di=userLat!==null?
+fd(hav(userLat,userLng,d.lat,d.lng))+ od Ciebie
:;return
+d.name+
+d.city+
+d.address+
+di+
} function am(d){const m=L.marker([d.lat,d.lng],{icon:mkIcon(false)}).addTo(map).bindPopup(ph(d),{maxWidth:220});m.on(click,()=>act(d.id,false));markers[d.id]=m} function act(id,sc=true){if(activeId!==null&&markers[activeId])markers[activeId].setIcon(mkIcon(false));activeId=id;const d=ALL.find(x=>x.id===id);if(markers[id]){markers[id].setIcon(mkIcon(true));markers[id].setPopupContent(ph(d));markers[id].openPopup();map.panTo([markers[id].getLatLng().lat,markers[id].getLatLng().lng],{animate:true})}document.querySelectorAll(#bbw .bb-item).forEach(el=>el.classList.toggle(on,parseInt(el.dataset.id)===id));if(sc){const el=document.querySelector(#bbw .bb-item[data-id=»‘+id+’»]);if(el)el.scrollIntoView({block:nearest,behavior:smooth})}} function rl(data){const l=document.getElementById(bb-list);document.getElementById(bb-cnt).textContent=data.length;if(!дата.length){l.innerHTML=
Brak wyników
;return}l.innerHTML=data.map(d=>
+d.city+(userLat!==null? · +fd(hav(userLat,userLng,d.lat,d.lng))+:)+
+d.name+
+d.address+
).join();l.querySelectorAll(.bb-item).forEach(el=>{el.addEventListener(click,()=>act(parseInt(el.dataset.id),false));el.addEventListener(keydown,e=>{if(e.key===Enter||e.key===)act(parseInt(el.dataset.id),false)})})} function sm(data){const v=new Set(data.map(d=>d.id));ALL.forEach(d=>{if(v.has(d.id)){if(!map.hasLayer(markers[d.id]))markers[d.id].addTo(map)}else{if(map.hasLayer(markers[d.id]))map.removeLayer(markers[d.id])}})} function af(sd=false){const q=document.getElementById(bbs).value.trim().toLowerCase();filtered=ALL.filter(d=>!q||d.name.toLowerCase().includes(q)||d.city.toLowerCase().includes(q)||d.address.toLowerCase().includes(q));if(sd&&userLat!==null)filtered.sort((a,b)=>hav(userLat,userLng,a.lat,a.lng)-hav(userLat,userLng,b.lat,b.lng));rl(filtered);sm(filtered)} document.getElementById(bb-search-btn).addEventListener(click,()=>af(userLat!==null)); document.getElementById(bbs).addEventListener(keydown,e=>{if(e.key===Enter)af(userLat!==null)}); document.getElementById(bbs).addEventListener(input,()=>af(userLat!==null)); document.getElementById(bb-loc).addEventListener(click,function(){ if(!navigator.geolocation) {sh (браузер не поддерживает геолокацию.);return} this.textContent=…;this.disabled=true; navigator.geolocation.getCurrentPosition(pos=>{ userLat=pos.coords.latitude;userLng=pos.coords.longitude; this.innerHTML= Użyj mojej lokalizacji; this.disabled=false;this.стили.background=var(—br);this.стили.color=#fff;this.стили.borderColor=var(—br); if(userMarker)map.removeLayer(userMarker); userMarker=L.marker([userLat,userLng],{icon:L.divIcon({html:
,className:,iconSize:[14,14],iconAnchor:[7,7]})}).addTo (map); af (true); sh(список отсортирован по расстоянию от вас); const near=filtered.срез (0,5).map(d=>[d.lat,d.lng]);near.push([userLat,userLng]);map.fitBounds(L.latLngBounds(near),{padding:[40,40]}); },()=>{this.innerHTML= используйте мое местоположение; this.disabled=false; sh(не удалось получить местоположение.)},{enableHighAccuracy:true,timeout:8000}); }); function sh(msg){document.getElementById(bb-hint-txt).textContent=msg;document.getElementById(bb-hint).classList.add(on)} fetch(API).then(r=>r.json()).then(data=>{ALL=data.sort((a,b)=>{const c=a.city.localeCompare(b.city,pl);return c||a.name.localeCompare(b.name,pl)});ALL.forEach(am);filtered=[…ALL];rl(ALL);}).catch(()=>{document.getElementById(bb-list).innerHTML=
Błąd ładowania danych.
}); })();