Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apis_entities): add a route that shows all places on a map #1180

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading