Skip to content

Commit

Permalink
feat(apis_entities): add a map route for place like entities
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Sep 16, 2024
1 parent 2f1e549 commit e724a5a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
14 changes: 14 additions & 0 deletions apis_core/apis_entities/static/js/entities_map.js
Original file line number Diff line number Diff line change
@@ -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: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).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);
}
}
26 changes: 26 additions & 0 deletions apis_core/apis_entities/templates/entities_map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "base.html" %}
{% load static %}

{% block scripts %}
<script src="{% static "js/entities_map.js" %}"></script>
{{ block.super }}
{% endblock scripts %}

{% block content %}
<datalist id="markers">
{% for object in object_list %}
{% if object.longitude and object.latitude %}
<option value="{{ object.label | slugify }}"
data-longitude="{{ object.longitude|floatformat:"4u" }}"
data-latitude="{{ object.latitude|floatformat:"4u" }}">
<p>
<b>{{ object.label }}</b>
<p>
<a href="{{ object.get_absolute_url }}">link</a>
</p>
</option>
{% endif %}
{% endfor %}
</datalist>
<div id="map" class="m-3" style="height: 80vh;"></div>
{% endblock content %}
5 changes: 5 additions & 0 deletions apis_core/apis_entities/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -90,4 +94,5 @@ def to_url(self, value):
include(entity_patterns),
),
path("autocomplete/", EntitiesAutocomplete.as_view(), name="autocomplete"),
path("<contenttype:contenttype>/map/", EntitiesMap.as_view(), name="map"),
]
6 changes: 5 additions & 1 deletion apis_core/apis_entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"

0 comments on commit e724a5a

Please sign in to comment.