const POINTS = [ { name: "Офис Астана", type: "office", coords: [51.171, 71.429], address: "пр. Мәңгілік Ел, 55/4", phone: "+7 7172 00-00-00", hours: "Пн–Пт 9:00–18:00" }, { name: "Сервисная точка Алматы", type: "service", coords: [43.222, 76.851], address: "пр. Абая, 116", phone: "+7 7273 00-00-00", hours: "Пн–Сб 9:00–19:00" }, { name: "Магазин Шымкент", type: "shop", coords: [42.317, 69.624], address: "пр. Ахметова, 109", phone: "+7 7252 00-00-00", hours: "Ежедневно 10:00–20:00" }, { name: "Сервисная точка Караганда", type: "service", coords: [49.773, 73.066], address: "пр. Абай, 31", phone: "+7 7212 00-00-00", hours: "Пн–Сб 9:00–18:00" }, { name: "Магазин Костанай", type: "shop", coords: [53.176, 63.753], address: "пр. Абая, 86", phone: "+7 7142 00-00-00", hours: "Пн–Сб 10:00–19:00" }, { name: "Офис Атырау", type: "office", coords: [47.113, 51.874], address: "пр. Махатма Ганди, 258", phone: "+7 7262 00-00-00", hours: "Пн–Пт 9:00–18:00" } ]; const FILTERS = [ { id: "all", label: "Все" }, { id: "office", label: "Офисы" }, { id: "service", label: "Сервис" }, { id: "shop", label: "Магазины" } ]; let map; let markers = {}; let userMarker = null; let activeFilter = "all"; function iconFor(point, isUser) { return L.divIcon({ className: "", html: '
', iconSize: [12, 12], iconAnchor: [6, 6] }); } function popupHtml(p) { const tel = p.phone ? '' + p.phone + "" : ""; return "" + p.name + "" + "
" + p.address + "
" + "
" + p.hours + "
" + tel; } function initMap() { map = L.map("map", { zoomControl: true, attributionControl: true }); L.tileLayer("https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png", { subdomains: "abcd", maxZoom: 19, attribution: "© OpenStreetMap © CARTO" }).addTo(map); const bounds = []; POINTS.forEach(function (p) { const m = L.marker(p.coords, { icon: iconFor(p, false) }).addTo(map); m.bindPopup(popupHtml(p)); markers[p.name] = m; bounds.push(p.coords); }); map.fitBounds(bounds, { padding: [40, 40] }); } function renderFilters() { const bar = document.getElementById("filterBar"); bar.innerHTML = ""; FILTERS.forEach(function (f) { const active = f.id === activeFilter; const chip = document.createElement("button"); chip.type = "button"; chip.className = "kt-ai-btn" + (active ? "" : ""); chip.setAttribute("data-variant", active ? "primary" : "ghost"); chip.setAttribute("data-size", "sm"); chip.textContent = f.label; chip.addEventListener("click", function () { activeFilter = f.id; applyFilter(); renderFilters(); }); bar.appendChild(chip); }); const visible = activeFilter === "all" ? POINTS.length : POINTS.filter(function (p) { return p.type === activeFilter; }).length; document.getElementById("countChip").textContent = visible + " точек"; } function applyFilter() { Object.keys(markers).forEach(function (name) { const p = POINTS.find(function (x) { return x.name === name; }); const show = activeFilter === "all" || p.type === activeFilter; if (show && !map.hasLayer(markers[name])) markers[name].addTo(map); if (!show && map.hasLayer(markers[name])) map.removeLayer(markers[name]); }); } function renderOfficeCard() { const main = POINTS.find(function (p) { return p.type === "office" && p.coords[0] > 50; }) || POINTS[0]; const card = document.getElementById("officeCard"); const tel = main.phone ? '' + main.phone + "" : ""; card.innerHTML = '

' + main.name + "

" + 'Открыто по графику
' + '
' + '
' + main.address + "
" + '
' + main.hours + "
" + "
" + tel; } function locate() { if (!navigator.geolocation) { map.flyTo([48.0, 68.0], 5); return; } navigator.geolocation.getCurrentPosition( function (pos) { const ll = [pos.coords.latitude, pos.coords.longitude]; if (userMarker) map.removeLayer(userMarker); userMarker = L.marker(ll, { icon: iconFor(null, true), zIndexOffset: 1000 }).addTo(map); userMarker.bindPopup("Вы здесь"); map.flyTo(ll, 12, { duration: 0.8 }); }, function () { map.flyTo([48.0, 68.0], 5); }, { enableHighAccuracy: false, timeout: 5000 } ); } document.addEventListener("DOMContentLoaded", function () { if (window.L) initMap(); renderFilters(); renderOfficeCard(); document.getElementById("locateBtn").addEventListener("click", locate); });