126 lines
5.8 KiB
JavaScript
126 lines
5.8 KiB
JavaScript
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: '<div class="kt-ai-mark' + (isUser ? " kt-ai-mark--me" : "") + '"></div>',
|
||
iconSize: [12, 12],
|
||
iconAnchor: [6, 6]
|
||
});
|
||
}
|
||
|
||
function popupHtml(p) {
|
||
const tel = p.phone ? '<a class="kt-ai-link" href="tel:' + p.phone.replace(/\s|-/g, "") + '" style="display:block;margin-top:8px;">' + p.phone + "</a>" : "";
|
||
return "<strong>" + p.name + "</strong>" +
|
||
"<div style='margin-top:6px;color:'" + "var(--kt-ai-fg-muted);" + "'>" + p.address + "</div>" +
|
||
"<div style='margin-top:4px'>" + p.hours + "</div>" + 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: "© <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap</a> © <a href='https://carto.com/attributions'>CARTO</a>"
|
||
}).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 ? '<a class="kt-ai-link" href="tel:' + main.phone.replace(/\s|-/g, "") + '" style="margin-top:12px;display:inline-block;">' + main.phone + "</a>" : "";
|
||
card.innerHTML =
|
||
'<div class="kt-ai-card-top"><h3 style="margin:0;">' + main.name + "</h3>" +
|
||
'<span class="kt-ai-chip" data-variant="default">Открыто по графику</span></div>' +
|
||
'<div class="kt-ai-card-body">' +
|
||
'<div class="kt-ai-card-line"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"/><circle cx="12" cy="10" r="3"/></svg><span>' + main.address + "</span></div>" +
|
||
'<div class="kt-ai-card-line"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg><span>' + main.hours + "</span></div>" +
|
||
"</div>" + 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);
|
||
});
|