Map client holes fix

* fixes bug where holes in stored geometries would not be rendered properly on initial loading the map client
    * drawback: multiple polygons are treated as a single feature on the map client. Not a real issue but maybe we can find a better solution to this
* quality of life: renders geometry area in m² on detail and report view
This commit is contained in:
mpeltriaux 2022-10-14 08:02:08 +02:00
parent 20c9950b7f
commit e6c0d8b1cf
2 changed files with 17 additions and 11 deletions

View File

@ -213,12 +213,9 @@ class Geometry(BaseResource):
geojson (dict): The FeatureCollection json (as dict) geojson (dict): The FeatureCollection json (as dict)
""" """
geom = self.geom geom = self.geom
if geom.srid != srid:
geom.transform(ct=srid) geom.transform(ct=srid)
polygons = []
for coords in geom.coords:
p = Polygon(coords[0], srid=geom.srid)
polygons.append(p)
geojson = { geojson = {
"type": "FeatureCollection", "type": "FeatureCollection",
"crs": { "crs": {
@ -230,8 +227,8 @@ class Geometry(BaseResource):
"features": [ "features": [
{ {
"type": "Feature", "type": "Feature",
"geometry": json.loads(x.geojson) "geometry": json.loads(geom.json),
} for x in polygons }
] ]
} }
return geojson return geojson

View File

@ -2,11 +2,20 @@
<div class="col-sm-12"> <div class="col-sm-12">
<div class="card"> <div class="card">
<div class="card-header rlp-r"> <div class="card-header rlp-r">
<div class="row">
<div class="col-6">
<h5> <h5>
{% fa5_icon 'search-location' %} {% fa5_icon 'search-location' %}
{% trans 'Spatial reference' %} {% trans 'Spatial reference' %}
</h5> </h5>
</div> </div>
<div class="col-6 text-right">
<h5>
{{ obj.geometry.geom.area|floatformat:2 }} m²
</h5>
</div>
</div>
</div>
<div class="card-body"> <div class="card-body">
<div hx-trigger="load, every 5s" hx-get="{% url 'geometry-parcels' geom_form.instance.geometry.id %}"> <div hx-trigger="load, every 5s" hx-get="{% url 'geometry-parcels' geom_form.instance.geometry.id %}">
<div class="row justify-content-center"> <div class="row justify-content-center">