From 57aeaae47ac4ddb9d0a171fd19d6a837c1281bad Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 16 Mar 2022 11:36:15 +0100 Subject: Geodata: fix templates with geovectordata --- .../templates/ishtar/sheet_contextrecord.html | 6 +-- .../templates/ishtar/sheet_basefind.html | 2 +- .../templates/ishtar/sheet_operation.html | 2 +- .../templates/ishtar/sheet_site.html | 2 +- .../templates/ishtar/sheet_container.html | 2 +- .../templates/ishtar/sheet_warehouse.html | 2 +- ishtar_common/models_common.py | 53 +++++++++++++++++++++- .../templates/ishtar/blocks/sheet_map.html | 16 +++++-- .../templates/ishtar/blocks/sheet_simple_map.html | 24 ---------- 9 files changed, 73 insertions(+), 36 deletions(-) delete mode 100644 ishtar_common/templates/ishtar/blocks/sheet_simple_map.html diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index c98bcef98..1c3bb4b41 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -149,19 +149,19 @@ {% field_flex "Depth of appearance (m)" item.depth_of_appearance '' '' has_image %} + {% if item.main_geodata %}

{% trans "Localisation"%}

{% with geo_item=item %} - {% include "ishtar/blocks/sheet_simple_map.html"%} + {% include "ishtar/blocks/sheet_map.html"%}
{% field_flex_multiple_full "Towns" item.operation.towns %} {% include "ishtar/blocks/sheet_coordinates.html"%} - {% if PROFILE.experimental_feature %} {% include "ishtar/blocks/sheet_geo_items.html"%} - {% endif %}
{% endwith %}
+ {% endif %}

{% trans "Sheet" %}

diff --git a/archaeological_finds/templates/ishtar/sheet_basefind.html b/archaeological_finds/templates/ishtar/sheet_basefind.html index 0b56727ca..225d8ee83 100644 --- a/archaeological_finds/templates/ishtar/sheet_basefind.html +++ b/archaeological_finds/templates/ishtar/sheet_basefind.html @@ -73,7 +73,7 @@

{% trans "Localisation"%}

{% with geo_item=base_find %} - {% include "ishtar/blocks/sheet_simple_map.html"%} + {% include "ishtar/blocks/sheet_map.html"%}
{% include "ishtar/blocks/sheet_coordinates.html"%} {% field_flex_full "Point of topographic reference" base_find.topographic_localisation %} diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index d24bb20fe..76aadb444 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -287,7 +287,7 @@
{% with geo_item=item %} - {% include "ishtar/blocks/sheet_simple_map.html"%} + {% include "ishtar/blocks/sheet_map.html"%}
{% include "ishtar/blocks/sheet_coordinates.html"%} {% if next %} diff --git a/archaeological_operations/templates/ishtar/sheet_site.html b/archaeological_operations/templates/ishtar/sheet_site.html index 4904b5562..a1125d202 100644 --- a/archaeological_operations/templates/ishtar/sheet_site.html +++ b/archaeological_operations/templates/ishtar/sheet_site.html @@ -63,7 +63,7 @@

{% trans "Localisation"%}

{% with geo_item=item %} - {% include "ishtar/blocks/sheet_simple_map.html"%} + {% include "ishtar/blocks/sheet_map.html"%}
{% include "ishtar/blocks/sheet_coordinates.html"%} diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html index 84bbd2f14..a6a1e279b 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_container.html +++ b/archaeological_warehouse/templates/ishtar/sheet_container.html @@ -152,7 +152,7 @@

{% trans "Localisation"%}

{% with geo_item=item %} - {% include "ishtar/blocks/sheet_simple_map.html" %} + {% include "ishtar/blocks/sheet_map.html" %}
{% include "ishtar/blocks/sheet_coordinates.html" %}
diff --git a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html index 0adf3c1b8..e03feb026 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html +++ b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html @@ -102,7 +102,7 @@

{% trans "Localisation"%}

{% with geo_item=item %} - {% if PROFILE.locate_warehouses %}{% include "ishtar/blocks/sheet_simple_map.html"%}{% endif %} + {% if PROFILE.locate_warehouses %}{% include "ishtar/blocks/sheet_map.html"%}{% endif %}
{% if PROFILE.locate_warehouses %}{% include "ishtar/blocks/sheet_coordinates.html"%}{% endif %} {% with full=True %}{% include "ishtar/blocks/sheet_address_section.html" %}{% endwith %} diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 414e63c55..104e46100 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2062,6 +2062,22 @@ class GeoProviderType(HierarchicalType): ) +GEOJSON_POINT_TPL = { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [] + }, + "properties": { + } + } + ] +} + + class GeoVectorData(models.Model): name = models.TextField(_("Name"), default=_("Default")) source_content_type = models.ForeignKey( @@ -2272,7 +2288,7 @@ class GeoVectorData(models.Model): def _geojson_serialize(self, geom_attr): if not hasattr(self, geom_attr): - return "" + return "{}" geojson = serialize( "geojson", self.__class__.objects.filter(pk=self.pk), @@ -2280,6 +2296,9 @@ class GeoVectorData(models.Model): fields=("name",), ) geojson_dct = json.loads(geojson) + return self._geojson_base_serialize(geojson_dct) + + def _geojson_base_serialize(self, geojson_dct): profile = get_current_profile() precision = profile.point_precision @@ -2311,6 +2330,38 @@ class GeoVectorData(models.Model): def multi_polygon_geojson(self): return self._geojson_serialize("multi_polygon") + @property + def geometry_type(self): + if self.x or self.y or self.z or self.point_2d or self.point_3d: + return "POINT" + if self.multi_line: + return "MULTILINE" + if self.multi_points: + return "MULTIPOINTS" + if self.multi_polygon: + return "MULTIPOLYGON" + return "" + + @property + def geojson(self): + if self.x or self.y or self.z: + geo = GEOJSON_POINT_TPL.copy() + geo["features"][0]["geometry"]["coordinates"] = [ + self.cached_x, self.cached_y + ] + return self._geojson_base_serialize(geo) + if self.point_2d: + return self._geojson_serialize("point_2d") + if self.point_3d: + return self._geojson_serialize("point_3d") + if self.multi_line: + return self._geojson_serialize("multi_line") + if self.multi_points: + return self._geojson_serialize("multi_points") + if self.multi_polygon: + return self._geojson_serialize("multi_polygon") + return "{}" + post_save.connect(post_save_geodata, sender=GeoVectorData) diff --git a/ishtar_common/templates/ishtar/blocks/sheet_map.html b/ishtar_common/templates/ishtar/blocks/sheet_map.html index 296516e86..e0278b8c7 100644 --- a/ishtar_common/templates/ishtar/blocks/sheet_map.html +++ b/ishtar_common/templates/ishtar/blocks/sheet_map.html @@ -1,11 +1,18 @@ +{% if PROFILE.mapping and geo_item.main_geodata %} +
+
+
+
+
+ +{% endif %} diff --git a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html deleted file mode 100644 index 93035862f..000000000 --- a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html +++ /dev/null @@ -1,24 +0,0 @@ -{% if PROFILE.mapping %} -{% if geo_item.point_2d or geo_item.multi_polygon %} -
-
-
-
-
- -{% endif %} -{% endif %} -- cgit v1.2.3