experimental map
authorRadek Czajka <rczajka@rczajka.pl>
Sat, 10 Jun 2023 17:02:37 +0000 (19:02 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Sat, 10 Jun 2023 17:02:37 +0000 (19:02 +0200)
src/references/templates/references/map.html [new file with mode: 0644]
src/references/urls.py [new file with mode: 0644]
src/references/views.py
src/wolnelektury/urls.py

diff --git a/src/references/templates/references/map.html b/src/references/templates/references/map.html
new file mode 100644 (file)
index 0000000..6204837
--- /dev/null
@@ -0,0 +1,35 @@
+{% load l10n %}
+
+<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
+   integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
+       crossorigin=""/>
+  <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
+   integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
+          crossorigin=""></script>
+
+<div id="map" style="height: 100%"></div>
+<script>
+  var map = L.map('map').setView([51.505, -0.09], 8);
+  L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
+    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
+  }).addTo(map);
+
+ {% localize off %}
+ {% for e in entities %}
+ L.marker(
+     [{{ e.lat }}, {{ e.lon }}],
+     {
+         title: "{{ e.label }}",
+         alt: "{{ e.label }}",
+     }
+ ).bindPopup("\
+<h1>{{ e.label }}</h1>\
+{% for ref in e.reference_set.all %}\
+<a href='/katalog/lektura/{{ ref.book.slug }}.html#{{ ref.first_section }}'>\
+  {{ ref.book.title }}\
+</a>\
+{% endfor %}\
+ ").addTo(map);
+ {% endfor %}
+ {% endlocalize %}
+</script>
diff --git a/src/references/urls.py b/src/references/urls.py
new file mode 100644 (file)
index 0000000..5bd2a62
--- /dev/null
@@ -0,0 +1,7 @@
+from django.urls import path
+from . import views
+
+
+urlpatterns = [
+    path('mapa/', views.map),
+]
index 91ea44a..b98d181 100644 (file)
@@ -1,3 +1,9 @@
 from django.shortcuts import render
+from . import models
 
-# Create your views here.
+
+def map(request):
+    return render(request, 'references/map.html', {
+        'entities': models.Entity.objects.exclude(lat=None).exclude(lon=None),
+    })
+                  
index f34071f..3d420ce 100644 (file)
@@ -44,6 +44,7 @@ urlpatterns += [
     path('wesprzyj/', include('funding.urls')),
     path('ankieta/', include('polls.urls')),
     path('biblioteki/', include('libraries.urls')),
+    path('pinezki/', include('references.urls')),
     path('newsletter/', include('newsletter.urls')),
     path('formularz/', include('forms_builder.forms.urls')),
     path('isbn/', include('isbn.urls')),