2024-08-18 00:38:09 +00:00
|
|
|
{% extends 'base.html' %}
|
|
|
|
|
|
|
|
|
|
{% block content %}
|
2024-08-21 19:38:01 +00:00
|
|
|
<div id="map" style="height: 100%; border-style: groove; border-radius: 22px; border-width: 4px; position: absolute;"></div>
|
2024-08-18 00:38:09 +00:00
|
|
|
<script>
|
|
|
|
|
//setView([51.505, -0.09], 13);
|
2024-08-31 23:50:22 +00:00
|
|
|
var map = new L.map('map', {zoomControl: false}, center=([20.57, -100.38], zoom=13));
|
2024-08-18 00:38:09 +00:00
|
|
|
var user_marker = new L.marker([20.57, -100.38]);
|
2024-08-31 23:50:22 +00:00
|
|
|
var user_radial = new L.circle(L.circle(user_marker.latlng));
|
2024-08-25 00:54:11 +00:00
|
|
|
//L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
|
|
|
|
2024-08-31 23:50:22 +00:00
|
|
|
//types of markers
|
|
|
|
|
var iconTypes = {
|
|
|
|
|
'bache': '<i class="fas fa-exclamation-triangle"></i>',
|
|
|
|
|
'coladera': '<i class="fas fa-ring"></i>',
|
|
|
|
|
'obra sin terminar': '<i class="far fa-wrench"></i>',
|
|
|
|
|
'escombro': '<i class="far fa-trash-alt"></i>',
|
|
|
|
|
'robo-asalto': '<i class="far fa-skull"></i>',
|
|
|
|
|
'biciestacionamiento': '<i class="far fa-home"></i>',
|
|
|
|
|
'mala iluminación': '<i class="far fa-lightbulb"></i>'
|
|
|
|
|
};
|
2024-08-18 00:38:09 +00:00
|
|
|
|
2024-08-21 19:38:01 +00:00
|
|
|
{% for pin in pins %}
|
2024-08-31 23:50:22 +00:00
|
|
|
|
|
|
|
|
var icon = L.divIcon({
|
|
|
|
|
className: '{{pin.typeofpin}}',
|
|
|
|
|
html: iconTypes['{{pin.typeofpin}}'],
|
|
|
|
|
iconSize:[10,10],
|
|
|
|
|
iconAnchor:[10,10],
|
|
|
|
|
});
|
|
|
|
|
L.marker([{{ pin.lat }}, {{ pin.lng }}], {icon: icon}).addTo(map)
|
2024-08-21 19:38:01 +00:00
|
|
|
.bindPopup("<b>{{ pin.description }}</b><p>Fecha del reporte: {{pin.time}}</p><br><img src='{{ pin.photo }}'>");
|
2024-08-31 23:50:22 +00:00
|
|
|
{% endfor %}
|
2024-08-18 00:38:09 +00:00
|
|
|
|
|
|
|
|
//var live_location = map.locate()
|
|
|
|
|
//if (navigator.geolocation) {
|
|
|
|
|
// navigator.geolocation.getCurrentPosition((position)) => {
|
|
|
|
|
// change map position
|
|
|
|
|
// };
|
|
|
|
|
// };
|
|
|
|
|
//var youarehere = L.marker([latlng.lat, latlng.lng]).addTo(map);
|
|
|
|
|
|
|
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
2024-08-26 19:40:34 +00:00
|
|
|
//L.tileLayer('https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png', {
|
2024-08-18 00:38:09 +00:00
|
|
|
attribution: '© OpenStreetMap contributors'
|
|
|
|
|
}).addTo(map);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Geolocation function
|
|
|
|
|
function onLocationFound(e) {
|
|
|
|
|
var radius = e.accuracy / 2; // Accuracy of the location
|
|
|
|
|
|
|
|
|
|
// Add a pin (marker) at the user's location
|
|
|
|
|
user_marker = L.marker(e.latlng).addTo(map)
|
|
|
|
|
.bindPopup("Te detectamos en un radio de " + radius + " metros de este punto").openPopup();
|
|
|
|
|
|
|
|
|
|
// Add a circle around the user's location
|
|
|
|
|
user_radial = L.circle(e.latlng, radius).addTo(map);
|
|
|
|
|
|
|
|
|
|
// Center the map on the user's location
|
2024-08-21 19:38:01 +00:00
|
|
|
map.setView(e.latlng, 16); // Adjust zoom level as needed
|
2024-08-18 00:38:09 +00:00
|
|
|
//return marker, radial;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Error handling for geolocation
|
|
|
|
|
function onLocationError(e) {
|
|
|
|
|
alert(e.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use Leaflet's built-in location detection
|
|
|
|
|
map.on('locationfound', onLocationFound);
|
|
|
|
|
map.on('locationerror', onLocationError);
|
|
|
|
|
|
|
|
|
|
// Start the location detection
|
|
|
|
|
map.locate({setView: true, maxZoom: 16});
|
|
|
|
|
map.on('click', function(e) {
|
|
|
|
|
var latlng = e.latlng;
|
2024-08-21 19:38:01 +00:00
|
|
|
document.getElementById('lat').value = latlng.lat;
|
|
|
|
|
document.getElementById('lng').value = latlng.lng;
|
2024-08-18 00:38:09 +00:00
|
|
|
map.flyTo(e.latlng, zoom=18);
|
|
|
|
|
//map.eachLayer( function (layer)) {
|
|
|
|
|
// console.log(layer);
|
|
|
|
|
// map.removeLayer(layer);
|
|
|
|
|
//};
|
|
|
|
|
//marker.remove();
|
|
|
|
|
//radial.remove();
|
2024-08-21 19:38:01 +00:00
|
|
|
user_marker.setLatLng(e.latlng).bindPopup('<button id="pinner-pop">Agregar bache-o-cosa</button>').openPopup();
|
2024-08-18 00:38:09 +00:00
|
|
|
user_radial.remove();
|
|
|
|
|
//setLanLng(e.latlng);
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-21 19:38:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-18 00:38:09 +00:00
|
|
|
</script>
|
|
|
|
|
{% endblock %}
|