fix: real-time reverse geocoding on drag, copy missing backend scripts to publik, update right sidebar card UI

This commit is contained in:
2026-06-12 10:14:09 +07:00
parent a9785feeb5
commit 0d995aee1e
18 changed files with 624 additions and 160 deletions
+28 -8
View File
@@ -763,19 +763,27 @@ Promise.all([
------------------------------------------------------- */
function reverseGeocode(lat, lng) {
el('fp_alamat').value = '';
el('geocodeStatus').textContent = '\u23F3 Mencari alamat...';
if (el('fp_alamat')) el('fp_alamat').value = '';
if (el('pm_alamat')) el('pm_alamat').value = '';
const statusEl = el('geocodeStatus');
if (statusEl) statusEl.textContent = '\u23F3 Mencari alamat...';
fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}&accept-language=id`)
.then(r => r.json())
.then(data => {
el('fp_alamat').value = data.display_name || 'Alamat tidak ditemukan';
el('geocodeStatus').textContent = '\u2713';
setTimeout(() => { el('geocodeStatus').textContent = ''; }, 2000);
const alamat = data.display_name || 'Alamat tidak ditemukan';
if (el('fp_alamat')) el('fp_alamat').value = alamat;
if (el('pm_alamat')) el('pm_alamat').value = alamat;
if (statusEl) {
statusEl.textContent = '\u2713';
setTimeout(() => { statusEl.textContent = ''; }, 2000);
}
})
.catch(() => {
el('fp_alamat').value = 'Gagal mengambil alamat';
el('geocodeStatus').textContent = '\u2715';
if (el('fp_alamat')) el('fp_alamat').value = 'Gagal mengambil alamat';
if (el('pm_alamat')) el('pm_alamat').value = 'Gagal mengambil alamat';
if (statusEl) statusEl.textContent = '\u2715';
});
}
@@ -840,6 +848,7 @@ map.on('click', e => {
previewMarker = L.marker(e.latlng, {
icon: createPendudukIcon(cek.status === 'Dalam Jangkauan')
}).addTo(map);
reverseGeocode(lat, lng);
showModal('pendudukModal');
return;
}
@@ -1317,7 +1326,7 @@ window.hapusData = function (tipe, id, pesan) {
/* -------------------------------------------------------
GLOBAL: UPDATE LOKASI DARI DRAG MARKER
------------------------------------------------------- */
window.updateLocation = function(tipe, id, lat, lng, nama) {
window.updateLocation = async function(tipe, id, lat, lng, nama) {
const urlMap = {
point: 'point/update_lokasi.php',
penduduk_miskin: 'penduduk_miskin/update_lokasi.php'
@@ -1332,6 +1341,17 @@ window.updateLocation = function(tipe, id, lat, lng, nama) {
const cek = cekJangkauan(lat, lng);
fd.append('status_jangkauan', cek.status);
fd.append('fasilitas_publik_id', cek.id || '');
// Ambil alamat baru
try {
const r = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}&accept-language=id`);
const data = await r.json();
if (data && data.display_name) {
fd.append('alamat', data.display_name);
}
} catch(e) {
console.warn("Gagal mendapatkan alamat saat drag");
}
}
postData(urlMap[tipe], fd).then(res => {