diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models_common.py | 10 | ||||
-rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 40 | ||||
-rw-r--r-- | ishtar_common/templates/base.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/sheet_coordinates.html | 28 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/sheet_geo_items.html | 48 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/sheet_map.html | 57 |
6 files changed, 88 insertions, 97 deletions
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 %} |