diff --git a/index.html b/index.html index 4805d39..8330ee1 100644 --- a/index.html +++ b/index.html @@ -63,14 +63,15 @@ body{font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Inter,sans-serif;
- + - - - + + + +
@@ -156,18 +157,57 @@ function init(){ function onRegionChange(){ const name=document.getElementById('regionSelect').value; const r=REGIONS.find(x=>x.name===name); - if(r)map.setView(r.center,9); + if(!r){document.getElementById('districtSelect').innerHTML='';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=''; + 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(){ - if(document.getElementById('districtSelect').value)searchLocation(); +function onDistrictSelect(){ + searchLocation(); } function searchLocation(){ - const q=[document.getElementById('regionSelect').value,document.getElementById('districtSelect').value,document.getElementById('villageInput').value].filter(Boolean).join(', '); - if(!q){showToast('Выберите регион или введите название');return;} - fetch('https://nominatim.openstreetmap.org/search?format=json&q='+encodeURIComponent(q)+'&countrycodes=kz&limit=5') + const parts=[document.getElementById('regionSelect').value]; + const d=document.getElementById('districtSelect').value; + 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=>{ - if(!data.length){showToast('Не найдено');return;} - map.setView([data[0].lat,data[0].lon],16);showToast('📍 '+data[0].display_name.split(',')[0]); + if(!data.length){showToast('❌ Не найдено: '+q);document.getElementById('locStatus').textContent='не найдено';return;} + 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); }); }