7cd391cf016c5b9abbaad0b356f74cd4b11f3fc2
[wolnelektury.git] / src / references / templates / references / map.html
1 {% extends "2022/base.html" %}
2 {% load static %}
3 {% load l10n %}
4
5 {% block global-content %}
6
7   <div id="references-map"></div>
8
9 {% endblock %}
10
11
12 {% block extrahead %}
13   <link rel="stylesheet" type="text/css" media="all" href="{% static 'contrib/leaflet-1.9.4/leaflet.css' %}">
14   <link rel="stylesheet" type="text/css" media="all" href="{% static 'contrib/leaflet.markercluster-1.4.1/MarkerCluster.css' %}">
15   <link rel="stylesheet" type="text/css" media="all" href="{% static 'contrib/leaflet.markercluster-1.4.1/MarkerCluster.Default.css' %}">
16 {% endblock %}
17
18
19 {% block extrabody %}
20   <script src="{% static 'contrib/leaflet-1.9.4/leaflet.js' %}"></script>
21   <script src="{% static 'contrib/leaflet.markercluster-1.4.1/leaflet.markercluster.js' %}"></script>
22   <script>
23    var map = L.map('references-map').setView([52, 20], 7);
24
25    if (navigator.geolocation) {
26        navigator.geolocation.getCurrentPosition(function(position) {
27            map.setView(
28                [position.coords.latitude, position.coords.longitude], 8,
29                {
30                    animate: true,
31                }
32            );
33        });
34    }
35
36    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
37        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
38    }).addTo(map);
39    var markers = L.markerClusterGroup();
40
41    function showMarker(m) {
42        $.get(
43            '/mapa/popup/' + m.target.options.mid,
44            function(data) {
45                let p = L.popup({minWidth: 340}).setLatLng(m.latlng).setContent(data);
46                map.openPopup(p);
47            }
48        );
49    }
50
51    {% localize off %}
52    {% for e in entities %}
53    L.marker(
54        [{{ e.lat }}, {{ e.lon }}],
55        {
56            title: "{{ e.label }}",
57            alt: "{{ e.label }}",
58            mid: {{ e.pk }},
59        }
60    ).on('click', showMarker).addTo(markers);
61    {% endfor %}
62    {% endlocalize %}
63
64    map.addLayer(markers);
65
66   </script>
67 {% endblock %}
68
69
70 {% block footer %}
71 {% endblock %}