v7: working region-district-village search via Nominatim
This commit is contained in:
parent
08a02c6fda
commit
0606f947b1
64
index.html
64
index.html
@ -63,14 +63,15 @@ body{font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Inter,sans-serif;
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="loc-panel">
|
<div class="loc-panel">
|
||||||
<label>📍 Регион:</label>
|
<label>📍 Область:</label>
|
||||||
<select id="regionSelect" onchange="onRegionChange()"><option value="">— выберите —</option></select>
|
<select id="regionSelect" onchange="onRegionChange()"><option value="">— выберите —</option></select>
|
||||||
<label>Район:</label>
|
<label>Район:</label>
|
||||||
<select id="districtSelect" onchange="onDistrictChange()"><option value="">— выберите —</option></select>
|
<select id="districtSelect" onchange="onDistrictSelect()"><option value="">— все —</option></select>
|
||||||
<label>Нас. пункт:</label>
|
<label>Село:</label>
|
||||||
<input type="text" id="villageInput" placeholder="Название села...">
|
<input type="text" id="villageInput" placeholder="Название села..." style="width:100px">
|
||||||
<button onclick="searchLocation()">🔍 Найти</button>
|
<button onclick="searchLocation()">🔍 Найти</button>
|
||||||
<button onclick="autoDetect()" style="background:#FF9800;color:#fff">🔄 Авто</button>
|
<button onclick="autoDetect()" style="background:#FF9800;color:#fff">🔄 Авто</button>
|
||||||
|
<span id="locStatus" style="color:#888;font-size:9px"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="settings">
|
<div class="settings">
|
||||||
<label>📐 Шаг: <input type="number" id="poleStep" value="50" min="10" max="200"> м</label>
|
<label>📐 Шаг: <input type="number" id="poleStep" value="50" min="10" max="200"> м</label>
|
||||||
@ -156,18 +157,57 @@ function init(){
|
|||||||
function onRegionChange(){
|
function onRegionChange(){
|
||||||
const name=document.getElementById('regionSelect').value;
|
const name=document.getElementById('regionSelect').value;
|
||||||
const r=REGIONS.find(x=>x.name===name);
|
const r=REGIONS.find(x=>x.name===name);
|
||||||
if(r)map.setView(r.center,9);
|
if(!r){document.getElementById('districtSelect').innerHTML='<option value="">— все —</option>';return;}
|
||||||
|
map.setView(r.center,9);
|
||||||
|
document.getElementById('locStatus').textContent='⏳ загрузка районов...';
|
||||||
|
// Загружаем районы области через Nominatim
|
||||||
|
fetch('https://nominatim.openstreetmap.org/search?format=json&q='+encodeURIComponent('районы '+name+' области')+'&countrycodes=kz&limit=30')
|
||||||
|
.then(r=>r.json()).then(data=>{
|
||||||
|
const sel=document.getElementById('districtSelect');
|
||||||
|
const names=new Set();
|
||||||
|
sel.innerHTML='<option value="">— все —</option>';
|
||||||
|
data.forEach(item=>{
|
||||||
|
const match=item.display_name.match(/^([^,]+),\s*([^,]+)/);
|
||||||
|
if(match){
|
||||||
|
let dname=match[1].trim();
|
||||||
|
if(!dname.endsWith('район')&&!dname.endsWith('ауданы'))return;
|
||||||
|
dname=dname.replace(/\s*ауданы$/,'').replace(/\s*район$/,'');
|
||||||
|
if(!names.has(dname)){
|
||||||
|
names.add(dname);
|
||||||
|
const o=document.createElement('option');
|
||||||
|
o.value=dname;
|
||||||
|
o.textContent=dname+(dname.endsWith('ский')||dname.endsWith('ской')?' район':'');
|
||||||
|
sel.appendChild(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
document.getElementById('locStatus').textContent='';
|
||||||
|
if(names.size===0)document.getElementById('locStatus').textContent='районы не найдены';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function onDistrictChange(){
|
function onDistrictSelect(){
|
||||||
if(document.getElementById('districtSelect').value)searchLocation();
|
searchLocation();
|
||||||
}
|
}
|
||||||
function searchLocation(){
|
function searchLocation(){
|
||||||
const q=[document.getElementById('regionSelect').value,document.getElementById('districtSelect').value,document.getElementById('villageInput').value].filter(Boolean).join(', ');
|
const parts=[document.getElementById('regionSelect').value];
|
||||||
if(!q){showToast('Выберите регион или введите название');return;}
|
const d=document.getElementById('districtSelect').value;
|
||||||
fetch('https://nominatim.openstreetmap.org/search?format=json&q='+encodeURIComponent(q)+'&countrycodes=kz&limit=5')
|
const v=document.getElementById('villageInput').value.trim();
|
||||||
|
if(d)parts.push(d+(d.endsWith('ский')||d.endsWith('ской')?' район':''));
|
||||||
|
if(v)parts.push(v);
|
||||||
|
const q=parts.join(', ');
|
||||||
|
if(!q){showToast('Выберите область или введите село');return;}
|
||||||
|
document.getElementById('locStatus').textContent='⏳ поиск...';
|
||||||
|
fetch('https://nominatim.openstreetmap.org/search?format=json&q='+encodeURIComponent(q)+'&countrycodes=kz&limit=8')
|
||||||
.then(r=>r.json()).then(data=>{
|
.then(r=>r.json()).then(data=>{
|
||||||
if(!data.length){showToast('Не найдено');return;}
|
if(!data.length){showToast('❌ Не найдено: '+q);document.getElementById('locStatus').textContent='не найдено';return;}
|
||||||
map.setView([data[0].lat,data[0].lon],16);showToast('📍 '+data[0].display_name.split(',')[0]);
|
const loc=data[0];
|
||||||
|
map.setView([loc.lat,loc.lon],16);
|
||||||
|
const name=loc.display_name.split(',')[0];
|
||||||
|
showToast('📍 '+name);
|
||||||
|
document.getElementById('villageInput').value=name;
|
||||||
|
document.getElementById('locStatus').textContent=name;
|
||||||
|
// Автозагрузка OSM данных
|
||||||
|
setTimeout(autoDetect,500);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user