-
Notifications
You must be signed in to change notification settings - Fork 4
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
finnus
wants to merge
29
commits into
main
Choose a base branch
from
optional_map_layer_model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
96e8669
add optional model for map layers
finnus 96d26df
add unit and name to choropleths
finnus 43f8d9e
read legend name and unit from map_store
Josephine-Marie 26ddf2e
change layer order to show clusters on top of other layers
finnus 56b7cdf
exclude blank choropleth_field
finnus ad42c41
add optional model for map layers
finnus 37046ab
add unit and name to choropleths
finnus 5809def
change layer order to show clusters on top of other layers
finnus d6dd963
exclude blank choropleth_field
finnus b0edbe2
Chart options are read from popup data and not modified in JS
henhuy cda3dfd
Update version to v0.10.0
henhuy 72080ba
Fix no choropleths set
henhuy c6903c3
Minor change
henhuy 1a50429
Minor change
henhuy 67a7726
Chart creation in popup is handled by project app (not mapengine)
henhuy af88549
Add .gitignore
henhuy 8b9f272
Merge remote-tracking branch 'origin/optional_map_layer_model' into o…
finnus a7fa820
change keyword to adapt to new legend
finnus 5863644
hand correct title to legend
finnus 622ec02
SHow cluster layer on top of all layers
henhuy 0cc4cb6
Add cluster properties
henhuy 06c0d2e
Fix choropleth legend unit brackets
henhuy e286998
Update version to v0.13.1
henhuy 14204e2
Fix map_store initialization
henhuy d97f475
add optional model for map layers
finnus 2b25537
add unit and name to choropleths
finnus 3c18c50
exclude blank choropleth_field
finnus d2cc9a1
change keyword to adapt to new legend
finnus c384ff9
Merge remote-tracking branch 'origin/optional_map_layer_model' into o…
finnus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Map Engine init, holds version""" | ||
|
||
__version__ = "0.9.0" | ||
__version__ = "0.13.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
@@ -65,6 +66,53 @@ 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) | ||
except ImportError: | ||
raise LookupError("The MapLayerModel does not exist.") | ||
|
||
# get choropleth fields | ||
try: | ||
model_field = MapLayerModel._meta.get_field("choropleth_field") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.exclude(choropleth_field="").filter(choropleth_field__isnull=False).values_list( | ||
"identifier", "geom_layer", "choropleth_unit", "name") | ||
store["choropleths"] = { | ||
item[0]: { | ||
'layers': [item[1]], | ||
'useFeatureState': True, | ||
'unit': [item[2]], | ||
'title': [item[3]] | ||
} | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
name: django_oemof | ||
name: django_mapengine | ||
dependencies: | ||
- python=3.9 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.