diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-09-01 12:08:11 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:18 +0100 |
commit | e0bcbeaa84c2adf3b8a179cdea792dd58fa109b2 (patch) | |
tree | 3d9fc261943e56b46c70a9236713909b9761648d | |
parent | a7acdf8ea0937321dc20e56d87abbe1fc6e240c6 (diff) | |
download | Ishtar-e0bcbeaa84c2adf3b8a179cdea792dd58fa109b2.tar.bz2 Ishtar-e0bcbeaa84c2adf3b8a179cdea792dd58fa109b2.zip |
Geo: select geo item to display on the sheet
12 files changed, 113 insertions, 135 deletions
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 @@ <div class='row'> {% with geo_item=item %} {% 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"%} - {% include "ishtar/blocks/sheet_geo_items.html"%} - </div> {% endwith %} </div> + <div class='row'> + {% field_flex_multiple_full "Towns" item.operation.towns %} + </div> {% endif %} <h3>{% trans "Sheet" %}</h3> 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 @@ <div class='row'> {% with geo_item=base_find %} {% 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 %} - </div> {% endwith %} </div> + <div class="row"> + {% field_flex_full "Point of topographic reference" base_find.topographic_localisation %} + </div> {% endif %} </div> 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 @@ <div class="row"> {% with geo_item=item %} {% include "ishtar/blocks/sheet_map.html"%} - <div class="col-12 col-lg-6 flex-wrap"> - {% 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 %} - </div> {% endwith %} </div> + <div class="row"> + {% 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 %} + </div> </div> {% 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 @@ <div class="row"> {% with geo_item=item %} {% include "ishtar/blocks/sheet_map.html"%} - - <div class="col-12 col-lg-6 flex-wrap"> - {% include "ishtar/blocks/sheet_coordinates.html"%} + {% endwith %} +</div> +<div class="row"> {% 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 "<pre>" "</pre>" %} {% field_flex_full "Cadastral locality" item.locality_cadastral "<pre>" "</pre>" %} - </div> - {% endwith %} </div> {% 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 @@ <div class='row'> {% with geo_item=item %} {% include "ishtar/blocks/sheet_map.html" %} - <div class="col-12 col-lg-6 flex-wrap"> - {% include "ishtar/blocks/sheet_coordinates.html" %} - </div> {% endwith %} </div> {% 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 @@ <div class='row'> {% with geo_item=item %} {% 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 %} - </div> {% endwith %} </div> + <div class="row"> + {% with full=True %}{% include "ishtar/blocks/sheet_address_section.html" %}{% endwith %} + </div> {% endif %} </div> 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("<pk>", properties["id"]); + var link = ""; + if (link_template[map_id]){ + link = link_template[map_id].replace("<pk>", properties["id"]); + } var txt = "<li>" + link + " " + properties['name'] + "</li>"; 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 %} -<dl class="col-12"> - <dt>{% trans "Coordinates" %}</dt> - <dd> - {% 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 %} - </dd> -</dl> -{% 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 %} -<dl class="col-12"> - <dt id="display-geo-items-for-{{geo_item.SLUG}}-{{geo_item.pk}}">{% trans "Display geo items" %}</dt> - <dd> - <fieldset> - {% if geo_item.SLUG == "operation" %} - <input type="checkbox" id="disp-cr-for-{{geo_item.SLUG}}-{{geo_item.pk}}" class='checkbox-geo-items'> - <label for="disp-cr-for-{{geo_item.SLUG}}-{{geo_item.pk}}">{% trans "Display context records" %}</label> - {% endif %} - <input type="checkbox" id="disp-bf-for-{{geo_item.SLUG}}-{{geo_item.pk}}" class='checkbox-geo-items'> - <label for="disp-bf-for-{{geo_item.SLUG}}-{{geo_item.pk}}">{% trans "Display base finds" %}</label> - </fieldset> - </dd> - <dd> - <label for="get-poly-for-{{geo_item.SLUG}}-{{geo_item.pk}}" id="get-poly-label-for-{{geo_item.SLUG}}-{{geo_item.pk}}">{% trans "Geometry: " %}</label> - <select id="get-poly-for-{{geo_item.SLUG}}-{{geo_item.pk}}" class='get-poly-geo-items'> - <option value="polygons" selected="selected">{% trans "Display polygons" %}</option> - <option value="points">{% trans "Display points" %}</option> - </select> - </dd> -</dl> -<script> -const hide_get_polygons = function() { - const disp_cr = $("#disp-cr-for-{{geo_item.SLUG}}-{{geo_item.pk}}"); - const disp_bf = $("#disp-bf-for-{{geo_item.SLUG}}-{{geo_item.pk}}"); - const get_poly = $("#get-poly-for-{{geo_item.SLUG}}-{{geo_item.pk}}"); - const label = $("#get-poly-label-for-{{geo_item.SLUG}}-{{geo_item.pk}}"); - get_poly.hide(); - label.hide(); - const display_get_poly = function () { - if (disp_bf.prop('checked') || ((disp_cr.length > 0) && disp_cr.prop('checked'))) { - get_poly.show(); - label.show(); - } else { - get_poly.hide(); - label.hide();} - } - if (disp_cr.length > 0) { - disp_cr.change( display_get_poly ); - } - disp_bf.change( display_get_poly ) -} -hide_get_polygons(); - -</script> -{% 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 %} <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> +<div class="col-12 col-lg-6 flex-wrap"> + <h4>{% trans "Geographic data" %}</h4> + <ul>{% for geodata in geodata_list %} + <li> + <input type="checkbox" name="map-ol-{{item.SLUG}}-{{item.pk}}-{{geodata.pk}}" + id="map-ol-{{item.SLUG}}-{{item.pk}}-{{geodata.pk}}" + {% if not forloop.counter0 %}checked{% endif %} + > + <label for="map-ol-{{item.SLUG}}-{{item.pk}}-{{geodata.pk}}"> + <strong>{{geodata.data_type}}</strong></label><br/> + {{geodata.name}} + </li>{% endfor %} + </ul> +</div> <script type="text/javascript"> -const disp_map = function() { +const refresh_map_{{item.SLUG}}_{{item.pk}} = function(first_init) { + var {{geo_item.SLUG}}{{geo_item.pk}}_point = {"type": "FeatureCollection", "features": []}; + var {{geo_item.SLUG}}{{geo_item.pk}}_other = {"type": "FeatureCollection", "features": []}; + {% for geodata in geodata_list %} + if ($("#map-ol-{{item.SLUG}}-{{item.pk}}-{{geodata.pk}}").prop('checked')){ + let geojson = {{geodata.geojson|safe}}; + {% if geodata.geometry_type == 'POINT' %} + Array.prototype.push.apply({{geo_item.SLUG}}{{geo_item.pk}}_point["features"], + geojson["features"]); + {% else %} + Array.prototype.push.apply({{geo_item.SLUG}}{{geo_item.pk}}_other["features"], + geojson["features"]); + {% endif %} + }{% endfor %} + display_lines_and_polys("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", {{geo_item.SLUG}}{{geo_item.pk}}_other, first_init); + display_points("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", {{geo_item.SLUG}}{{geo_item.pk}}_point, first_init); +} + +const display_map_{{item.SLUG}}_{{item.pk}} = 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); - 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 %} - display_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", null, {{geo_item.SLUG}}{{geo_item.pk}}); - {% endif %} + display_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", null, null); + {% for geodata in geodata_list %} + $("#map-ol-{{item.SLUG}}-{{item.pk}}-{{geodata.pk}}").change( + function(){ + refresh_map_{{item.SLUG}}_{{item.pk}}(false); + } + ); + {% endfor %} } -disp_map(); + +display_map_{{item.SLUG}}_{{item.pk}}(); +refresh_map_{{item.SLUG}}_{{item.pk}}(true); + {% if geo_item.SLUG == "operation" or geo_item.SLUG == "contextrecord" %} const disp_geo_items = function(disp_cr, disp_bf, get_polygons) { @@ -69,4 +107,5 @@ get_polygons.change( function () { {% endif %} </script> +{% endwith %} {% endif %} |