From e0bcbeaa84c2adf3b8a179cdea792dd58fa109b2 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 1 Sep 2022 12:08:11 +0200 Subject: Geo: select geo item to display on the sheet --- .../templates/ishtar/sheet_contextrecord.html | 8 ++- .../templates/ishtar/sheet_basefind.html | 7 ++- .../templates/ishtar/sheet_operation.html | 30 +++++------- .../templates/ishtar/sheet_site.html | 8 ++- .../templates/ishtar/sheet_container.html | 3 -- .../templates/ishtar/sheet_warehouse.html | 7 ++- ishtar_common/models_common.py | 10 ++++ ishtar_common/static/js/ishtar-map.js | 40 ++++++++++----- ishtar_common/templates/base.html | 2 + .../templates/ishtar/blocks/sheet_coordinates.html | 28 ----------- .../templates/ishtar/blocks/sheet_geo_items.html | 48 ------------------ .../templates/ishtar/blocks/sheet_map.html | 57 ++++++++++++++++++---- 12 files changed, 113 insertions(+), 135 deletions(-) delete mode 100644 ishtar_common/templates/ishtar/blocks/sheet_coordinates.html delete mode 100644 ishtar_common/templates/ishtar/blocks/sheet_geo_items.html diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index 7eb5b4a29..acc131e88 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -168,13 +168,11 @@
{% with geo_item=item %} {% include "ishtar/blocks/sheet_map.html"%} -
- {% field_flex_multiple_full "Towns" item.operation.towns %} - {% include "ishtar/blocks/sheet_coordinates.html"%} - {% include "ishtar/blocks/sheet_geo_items.html"%} -
{% endwith %}
+
+ {% field_flex_multiple_full "Towns" item.operation.towns %} +
{% endif %}

{% trans "Sheet" %}

diff --git a/archaeological_finds/templates/ishtar/sheet_basefind.html b/archaeological_finds/templates/ishtar/sheet_basefind.html index 225d8ee83..81705aaae 100644 --- a/archaeological_finds/templates/ishtar/sheet_basefind.html +++ b/archaeological_finds/templates/ishtar/sheet_basefind.html @@ -74,12 +74,11 @@
{% with geo_item=base_find %} {% include "ishtar/blocks/sheet_map.html"%} -
- {% include "ishtar/blocks/sheet_coordinates.html"%} - {% field_flex_full "Point of topographic reference" base_find.topographic_localisation %} -
{% endwith %}
+
+ {% field_flex_full "Point of topographic reference" base_find.topographic_localisation %} +
{% endif %} diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index f884ed435..b868185df 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -302,25 +302,21 @@
{% with geo_item=item %} {% include "ishtar/blocks/sheet_map.html"%} -
- {% include "ishtar/blocks/sheet_coordinates.html"%} - {% if next %} - {% field_flex_full "Towns" item|m2m_listing:'towns'|join:" ; " %} - {% else %} - {{ item.cached_towns_label }} - {% endif %} - {% field_flex "Address" item.address %} - {% if not item.address %} - {% field_flex "Main address" item.associated_file.address %} - {% field_flex "Complement" item.associated_file.address_complement %} - {% field_flex "Postal code" item.associated_file.postal_code %} - {% endif %} - {% if PROFILE.experimental_feature %} - {% include "ishtar/blocks/sheet_geo_items.html"%} - {% endif %} -
{% endwith %}
+
+ {% if next %} + {% field_flex "Towns" item|m2m_listing:'towns'|join:" ; " %} + {% else %} + {% field_flex "Towns" item.cached_towns_label %} + {% endif %} + {% field_flex "Address" item.address %} + {% if not item.address %} + {% field_flex "Main address" item.associated_file.address %} + {% field_flex "Complement" item.associated_file.address_complement %} + {% field_flex "Postal code" item.associated_file.postal_code %} + {% endif %} +
{% if display_sites %} diff --git a/archaeological_operations/templates/ishtar/sheet_site.html b/archaeological_operations/templates/ishtar/sheet_site.html index b5401c9fb..a3ddb38bf 100644 --- a/archaeological_operations/templates/ishtar/sheet_site.html +++ b/archaeological_operations/templates/ishtar/sheet_site.html @@ -69,9 +69,9 @@
{% with geo_item=item %} {% include "ishtar/blocks/sheet_map.html"%} - -
- {% include "ishtar/blocks/sheet_coordinates.html"%} + {% endwith %} +
+
{% if next %} {% field_flex_full "Towns" item|m2m_listing:'towns'|join:" ; " %} {% else %} @@ -79,8 +79,6 @@ {% endif %} {% field_flex_full "National Geographic Institute locality" item.locality_ngi "
" "
" %} {% field_flex_full "Cadastral locality" item.locality_cadastral "
" "
" %} -
- {% endwith %}
{% endif %} diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html index a6a1e279b..3cc03cad1 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_container.html +++ b/archaeological_warehouse/templates/ishtar/sheet_container.html @@ -153,9 +153,6 @@
{% with geo_item=item %} {% include "ishtar/blocks/sheet_map.html" %} -
- {% include "ishtar/blocks/sheet_coordinates.html" %} -
{% endwith %}
{% endif %} diff --git a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html index e03feb026..4f4cfd6ba 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html +++ b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html @@ -103,12 +103,11 @@
{% with geo_item=item %} {% 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 %} -
{% endwith %}
+
+ {% with full=True %}{% include "ishtar/blocks/sheet_address_section.html" %}{% endwith %} +
{% endif %} diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 221fa3ede..83897768c 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2545,6 +2545,16 @@ class GeographicItem(models.Model): self.main_geodata = self.geodata.order_by("pk").all()[0] self.save() + @property + def geodata_list(self): + lst = [] + if self.main_geodata: + lst.append(self.main_geodata) + for geo in self.geodata.all(): + if geo != self.main_geodata: + lst.append(geo) + return lst + class TownManager(models.Manager): def get_by_natural_key(self, numero_insee, year): diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js index a3f275720..95f8ad3e3 100644 --- a/ishtar_common/static/js/ishtar-map.js +++ b/ishtar_common/static/js/ishtar-map.js @@ -29,6 +29,8 @@ var geoloc_activated = {}; var fetching_msg = "Fetching data..."; +var base_maps_msg = "Base maps"; + var _map_submit_search = function(query_vars, name, source, extra){ if (!extra) extra = "default"; var modal_base_text = $('.modal-progress .modal-header').html(); @@ -523,7 +525,10 @@ var _display_items = function(map_id, features, offset_x, offset_y){ } var feat = features[idx_feat]; var properties = feat.getProperties(); - var link = link_template[map_id].replace("", properties["id"]); + var link = ""; + if (link_template[map_id]){ + link = link_template[map_id].replace("", properties["id"]); + } var txt = "
  • " + link + " " + properties['name'] + "
  • "; window_content += txt; if (idx_feat < 5){ @@ -623,7 +628,7 @@ var initialize_base_map = function(map_id, layers){ map_layers[map_id] = [ new ol.layer.Group({ - title: 'Base maps', + title: base_maps_msg, visible: true, layers: get_layers(layers) }) @@ -677,7 +682,7 @@ var display_map = function(map_id, points, lines_and_polys, layers){ if (points){ link_template[map_id] = points['link_template']; - } else { + } else if (lines_and_polys) { link_template[map_id] = lines_and_polys['link_template']; } if (map[map_id]){ @@ -686,7 +691,6 @@ var display_map = function(map_id, points, lines_and_polys, layers){ initialize_base_map(map_id, layers); } display_points(map_id, points); - display_lines_and_polys(map_id, lines_and_polys); init_popup(map_id); @@ -698,31 +702,43 @@ var display_map = function(map_id, points, lines_and_polys, layers){ } }; -var display_points = function(map_id, points){ +var display_points = function(map_id, points, first_init){ if (!points) return; point_features[map_id] = geojson_format.readFeatures(points); - enable_clustering(map_id); + console.log(708); + if (!cluster_source[map_id]){ + enable_clustering(map_id); + } else { + cluster_source[map_id].getSource().clear(); + cluster_source[map_id].getSource().refresh(); + } cluster_source[map_id].getSource().addFeatures(point_features[map_id]); - if (points.features.length){ + if (first_init && points.features && points.features.length){ map_view[map_id].fit(cluster_source[map_id].getSource().getExtent()); - if (map_view[map_id].getZoom() > 12){ - map_view[map_id].setZoom(12); + if (map_view[map_id].getZoom() > 14){ + map_view[map_id].setZoom(14); } } }; -var display_lines_and_polys = function(map_id, lines_and_polys){ +var display_lines_and_polys = function(map_id, lines_and_polys, first_init){ if (!lines_and_polys) return; vector_features[map_id] = geojson_format.readFeatures(lines_and_polys); - vector_source[map_id] = new ol.source.Vector(); + if (!vector_source[map_id]){ + vector_source[map_id] = new ol.source.Vector(); + } else { + vector_source[map_id].clear(); + vector_source[map_id].refresh(); + } vector_source[map_id].addFeatures(vector_features[map_id]); vector_layer[map_id] = new ol.layer.Vector({ source: vector_source[map_id], style: get_vector_style }); + console.log(738); map[map_id].addLayer(vector_layer[map_id]); - if (lines_and_polys.features.length){ + if (first_init && lines_and_polys.features && lines_and_polys.features.length){ map_view[map_id].fit(vector_source[map_id].getExtent()); } }; diff --git a/ishtar_common/templates/base.html b/ishtar_common/templates/base.html index 8041452c6..12e8567a1 100644 --- a/ishtar_common/templates/base.html +++ b/ishtar_common/templates/base.html @@ -73,6 +73,8 @@ var YES = "{% trans 'yes' %}"; var NO = "{% trans 'no' %}"; var fetching_msg = "{% trans 'Fetching data...' %}"; + var base_maps_msg = "{% trans 'Base maps' %}"; + var layers_msg = "{% trans 'Layers' %}"; var stats_incompatible_modality = "{% trans 'This graph type accept only one modality.' %}"; var show_msg = "{% trans "Show" %}"; var entries_msg = "{% trans "entries" %}"; diff --git a/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html b/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html deleted file mode 100644 index 0093ed31f..000000000 --- a/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html +++ /dev/null @@ -1,28 +0,0 @@ -{% load i18n window_field %}{% if PROFILE.mapping and geo_item.main_geodata %} -{% with geodata=geo_item.main_geodata %} -{% if geodata.cached_x or geodata.cached_z %} -
    -
    {% trans "Coordinates" %}
    -
    - {% with coordinates=geodata.display_coordinates %} - {% trans "X:"%} {{coordinates.0|default_if_none:"-"}} - {% if geodata.estimated_error_x %} ({% trans "error:" %} {{geodata.estimated_error_x}}){% endif %}, - {% trans "Y:"%} {{coordinates.1|default_if_none:"-"}} - {% if geodata.estimated_error_y %} ({% trans "error:" %} {{geodata.estimated_error_y}}){% endif %}, - {% endwith %} - {% trans "Z:"%} {{geodata.z|default_if_none:"-"}} - {% if geodata.estimated_error_z %} ({% trans "error:" %} {{geodata.estimated_error_z}}){% endif %} - {% with srs=geodata.display_spatial_reference_system %} - {% if srs %} – {{srs.label}} - {% trans "SRID"%} {{srs.srid}} {% endif %} - {% endwith %} -
    -
    -{% field_flex_full "Data type" geodata.data_type %} -{% field_flex_full "Source" geodata.source_label %} -{% field_flex_full "Name" geodata.name %} -{% field_flex_full "Origin" geodata.origin %} -{% field_flex_full "Provider" geodata.provider %} -{% field_flex_full "Comment" geodata.comment %} -{% endif %} -{% endwith %} -{% endif %} diff --git a/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html b/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html deleted file mode 100644 index 12e4b4ef0..000000000 --- a/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html +++ /dev/null @@ -1,48 +0,0 @@ -{% load i18n window_field %}{% if PROFILE.mapping %} -{% if geo_item.point_2d or geo_item.multi_polygon %} -
    -
    {% trans "Display geo items" %}
    -
    -
    - {% if geo_item.SLUG == "operation" %} - - - {% endif %} - - -
    -
    -
    - - -
    -
    - -{% endif %} -{% endif %} \ No newline at end of file diff --git a/ishtar_common/templates/ishtar/blocks/sheet_map.html b/ishtar_common/templates/ishtar/blocks/sheet_map.html index e0278b8c7..16e014b49 100644 --- a/ishtar_common/templates/ishtar/blocks/sheet_map.html +++ b/ishtar_common/templates/ishtar/blocks/sheet_map.html @@ -1,22 +1,60 @@ -{% if PROFILE.mapping and geo_item.main_geodata %} +{% load i18n window_field %}{% if PROFILE.mapping and geo_item.main_geodata %} +{% with geodata_list=geo_item.geodata_list %}
    +
    +

    {% trans "Geographic data" %}

    +
      {% for geodata in geodata_list %} +
    • + +  
      + {{geodata.name}} +
    • {% endfor %} +
    +
    +{% endwith %} {% endif %} -- cgit v1.2.3