39 lines
1.3 KiB
HTML
39 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Title</title>
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
|
|
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="map" style="width: 600px; height: 400px;"></div>
|
|
<script>
|
|
var map = L.map('map').setView([51.505, -0.09], 13); // Default to London, adjust as needed
|
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
}).addTo(map);
|
|
|
|
var marker;
|
|
|
|
map.on('click', function(e) {
|
|
if (marker) {
|
|
map.removeLayer(marker);
|
|
}
|
|
marker = L.marker(e.latlng).addTo(map);
|
|
document.querySelector('input[name="latitude"]').value = e.latlng.lat;
|
|
document.querySelector('input[name="longitude"]').value = e.latlng.lng;
|
|
});
|
|
|
|
// If editing, set the marker to the existing coordinates
|
|
var latInput = document.querySelector('input[name="latitude"]');
|
|
var lngInput = document.querySelector('input[name="longitude"]');
|
|
if (latInput.value && lngInput.value) {
|
|
marker = L.marker([latInput.value, lngInput.value]).addTo(map);
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html> |