diff --git a/app.js b/app.js index e875697..935a899 100644 --- a/app.js +++ b/app.js @@ -15,6 +15,7 @@ let mode = null; // 'ibadah' | 'miskin' | null let editMode = null; // { type:'ibadah'|'miskin', id } β€” saat edit let ibadahList = []; let miskinList = []; +let importedGeoJSON = []; let myMarker = null; let pendingLatLng = null; let pendingAddr = null; @@ -589,14 +590,15 @@ window.removeMiskin = (id) => { document.getElementById('btn-reset').addEventListener('click', () => { ibadahList.forEach(ib => { map.removeLayer(ib.marker); map.removeLayer(ib.circle); }); miskinList.forEach(m => { map.removeLayer(m.marker); if (m.circle) map.removeLayer(m.circle); }); + importedGeoJSON.forEach(g => { map.removeLayer(g.layer); }); if (myMarker) { map.removeLayer(myMarker); myMarker = null; } if (tempMarker) { map.removeLayer(tempMarker); tempMarker = null; } - ibadahList = []; miskinList = []; + ibadahList = []; miskinList = []; importedGeoJSON = []; mode = null; editMode = null; updateToolbar(); resetMapCursor(); document.getElementById('form-overlay').classList.add('hidden'); document.getElementById('my-location-info').style.display = 'none'; document.getElementById('loc-bar').style.display = 'none'; - renderIbadahList(); renderMiskinList(); updateStats(); + renderIbadahList(); renderMiskinList(); if(typeof renderGeoJSONList === 'function') renderGeoJSONList(); updateStats(); showToast('πŸ—‘οΈ Semua data dihapus', '#ef4444'); }); @@ -644,4 +646,97 @@ document.addEventListener('keydown', e => { mode = null; updateToolbar(); resetMapCursor(); clearHighlights(); } } -}); \ No newline at end of file +}); + +// ═══════════════════════════════════════════════════════════════ +// GEOJSON IMPORT +// ═══════════════════════════════════════════════════════════════ +const fImportGeoJSON = document.getElementById('f-import-geojson'); +if (fImportGeoJSON) { + fImportGeoJSON.addEventListener('change', function(e) { + const file = e.target.files[0]; + if (!file) return; + + const reader = new FileReader(); + reader.onload = function(evt) { + try { + const geojsonData = JSON.parse(evt.target.result); + + // Buat layer GeoJSON + const layer = L.geoJSON(geojsonData, { + style: function(feature) { + return { + color: '#f59e0b', + weight: 3, + opacity: 0.8, + fillColor: '#f59e0b', + fillOpacity: 0.2 + }; + }, + onEachFeature: function(feature, layer) { + let popupContent = 'GeoJSON Feature
'; + if (feature.properties) { + for (const key in feature.properties) { + popupContent += `${key}: ${feature.properties[key]}
`; + } + } + layer.bindPopup(popupContent); + } + }).addTo(map); + + // Zoom ke layer yang baru diimpor + map.fitBounds(layer.getBounds()); + + const id = Date.now(); + importedGeoJSON.push({ + id: id, + name: file.name, + layer: layer + }); + + renderGeoJSONList(); + showToast(`πŸ“‚ File ${file.name} berhasil diimpor`, '#22c55e'); + + } catch (err) { + console.error(err); + showToast('❌ Gagal memparsing file GeoJSON', '#ef4444'); + } + + // Reset input agar file yang sama bisa dipilih lagi + fImportGeoJSON.value = ''; + }; + reader.readAsText(file); + }); +} + +window.renderGeoJSONList = function() { + const el = document.getElementById('geojson-list'); + if (!el) return; + + if (!importedGeoJSON.length) { + el.innerHTML = ''; + return; + } + + el.innerHTML = importedGeoJSON.map(g => ` +
+
πŸ—ΊοΈ
+
+
${truncate(g.name, 25)}
+
GeoJSON Layer
+
+
+ +
+
+ `).join(''); +}; + +window.removeGeoJSON = function(id) { + const idx = importedGeoJSON.findIndex(g => g.id === id); + if (idx < 0) return; + map.removeLayer(importedGeoJSON[idx].layer); + importedGeoJSON.splice(idx, 1); + renderGeoJSONList(); + showToast('πŸ—‘οΈ Layer dihapus', '#f59e0b'); +}; \ No newline at end of file diff --git a/index.html b/index.html index f3acb77..6a9d981 100644 --- a/index.html +++ b/index.html @@ -85,6 +85,12 @@ SPBU & Pangkalan BBM 0 + + +
+
Belum ada data SPBU