From e724a5a49cd5727a4f9a21ff7770e6c19060a77c Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Thu, 12 Sep 2024 13:36:13 +0200 Subject: [PATCH] feat(apis_entities): add a map route for place like entities --- .../apis_entities/static/js/entities_map.js | 14 ++++++++++ .../apis_entities/templates/entities_map.html | 26 +++++++++++++++++++ apis_core/apis_entities/urls.py | 5 ++++ apis_core/apis_entities/views.py | 6 ++++- 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 apis_core/apis_entities/static/js/entities_map.js create mode 100644 apis_core/apis_entities/templates/entities_map.html diff --git a/apis_core/apis_entities/static/js/entities_map.js b/apis_core/apis_entities/static/js/entities_map.js new file mode 100644 index 000000000..e345a37ea --- /dev/null +++ b/apis_core/apis_entities/static/js/entities_map.js @@ -0,0 +1,14 @@ +// we center on vienna first +var map = L.map('map').setView([47.26, 11.3933], 8); +L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { + maxZoom: 19, + attribution: '© OpenStreetMap' +}).addTo(map); +var markers = document.getElementById("markers"); +for (option of markers.options) { + var longitude = option.dataset.longitude; + var latitude = option.dataset.latitude; + if ((latitude > -180 && latitude < 180) && (longitude > -90 && longitude < 90)) { + var marker = L.marker([latitude, longitude]).addTo(map).bindPopup(option.innerHtml); + } +} \ No newline at end of file diff --git a/apis_core/apis_entities/templates/entities_map.html b/apis_core/apis_entities/templates/entities_map.html new file mode 100644 index 000000000..b7f144855 --- /dev/null +++ b/apis_core/apis_entities/templates/entities_map.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} +{% load static %} + +{% block scripts %} + + {{ block.super }} +{% endblock scripts %} + +{% block content %} + + {% for object in object_list %} + {% if object.longitude and object.latitude %} + + {% endif %} + {% endfor %} + +
+ {% endblock content %} diff --git a/apis_core/apis_entities/urls.py b/apis_core/apis_entities/urls.py index b1d21ad38..de26ac1e8 100644 --- a/apis_core/apis_entities/urls.py +++ b/apis_core/apis_entities/urls.py @@ -8,11 +8,15 @@ from apis_core.apis_entities.views import ( EntitiesAutocomplete, EntitiesDuplicate, + EntitiesMap, EntitiesMerge, EntitiesUpdate, ) +from apis_core.generic.urls import ContenttypeConverter from apis_core.generic.views import Create, Delete, Detail, List +register_converter(ContenttypeConverter, "contenttype") + class EntityToContenttypeConverter: """ @@ -90,4 +94,5 @@ def to_url(self, value): include(entity_patterns), ), path("autocomplete/", EntitiesAutocomplete.as_view(), name="autocomplete"), + path("/map/", EntitiesMap.as_view(), name="map"), ] diff --git a/apis_core/apis_entities/views.py b/apis_core/apis_entities/views.py index ac2ba4e63..e740e4c97 100644 --- a/apis_core/apis_entities/views.py +++ b/apis_core/apis_entities/views.py @@ -12,7 +12,7 @@ from apis_core.apis_entities.forms import EntitiesMergeForm from apis_core.apis_metainfo.models import RootObject from apis_core.generic.helpers import generate_search_filter -from apis_core.generic.views import GenericModelMixin, Update +from apis_core.generic.views import GenericModelMixin, List, Update class EntitiesUpdate(Update): @@ -120,3 +120,7 @@ def get_queryset(self): content_type.model_class(), self.q, prefix=f"{name}__" ) return RootObject.objects_inheritance.select_subclasses().filter(q) + + +class EntitiesMap(List): + template_name = "entities_map.html"