// Pastikan sudah menyertakan Leaflet di HTML
//
//
// Inisialisasi peta
var map = L.map('map').setView([-6.200000, 106.816666], 10); // Sesuaikan koordinat dan zoom
// Tambahkan layer peta dasar dari OpenStreetMap
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Memuat data GeoJSON dari file eksternal
document.addEventListener("DOMContentLoaded", function() {
fetch('apiapi.geojson') // Ganti dengan path yang sesuai
.then(response => {
if (!response.ok) {
throw new Error("Gagal memuat GeoJSON");
}
return response.json();
})
.then(data => {
L.geoJSON(data, {
style: function (feature) {
return { color: "blue" };
},
onEachFeature: function (feature, layer) {
if (feature.properties && feature.properties.name) {
layer.bindPopup("Nama: " + feature.properties.name);
}
}
}).addTo(map);
})
.catch(error => console.error('Error loading GeoJSON:', error));
});