From 824b2d247f9e9ba4dd8859084ab82014ef079f5d Mon Sep 17 00:00:00 2001 From: robinvandermolen Date: Mon, 25 Nov 2024 14:19:04 +0100 Subject: [PATCH] :sparkles: [#2173] Define map tile layer url on request The map configuration can be edited at any moment. To make sure that we always return the correct tile layer url, fetch the url and add it to the component object dynamically. Using the mutate_config_dynamically we can now use the tile_layer_url for form steps and the form summary. --- src/openforms/formio/components/custom.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/openforms/formio/components/custom.py b/src/openforms/formio/components/custom.py index e7521c482b..7f78b6fc19 100644 --- a/src/openforms/formio/components/custom.py +++ b/src/openforms/formio/components/custom.py @@ -14,7 +14,7 @@ from rest_framework.request import Request from openforms.authentication.service import AuthAttribute -from openforms.config.models import GlobalConfiguration +from openforms.config.models import GlobalConfiguration, MapTileLayer from openforms.submissions.models import Submission from openforms.typing import DataMapping from openforms.utils.date import TIMEZONE_AMS, datetime_in_amsterdam, format_date_value @@ -189,6 +189,15 @@ def build_serializer_field( class Map(BasePlugin[Component]): formatter = MapFormatter + def mutate_config_dynamically( + self, component, submission: Submission, data: DataMapping + ) -> None: + if (identifier := component.get("tileLayerIdentifier")) is not None: + tile_layer = MapTileLayer.objects.filter(identifier=identifier).first() + if tile_layer is not None: + # Add the tile layer url information + component["tileLayerUrl"] = tile_layer.url + @staticmethod def rewrite_for_request(component, request: Request): if component.get("useConfigDefaultMapSettings", False):