fix(master-land): create showmap function
This commit is contained in:
parent
f8d8165492
commit
f8732a5bb6
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -1,4 +1,5 @@
|
|||
var map;
|
||||
var currentMarker = null;
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
// Initialize the first map
|
||||
map = L.map("map", {
|
||||
|
@ -91,6 +92,42 @@ function getRegencies(provinceId) {
|
|||
function showmap(districtId) {
|
||||
mapContainer.style.display = "block";
|
||||
map.invalidateSize();
|
||||
if (!navigator.geolocation) {
|
||||
alert("Geolocation tidak didukung oleh browser ini.");
|
||||
return;
|
||||
}
|
||||
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
function (position) {
|
||||
var lat = position.coords.latitude;
|
||||
var lng = position.coords.longitude;
|
||||
|
||||
console.log(lat, lng);
|
||||
|
||||
map.setView([lat, lng], 16);
|
||||
|
||||
if (currentMarker) {
|
||||
map.removeLayer(currentMarker);
|
||||
}
|
||||
|
||||
var iconMarker = L.icon({
|
||||
iconUrl: "/assets/images/marker.png",
|
||||
iconSize: [50, 50],
|
||||
iconAnchor: [25, 50],
|
||||
popupAnchor: [0, -50],
|
||||
});
|
||||
|
||||
currentMarker = L.marker([lat, lng], {
|
||||
icon: iconMarker,
|
||||
draggable: true,
|
||||
}).addTo(map);
|
||||
|
||||
currentMarker.bindPopup("Kamu berada di sini.").openPopup();
|
||||
},
|
||||
function (error) {
|
||||
alert("Error: " + error.message);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function getDistricts(regencyId) {
|
||||
|
|
Loading…
Reference in New Issue