add geometry endpoint
This commit is contained in:
parent
8abb9fe044
commit
9a9ea45242
3 changed files with 24 additions and 4 deletions
|
@ -348,6 +348,21 @@ class LocationViewSetBase(RetrieveModelMixin, GenericViewSet):
|
||||||
editor_url=can_access_editor(request)
|
editor_url=can_access_editor(request)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@action(detail=True, methods=['get'])
|
||||||
|
@api_etag(base_mapdata_check=True)
|
||||||
|
def geometry(self, request, **kwargs):
|
||||||
|
location = self.get_object()
|
||||||
|
|
||||||
|
if location is None:
|
||||||
|
raise NotFound
|
||||||
|
|
||||||
|
if isinstance(location, LocationRedirect):
|
||||||
|
return redirect('../' + str(location.target.pk) + '/geometry/')
|
||||||
|
|
||||||
|
return Response(location.get_geometry(
|
||||||
|
detailed_geometry=MapdataViewSet.can_access_geometry(request, location),
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
class LocationViewSet(LocationViewSetBase):
|
class LocationViewSet(LocationViewSetBase):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -42,6 +42,9 @@ class SerializableMixin(models.Model):
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_geometry(self, detailed_geometry=True):
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self):
|
def title(self):
|
||||||
return self._meta.verbose_name + ' ' + str(self.id)
|
return self._meta.verbose_name + ' ' + str(self.id)
|
||||||
|
|
|
@ -88,12 +88,14 @@ class GeometryMixin(SerializableMixin):
|
||||||
|
|
||||||
def details_display(self, detailed_geometry=True, **kwargs):
|
def details_display(self, detailed_geometry=True, **kwargs):
|
||||||
result = super().details_display(**kwargs)
|
result = super().details_display(**kwargs)
|
||||||
if detailed_geometry:
|
result['geometry'] = self.get_geometry(detailed_geometry=detailed_geometry)
|
||||||
result['geometry'] = format_geojson(smart_mapping(self.geometry), round=False)
|
|
||||||
else:
|
|
||||||
result['geometry'] = format_geojson(smart_mapping(box(*self.geometry.bounds)), round=False)
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def get_geometry(self, detailed_geometry=True):
|
||||||
|
if detailed_geometry:
|
||||||
|
return format_geojson(smart_mapping(self.geometry), round=False)
|
||||||
|
return format_geojson(smart_mapping(box(*self.geometry.bounds)), round=False)
|
||||||
|
|
||||||
def get_shadow_geojson(self):
|
def get_shadow_geojson(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue