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

add optional model for map layers #3

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
96e8669
add optional model for map layers
finnus May 24, 2023
96d26df
add unit and name to choropleths
finnus May 30, 2023
43f8d9e
read legend name and unit from map_store
Josephine-Marie May 30, 2023
26ddf2e
change layer order to show clusters on top of other layers
finnus Jun 1, 2023
56b7cdf
exclude blank choropleth_field
finnus Jun 1, 2023
ad42c41
add optional model for map layers
finnus May 24, 2023
37046ab
add unit and name to choropleths
finnus May 30, 2023
5809def
change layer order to show clusters on top of other layers
finnus Jun 1, 2023
d6dd963
exclude blank choropleth_field
finnus Jun 1, 2023
b0edbe2
Chart options are read from popup data and not modified in JS
henhuy Jun 12, 2023
cda3dfd
Update version to v0.10.0
henhuy Jun 12, 2023
72080ba
Fix no choropleths set
henhuy Jun 12, 2023
c6903c3
Minor change
henhuy Jun 12, 2023
1a50429
Minor change
henhuy Jun 15, 2023
67a7726
Chart creation in popup is handled by project app (not mapengine)
henhuy Jun 15, 2023
af88549
Add .gitignore
henhuy Jun 15, 2023
8b9f272
Merge remote-tracking branch 'origin/optional_map_layer_model' into o…
finnus Jun 22, 2023
a7fa820
change keyword to adapt to new legend
finnus Jun 22, 2023
5863644
hand correct title to legend
finnus Jun 22, 2023
622ec02
SHow cluster layer on top of all layers
henhuy Jun 27, 2023
0cc4cb6
Add cluster properties
henhuy Jul 5, 2023
06c0d2e
Fix choropleth legend unit brackets
henhuy Jul 13, 2023
e286998
Update version to v0.13.1
henhuy Jul 13, 2023
14204e2
Fix map_store initialization
henhuy Aug 23, 2023
d97f475
add optional model for map layers
finnus May 24, 2023
2b25537
add unit and name to choropleths
finnus May 30, 2023
3c18c50
exclude blank choropleth_field
finnus Jun 1, 2023
d2cc9a1
change keyword to adapt to new legend
finnus Jun 22, 2023
c384ff9
Merge remote-tracking branch 'origin/optional_map_layer_model' into o…
finnus Aug 25, 2023
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
45 changes: 44 additions & 1 deletion django_mapengine/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Views and mixins in order to use mapengine"""

from django.apps import apps
from django.conf import settings
from django.http import JsonResponse
from django.views.generic.base import ContextMixin

from django.core.exceptions import FieldDoesNotExist
from . import __version__, layers, sources


Expand Down Expand Up @@ -65,6 +66,48 @@ def get_context_data(self, **kwargs) -> dict:
"choropleths": {choropleth.name: choropleth.as_dict() for choropleth in settings.MAP_ENGINE_CHOROPLETHS},
}

if settings.MAP_ENGINE_MAPLAYER_MODEL:
# get MapLayerModel from settings
try:
MapLayerModel = apps.get_model(app_label='map', model_name=settings.MAP_ENGINE_MAPLAYER_MODEL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the MapLayerModel would be integrated in mapengine's models.py ?
This would make model available in all projects which use mapengine automatically.
Also this would remove need for app.get_model and currently hardcoded "map" namespace.

except ImportError:
raise LookupError("The MapLayerModel does not exist.")

# get choropleth fields
try:
model_field = MapLayerModel._meta.get_field("choropleth_field")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also be obsolete, as we make sure field exists by providing model from within mapengine

except FieldDoesNotExist:
raise LookupError("Your MapLayerModel has no field named 'choropleth_field', which is mandatory.")
choropleths = MapLayerModel.objects.filter(choropleth_field__isnull=False).values_list("identifier",
"geom_layer")
store["choropleths"] = {
item[0]: {'layers': [item[1]], 'useFeatureState': True}
for item in choropleths
}

# get popups
try:
model_field = MapLayerModel._meta.get_field("popup_fields")
except FieldDoesNotExist:
raise LookupError("Your MapLayerModel has no field named 'popup_fields', which is mandatory.")

popups = MapLayerModel.objects.filter(popup_fields__isnull=False).values_list("identifier", "geom_layer")
transformed_popups = {}
for item in popups:
layer_id = item[1]
choropleth = item[0]

if layer_id not in transformed_popups:
transformed_popups[layer_id] = {
'layerID': layer_id,
'atDefaultLayer': False,
'choropleths': []
}

transformed_popups[layer_id]['choropleths'].append(choropleth)

store["popups"] = transformed_popups

context["mapengine_store_cold_init"] = store

return context