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

Allow more map interactions and refactor map value datastructures #4953

Merged
Merged
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
Loading