Skip to content

Commit

Permalink
App Datenmanagement: Bugfix Kartendaten laden
Browse files Browse the repository at this point in the history
  • Loading branch information
gdmhrogut committed Sep 22, 2023
1 parent f7cb656 commit 0a9995a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 49 deletions.
32 changes: 16 additions & 16 deletions datenmanagement/templates/datenmanagement/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,13 @@ <h5>Adressensuche</h5>

// define several globally available variables
window.geometryType = '{{ geometry_type }}';
window.promises = [];
window.count = 0;
{% if heavy_load_limit %}
window.heavyLoadLimit = true
// variables and constants for the number of (already fetched) features of the GeoJSON feature collection
window.border = {{ objects_count }}
window.limit = {{ heavy_load_limit }}
{% endif %}
{% if highlight_flag %}
window.highlightFlag = true
Expand Down Expand Up @@ -301,14 +306,9 @@ <h5>Adressensuche</h5>

// falls große Datenmenge zu erwarten ist...
if (window.heavyLoadLimit) {
// Konstanten und Variablen für die Anzahl der (bereits geholten) Features der GeoJSON featureCollection definieren
const border = {{ objects_count }};
const limit = {{ heavy_load_limit }};
let promises = [];
let count = 0;
// Zähler im Bootstrap-Modal setzen, das während des Ladevorgangs der GeoJSON featureCollection für die Karte eingeblendet wird
$('#loading-modal-map-data-count').text(count);
$('#loading-modal-map-data-border').text(border);
$('#loading-modal-map-data-count').text(window.count);
$('#loading-modal-map-data-border').text(window.border);
}

/**
Expand Down Expand Up @@ -342,9 +342,9 @@ <h5>Adressensuche</h5>
});
const data = await response.json();
if (heavyLoad) {
count += data.features.length;
$('#loading-modal-map-data-count').text(count);
if (count === border) {
window.count += data.features.length;
$('#loading-modal-map-data-count').text(window.count);
if (window.count === window.border) {
toggleModal($('#loading-modal'));
}
} else
Expand All @@ -362,10 +362,10 @@ <h5>Adressensuche</h5>
// falls große Datenmenge zu erwarten ist...
if (window.heavyLoadLimit) {
// GeoJSON featureCollection für die Karte in mehreren Ladeschritten holen, die alle parallel ausgeführt werden
for (let offset = 0; offset < border; offset += limit) {
promises.push(fetchGeoJsonFeatureCollection(true, limit, offset));
for (let offset = 0; offset < window.border; offset += window.limit) {
window.promises.push(fetchGeoJsonFeatureCollection(true, window.limit, offset));
}
Promise.all(promises)
Promise.all(window.promises)
.then(data => {
// jedes Feature der GeoJSON featureCollection mit Marker versehen, Aktionen und Eigenschaften definieren, Tooltip setzen und zum Cluster hinzufügen
L.Proj.geoJson(data, {
Expand Down Expand Up @@ -415,10 +415,10 @@ <h5>Adressensuche</h5>
// falls große Datenmenge zu erwarten ist...
if (window.heavyLoadLimit) {
// GeoJSON featureCollection für die Karte in mehreren Ladeschritten holen, die alle parallel ausgeführt werden
for (let offset = 0; offset < border; offset += limit) {
promises.push(fetchGeoJsonFeatureCollection(true, limit, offset));
for (let offset = 0; offset < window.border; offset += window.limit) {
window.promises.push(fetchGeoJsonFeatureCollection(true, window.limit, offset));
}
Promise.all(promises)
Promise.all(window.promises)
.then(data => {
// für jedes Feature der GeoJSON featureCollection Aktionen und Eigenschaften definieren und Feature zur Karte hinzufügen
L.Proj.geoJson(data, {
Expand Down
19 changes: 10 additions & 9 deletions datenmanagement/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from .views.functions import delete_object_immediately
from .views.views_form import DataAddView, DataChangeView, DataDeleteView
from .views.views_general import GeometryView, GISFiletoGeoJSON, IndexView, StartView
from .views.views_list_map import DataListView, DataMapListView, DataMapView, DataView
from .views.views_list_map import MapDataCompositionView, MapListView, TableDataCompositionView, \
TableListView


router = DefaultRouter()
Expand Down Expand Up @@ -84,7 +85,7 @@ def permission_required(*perms):
model_name + '/data',
view=permission_required(
'datenmanagement.view_' + model_name_lower
)(DataView.as_view(model=model)),
)(TableDataCompositionView.as_view(model=model)),
name=model_name + '_data'
)
)
Expand All @@ -96,7 +97,7 @@ def permission_required(*perms):
model_name + '/data/subset/<subset_id>',
view=permission_required(
'datenmanagement.view_' + model_name_lower
)(DataView.as_view(model=model)),
)(TableDataCompositionView.as_view(model=model)),
name=model_name + '_data_subset'
)
)
Expand All @@ -109,7 +110,7 @@ def permission_required(*perms):
'datenmanagement.change_' + model_name_lower,
'datenmanagement.delete_' + model_name_lower,
'datenmanagement.view_' + model_name_lower
)(DataListView.as_view(
)(TableListView.as_view(
model=model,
template_name='datenmanagement/list.html'
)),
Expand All @@ -126,7 +127,7 @@ def permission_required(*perms):
'datenmanagement.change_' + model_name_lower,
'datenmanagement.delete_' + model_name_lower,
'datenmanagement.view_' + model_name_lower
)(DataListView.as_view(
)(TableListView.as_view(
model=model,
template_name='datenmanagement/list.html'
)),
Expand All @@ -140,7 +141,7 @@ def permission_required(*perms):
model_name + '/mapdata',
view=permission_required(
'datenmanagement.view_' + model_name_lower
)(DataMapView.as_view(model=model)),
)(MapDataCompositionView.as_view(model=model)),
name=model_name + '_mapdata'
)
)
Expand All @@ -152,7 +153,7 @@ def permission_required(*perms):
model_name + '/mapdata/subset/<subset_id>',
view=permission_required(
'datenmanagement.view_' + model_name_lower
)(DataMapView.as_view(model=model)),
)(MapDataCompositionView.as_view(model=model)),
name=model_name + '_mapdata_subset'
)
)
Expand All @@ -165,7 +166,7 @@ def permission_required(*perms):
'datenmanagement.change_' + model_name_lower,
'datenmanagement.delete_' + model_name_lower,
'datenmanagement.view_' + model_name_lower
)(DataMapListView.as_view(
)(MapListView.as_view(
model=model,
template_name='datenmanagement/map.html'
)),
Expand All @@ -182,7 +183,7 @@ def permission_required(*perms):
'datenmanagement.change_' + model_name_lower,
'datenmanagement.delete_' + model_name_lower,
'datenmanagement.view_' + model_name_lower
)(DataMapListView.as_view(
)(MapListView.as_view(
model=model,
template_name='datenmanagement/map.html'
)),
Expand Down
2 changes: 1 addition & 1 deletion datenmanagement/views/views_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db import connections
from django.forms.models import modelform_factory
from django.urls import reverse
from django.views.generic import CreateView, DeleteView, UpdateView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from json import dumps
from re import sub
from time import time
Expand Down
36 changes: 13 additions & 23 deletions datenmanagement/views/views_list_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db.models import Q
from django.urls import reverse
from django.utils.html import escape
from django.views import generic
from django.views.generic.base import TemplateView
from django_datatables_view.base_datatable_view import BaseDatatableView
from jsonview.views import JsonView
from json import dumps, loads
Expand All @@ -18,7 +18,7 @@
add_model_context_elements


class DataView(BaseDatatableView):
class TableDataCompositionView(BaseDatatableView):
"""
bereitet Datenbankobjekte für Tabellenansicht auf
Expand All @@ -39,7 +39,7 @@ def __init__(self, model=None):
self.columns_with_foreign_key = self.model.BasemodelMeta.list_fields_with_foreign_key
self.column_as_highlight_flag = self.model.BasemodelMeta.list_highlight_flag
self.thumbs = self.model.BasemodelMeta.thumbs
super(DataView, self).__init__()
super().__init__()

def get_initial_queryset(self):
if self.kwargs and self.kwargs['subset_id']:
Expand Down Expand Up @@ -253,7 +253,7 @@ def ordering(self, qs):
return qs


class DataListView(generic.ListView):
class TableListView(TemplateView):
"""
listet alle Datenbankobjekte eines Datensatzes in einer Tabelle auf
Expand All @@ -262,17 +262,12 @@ class DataListView(generic.ListView):
:param success_url: Success-URL
"""

model = None

def __init__(self, model=None, template_name=None, success_url=None):
self.model = model
self.template_name = template_name
super(DataListView, self).__init__()

def get_queryset(self):
"""
überschreibt Funktion für Standard-Rückgabewert,
damit diese nichts zurückgibt statt stumpf die Gesamtmenge aller Objekte des Datenmodells
"""
return
super().__init__()

def get_context_data(self, **kwargs):
"""
Expand All @@ -291,7 +286,7 @@ def get_context_data(self, **kwargs):
return context


class DataMapView(JsonView):
class MapDataCompositionView(JsonView):
"""
Abfrage aller Datenbankobjekte eines Datensatzes für die Karte
* limit: auf n Datenbankobjekte limitieren (entspricht SQL-LIMIT)
Expand All @@ -307,7 +302,7 @@ def __init__(self, model):
self.model_name_lower = self.model.__name__.lower()
self.model_pk_field = self.model._meta.pk.name
self.editable = self.model.BasemodelMeta.editable
super(DataMapView, self).__init__()
super().__init__()

def get_context_data(self, **kwargs):
"""
Expand Down Expand Up @@ -445,7 +440,7 @@ def get_context_data(self, **kwargs):
return map_features


class DataMapListView(generic.ListView):
class MapListView(TemplateView):
"""
zeigt alle Datenbankobjekte eines Datensatzes auf einer Karte an;
außerdem werden, falls definiert, entsprechende Filtermöglichkeiten geladen
Expand All @@ -454,19 +449,14 @@ class DataMapListView(generic.ListView):
:param template_name: Name des Templates
"""

model = None

def __init__(self, model=None, template_name=None):
self.model = model
self.model_name = self.model.__name__
self.model_name_lower = self.model.__name__.lower()
self.template_name = template_name
super(DataMapListView, self).__init__()

def get_queryset(self):
"""
überschreibt Funktion für Standard-Rückgabewert,
damit diese nichts zurückgibt statt stumpf die Gesamtmenge aller Objekte des Datenmodells
"""
return
super().__init__()

def get_context_data(self, **kwargs):
"""
Expand Down

0 comments on commit 0a9995a

Please sign in to comment.