-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4953 from open-formulieren/feature/2177-map-inter…
…actions-and-different-map-data Allow more map interactions and refactor map value datastructures
- Loading branch information
Showing
40 changed files
with
3,947 additions
and
1,413 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]] |
Oops, something went wrong.