Skip to content

Commit

Permalink
✨ [FEAT] Add Annotation Categories to APIv2 in HD Views annotations (…
Browse files Browse the repository at this point in the history
…refs #4032)
  • Loading branch information
Chatewgne committed Jul 25, 2024
1 parent 20ad94b commit 2937618
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions geotrek/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class Meta:
class HDViewPointSerializer(TimeStampedSerializer):
geometry = geo_serializers.GeometryField(read_only=True, source="geom_transformed", precision=7)
picture_tiles_url = serializers.SerializerMethodField()
annotations = serializers.SerializerMethodField()
thumbnail_url = serializers.SerializerMethodField()
metadata_url = serializers.SerializerMethodField()
trek = serializers.SerializerMethodField()
Expand Down Expand Up @@ -397,6 +398,19 @@ def get_poi(self, obj):
return {'uuid': related_obj.uuid, 'id': related_obj.id}
return None

def get_annotations(self, obj):
annotations = obj.annotations
annotations_categories = obj.annotations_categories
for feature in annotations["features"]:
feat_id = feature["properties"]["annotationId"]
feat_type = feature["geometry"]["type"]
if feat_type == "Point" and str(feat_id) in annotations_categories.keys():
feature["properties"]['category'] = int(annotations_categories[str(feat_id)])
else:
feature["properties"]['category'] = None
return annotations


class Meta(TimeStampedSerializer.Meta):
model = common_models.HDViewPoint
fields = TimeStampedSerializer.Meta.fields + (
Expand Down

0 comments on commit 2937618

Please sign in to comment.