Skip to content

Commit

Permalink
✨ [#2173] Define map tile layer url on request
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robinmolen committed Dec 17, 2024
1 parent cfe9972 commit 824b2d2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/openforms/formio/components/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 824b2d2

Please sign in to comment.