Skip to content

Commit

Permalink
Merge pull request #4953 from open-formulieren/feature/2177-map-inter…
Browse files Browse the repository at this point in the history
…actions-and-different-map-data

Allow more map interactions and refactor map value datastructures
  • Loading branch information
sergei-maertens authored Jan 22, 2025
2 parents 1de4853 + 308f1c4 commit a4d0095
Show file tree
Hide file tree
Showing 40 changed files with 3,947 additions and 1,413 deletions.
436 changes: 392 additions & 44 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@fortawesome/fontawesome-free": "^6.1.1",
"@open-formulieren/design-tokens": "^0.53.0",
"@open-formulieren/formio-builder": "^0.34.0",
"@open-formulieren/formio-builder": "^0.35.0",
"@open-formulieren/leaflet-tools": "^1.0.0",
"@open-formulieren/monaco-json-editor": "^0.2.0",
"@tinymce/tinymce-react": "^4.3.2",
Expand Down
65 changes: 65 additions & 0 deletions src/openforms/api/geojson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from typing import Literal, TypedDict

from django.db import models
from django.utils.translation import gettext_lazy as _

from drf_polymorphic.serializers import PolymorphicSerializer
from rest_framework import serializers


class GeoJsonGeometryTypes(models.TextChoices):
point = "Point", _("Point")
polygon = "Polygon", _("Polygon")
line_string = "LineString", _("LineString")


class GeoJSONCoordinatesField(serializers.ListField):
child = serializers.FloatField(required=True, allow_null=False)

def __init__(self, *args, **kwargs):
kwargs["min_length"] = 2
kwargs["max_length"] = 2
super().__init__(*args, **kwargs)


class GeoJSONPointGeometrySerializer(serializers.Serializer):
coordinates = GeoJSONCoordinatesField()


class GeoJSONLineStringGeometrySerializer(serializers.Serializer):
coordinates = serializers.ListField(child=GeoJSONCoordinatesField())


class GeoJSONPolygonGeometrySerializer(serializers.Serializer):
coordinates = serializers.ListField(
child=serializers.ListField(child=GeoJSONCoordinatesField())
)


class GeoJsonGeometryPolymorphicSerializer(PolymorphicSerializer):
type = serializers.ChoiceField(choices=GeoJsonGeometryTypes.choices, required=True)

discriminator_field = "type"
serializer_mapping = {
GeoJsonGeometryTypes.point: GeoJSONPointGeometrySerializer,
GeoJsonGeometryTypes.line_string: GeoJSONLineStringGeometrySerializer,
GeoJsonGeometryTypes.polygon: GeoJSONPolygonGeometrySerializer,
}


type Coordinates = tuple[float, float]


class PointGeometry(TypedDict):
type: Literal["Point"]
coordinates: Coordinates


class LineStringGeometry(TypedDict):
type: Literal["LineString"]
coordinates: list[Coordinates]


class PolygonGeometry(TypedDict):
type: Literal["Polygon"]
coordinates: list[list[Coordinates]]
Loading

0 comments on commit a4d0095

Please sign in to comment.