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

Highlight region boundaries #85

Merged
merged 5 commits into from
Apr 18, 2024
Merged
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.PHONY : load_regions load_data empty_data dump_fixtures load_fixtures distill check_distill_coordinates

MAP_ENGINE_DISTILL=True
DJANGO_READ_DOT_ENV_FILE=True
export

load_regions:
Expand Down
3 changes: 3 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def __getitem__(self, item): # noqa: D105, ANN001, ANN204
]

MAP_ENGINE_API_MVTS = {
"region": [setup.MVTAPI("region_boundaries", "map", "RegionBoundaries")],
"municipality": [
setup.MVTAPI("municipality", "map", "Municipality"),
setup.MVTAPI("municipalitylabel", "map", "Municipality", "label_tiles"),
Expand Down Expand Up @@ -359,6 +360,8 @@ def __getitem__(self, item): # noqa: D105, ANN001, ANN204
setup.ClusterAPI("storage", "map", "Storage", properties=["id", "unit_count"]),
]

MAP_ENGINE_LAYERS_AT_STARTUP = ["region_boundaries"]

MAP_ENGINE_STYLES_FOLDER = "digiplan/static/config/"
MAP_ENGINE_ZOOM_LEVELS = {
"municipality": setup.Zoom(8, 14),
Expand Down
25 changes: 25 additions & 0 deletions digiplan/map/migrations/0045_regionboundaries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.2.25 on 2024-03-28 10:53

import django.contrib.gis.db.models.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('map', '0044_merge_20240318_1859'),
]

operations = [
migrations.CreateModel(
name='RegionBoundaries',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('geom', django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326)),
],
options={
'verbose_name': 'RegionBoundaries',
'verbose_name_plural': 'RegionBoundaries',
},
),
]
17 changes: 17 additions & 0 deletions digiplan/map/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ def quantity_per_municipality_per_year(cls) -> pd.DataFrame:
return population_per_year


class RegionBoundaries(models.Model):
"""Region Boundaries model."""

geom = models.MultiPolygonField(srid=4326)

objects = models.Manager()
vector_tiles = StaticMVTManager(columns=[])

data_file = "bkg_vg250_region"
layer = "bkg_vg250_region"
mapping = {"geom": "MULTIPOLYGON"}

class Meta: # noqa: D106
verbose_name = _("RegionBoundaries")
verbose_name_plural = _("RegionBoundaries")


class RenewableModel(models.Model):
"""Base class for renewable cluster models."""

Expand Down
10 changes: 10 additions & 0 deletions digiplan/map/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def get_context_data(self, **kwargs) -> dict:
# Add unique session ID
context = super().get_context_data(**kwargs)

# Move region_boundaries layer to bottom:
context["mapengine_layers"].insert(
0,
context["mapengine_layers"].pop(
next(
i for i, element in enumerate(context["mapengine_layers"]) if element["id"] == "region_boundaries"
),
),
)

context["panels"] = [
forms.EnergyPanelForm(
utils.get_translated_json_from_file(config.ENERGY_SETTINGS_PANEL_FILE, self.request),
Expand Down
11 changes: 9 additions & 2 deletions digiplan/static/config/layer_styles.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"region-fill": {
"type": "fill",
"paint": {
"fill-color": "rgb(250,174,29)",
"fill-color": "rgb(250, 174, 29)",
"fill-opacity": [
"case",
[
Expand Down Expand Up @@ -51,7 +51,7 @@
"region-line": {
"type": "line",
"paint": {
"line-color": "rgb(250, 174,29)",
"line-color": "rgb(250, 174, 29)",
"line-width": [
"case",
[
Expand All @@ -67,6 +67,13 @@
]
}
},
"region_boundaries": {
"type": "line",
"paint": {
"line-color": "rgb(250, 174, 29)",
"line-width": 2
}
},
"wind": {
"type": "symbol",
"filter": ["!", ["has", "point_count"]],
Expand Down
1 change: 1 addition & 0 deletions digiplan/utils/data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
REGIONS = [models.Municipality]

MODELS = [
models.RegionBoundaries,
# Clusters
models.WindTurbine,
models.PVroof,
Expand Down