summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_context_records/templates/ishtar/sheet_contextrecord.html6
-rw-r--r--archaeological_finds/templates/ishtar/sheet_basefind.html2
-rw-r--r--archaeological_operations/templates/ishtar/sheet_operation.html2
-rw-r--r--archaeological_operations/templates/ishtar/sheet_site.html2
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_container.html2
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_warehouse.html2
-rw-r--r--ishtar_common/models_common.py53
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_map.html16
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_simple_map.html24
9 files changed, 73 insertions, 36 deletions
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 %}
</div>
+ {% if item.main_geodata %}
<h3>{% trans "Localisation"%}</h3>
<div class='row'>
{% with geo_item=item %}
- {% include "ishtar/blocks/sheet_simple_map.html"%}
+ {% include "ishtar/blocks/sheet_map.html"%}
<div class="col-12 col-lg-6 flex-wrap">
{% 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 %}
</div>
{% endwith %}
</div>
+ {% endif %}
<h3>{% trans "Sheet" %}</h3>
<div class="row">
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 @@
<h3>{% trans "Localisation"%}</h3>
<div class='row'>
{% with geo_item=base_find %}
- {% include "ishtar/blocks/sheet_simple_map.html"%}
+ {% include "ishtar/blocks/sheet_map.html"%}
<div class="col-12 col-lg-6 flex-wrap">
{% 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 @@
<div class="row">
{% with geo_item=item %}
- {% include "ishtar/blocks/sheet_simple_map.html"%}
+ {% include "ishtar/blocks/sheet_map.html"%}
<div class="col-12 col-lg-6 flex-wrap">
{% 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 @@
<h3>{% trans "Localisation"%}</h3>
<div class="row">
{% with geo_item=item %}
- {% include "ishtar/blocks/sheet_simple_map.html"%}
+ {% include "ishtar/blocks/sheet_map.html"%}
<div class="col-12 col-lg-6 flex-wrap">
{% 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 @@
<h3>{% trans "Localisation"%}</h3>
<div class='row'>
{% with geo_item=item %}
- {% include "ishtar/blocks/sheet_simple_map.html" %}
+ {% include "ishtar/blocks/sheet_map.html" %}
<div class="col-12 col-lg-6 flex-wrap">
{% include "ishtar/blocks/sheet_coordinates.html" %}
</div>
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 @@
<h3>{% trans "Localisation"%}</h3>
<div class='row'>
{% 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 %}
<div class="col-12 col-lg-6 flex-wrap">
{% 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 %}
+<div class="col-12 col-lg-6 flex-wrap">
+ <div class="window-map" id="map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}">
+ </div>
+ <div id="map-content-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}"></div>
+</div>
+<script type="text/javascript">
+
const disp_map = function() {
const html = render_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", false, true);
$("#map-content-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}").html(html);
- {% if geo_item.most_precise_geo == 'point' %}
- const {{geo_item.SLUG}}{{geo_item.pk}} = {{geo_item.point_2d_geojson|safe}};
+ const {{geo_item.SLUG}}{{geo_item.pk}} = {{geo_item.main_geodata.geojson|safe}};
+ {% if geo_item.main_geodata.geometry_type == 'POINT' %}
display_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", {{geo_item.SLUG}}{{geo_item.pk}});
{% else %}
- const {{geo_item.SLUG}}{{geo_item.pk}} = {{geo_item.multi_polygon_geojson|safe}};
display_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", null, {{geo_item.SLUG}}{{geo_item.pk}});
{% endif %}
}
@@ -60,3 +67,6 @@ get_polygons.change( function () {
})
{% endif %}
{% endif %}
+
+</script>
+{% 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 %}
-<div class="col-12 col-lg-6 flex-wrap">
-<div class="window-map" id="map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}">
-</div>
-<div id="map-content-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}"></div>
-</div>
-<script type="text/javascript">
-{% if PROFILE.experimental_feature %}
-{% include "ishtar/blocks/sheet_map.html" %}
-{% else %}
-var html = render_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", false, true);
-$("#map-content-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}").html(html);
-{% if geo_item.most_precise_geo == 'point' %}
-var {{geo_item.SLUG}}{{geo_item.pk}} = {{geo_item.point_2d_geojson|safe}};
-display_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", {{geo_item.SLUG}}{{geo_item.pk}});
-{% else %}
-var {{geo_item.SLUG}}{{geo_item.pk}} = {{geo_item.multi_polygon_geojson|safe}};
-display_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", null, {{geo_item.SLUG}}{{geo_item.pk}});
-{% endif %}
-{% endif %}
-</script>
-{% endif %}
-{% endif %}