Dynamic map

This commit is contained in:
Ethanell 2021-12-03 05:22:13 +01:00
parent 046e52ecd3
commit 30da722bac
6 changed files with 50 additions and 4 deletions

View file

@ -31,7 +31,7 @@ ALLOWED_HOSTS = ["3cab-134-214-214-199.ngrok.io", "localhost", "4125-134-214-214
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
"core.apps.AppConfig", "core.apps.CoreConfig",
"rescue.apps.RescueConfig", "rescue.apps.RescueConfig",
"people.apps.PeopleConfig", "people.apps.PeopleConfig",
"boat.apps.BoatConfig", "boat.apps.BoatConfig",

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 B

View file

@ -8,7 +8,7 @@
<p class="desc">{{ rescue.resume }}</p> <p class="desc">{{ rescue.resume }}</p>
<div class="pic-flex"> <div class="pic-flex">
<img src="{% static 'images/bateau.jpg' %}"> <img src="{% static 'images/bateau.jpg' %}">
<img src="{% static 'images/sauvetage.png' %}"> <div id="map" style="width:300px; height:300px"></div>
</div> </div>
<div class="content"> <div class="content">
{{ rescue.description.html | safe }} {{ rescue.description.html | safe }}
@ -30,6 +30,35 @@
</section> </section>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
<script>
let map = L.map('map').setView([{{ rescue.location_long }}, {{ rescue.location_lat }}], 7);
const iconRetinaUrl = '{% static 'images/marker-icon-2x.png' %}';
const iconUrl = '{% static 'images/marker-icon.png' %}';
const shadowUrl = '{% static 'images/marker-shadow.png' %}';
const iconDefault = L.icon({
iconRetinaUrl,
iconUrl,
shadowUrl,
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
tooltipAnchor: [16, -28],
shadowSize: [41, 41]
});
L.Marker.prototype.options.icon = iconDefault;
let osmLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors',
maxZoom: 19
});
L.marker([{{ rescue.location_long }}, {{ rescue.location_lat }}]).addTo(map).bindPopup('{{ rescue.name }}');
map.addLayer(osmLayer);
</script>
{% endblock %} {% endblock %}

View file

@ -5,7 +5,6 @@
<section> <section>
<h2>Carte dynamique</h2> <h2>Carte dynamique</h2>
<div id="map" style="width:100%; height:60%"></div> <div id="map" style="width:100%; height:60%"></div>
<!-- <img class="map" src="{% static 'images/map.png' %}"> -->
</section> </section>
<section> <section>
<h2>Articles récents</h2> <h2>Articles récents</h2>
@ -30,12 +29,30 @@
<script> <script>
let map = L.map('map').setView([51.127, 2.253], 7); let map = L.map('map').setView([51.127, 2.253], 7);
const iconRetinaUrl = '{% static 'images/marker-icon-2x.png' %}';
const iconUrl = '{% static 'images/marker-icon.png' %}';
const shadowUrl = '{% static 'images/marker-shadow.png' %}';
const iconDefault = L.icon({
iconRetinaUrl,
iconUrl,
shadowUrl,
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
tooltipAnchor: [16, -28],
shadowSize: [41, 41]
});
L.Marker.prototype.options.icon = iconDefault;
let osmLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { let osmLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors', attribution: '© OpenStreetMap contributors',
maxZoom: 19 maxZoom: 19
}); });
L.marker([48.5, -0.09]).addTo(map).bindPopup('<a href="/a/1/">Sauvetage de mer</a>'); {% for rescue in rescues %}
L.marker([{{ rescue.location_long }}, {{ rescue.location_lat }}]).addTo(map).bindPopup('<a href="/a/{{ rescue.pk }}/">{{ rescue.name }}</a>');
{% endfor %}
map.addLayer(osmLayer); map.addLayer(osmLayer);
</script> </script>