v6: координаты каждого села, карта открывается на выбранном селе
This commit is contained in:
parent
e44907f283
commit
655784582f
35
js/app.js
35
js/app.js
@ -128,8 +128,9 @@ function initSelectors() {
|
|||||||
if (!rayon) return;
|
if (!rayon) return;
|
||||||
rayon.villages.forEach((v) => {
|
rayon.villages.forEach((v) => {
|
||||||
const opt = document.createElement("option");
|
const opt = document.createElement("option");
|
||||||
opt.value = v;
|
const vname = typeof v === "string" ? v : v.name;
|
||||||
opt.textContent = v;
|
opt.value = vname;
|
||||||
|
opt.textContent = vname;
|
||||||
villageSel.appendChild(opt);
|
villageSel.appendChild(opt);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -148,13 +149,20 @@ function initSelectors() {
|
|||||||
if (center) map.setView(center, 10);
|
if (center) map.setView(center, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getVillageCenter(v) {
|
||||||
|
if (typeof v === "object" && v.lat && v.lng) return [v.lat, v.lng];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function findVillageData(name) {
|
function findVillageData(name) {
|
||||||
const q = name.toLowerCase().trim();
|
const q = name.toLowerCase().trim();
|
||||||
for (const o of KZ_DATA) {
|
for (const o of KZ_DATA) {
|
||||||
for (const r of o.rayons) {
|
for (const r of o.rayons) {
|
||||||
for (const v of r.villages) {
|
for (const v of r.villages) {
|
||||||
if (v.toLowerCase() === q) {
|
const vname = typeof v === "string" ? v : v.name;
|
||||||
return { village: v, rayon: r.rayon, oblast: o.oblast, center: r.center || o.center };
|
if (vname.toLowerCase() === q) {
|
||||||
|
const center = getVillageCenter(v) || r.center || o.center;
|
||||||
|
return { village: vname, rayon: r.rayon, oblast: o.oblast, center };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,7 +198,18 @@ function initSelectors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
villageSel.addEventListener("change", function () {
|
villageSel.addEventListener("change", function () {
|
||||||
goToVillage(this.value);
|
const name = this.value;
|
||||||
|
if (!name) return;
|
||||||
|
const oblast = KZ_DATA.find((o) => o.oblast === oblastSel.value);
|
||||||
|
if (!oblast) return;
|
||||||
|
const rayon = oblast.rayons.find((r) => r.rayon === rayonSel.value);
|
||||||
|
if (!rayon) return;
|
||||||
|
const village = rayon.villages.find((v) => (typeof v === "string" ? v : v.name) === name);
|
||||||
|
const center = getVillageCenter(village) || (rayon ? rayon.center : null) || oblast.center;
|
||||||
|
if (center) {
|
||||||
|
map.setView(center, 14);
|
||||||
|
L.popup().setLatLng(center).setContent(`<b>${name}</b><br>${oblast.oblast}, ${rayon.rayon}`).openOn(map);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
manualVillage.addEventListener("keydown", function (e) {
|
manualVillage.addEventListener("keydown", function (e) {
|
||||||
@ -213,8 +232,10 @@ function initSelectors() {
|
|||||||
KZ_DATA.forEach((o) => {
|
KZ_DATA.forEach((o) => {
|
||||||
o.rayons.forEach((r) => {
|
o.rayons.forEach((r) => {
|
||||||
r.villages.forEach((v) => {
|
r.villages.forEach((v) => {
|
||||||
if (v.toLowerCase().includes(q)) {
|
const vname = typeof v === "string" ? v : v.name;
|
||||||
results.push({ village: v, rayon: r.rayon, oblast: o.oblast, center: r.center || o.center });
|
if (vname.toLowerCase().includes(q)) {
|
||||||
|
const center = getVillageCenter(v) || r.center || o.center;
|
||||||
|
results.push({ village: vname, rayon: r.rayon, oblast: o.oblast, center });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
17058
js/kz-data.js
17058
js/kz-data.js
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user