diff options
Diffstat (limited to 'ishtar_common/templates/ishtar/blocks/sheet_map.html')
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/sheet_map.html | 98 |
1 files changed, 29 insertions, 69 deletions
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_map.html b/ishtar_common/templates/ishtar/blocks/sheet_map.html index 16e014b49..11780ae8a 100644 --- a/ishtar_common/templates/ishtar/blocks/sheet_map.html +++ b/ishtar_common/templates/ishtar/blocks/sheet_map.html @@ -10,6 +10,7 @@ <ul>{% for geodata in geodata_list %} <li> <input type="checkbox" name="map-ol-{{item.SLUG}}-{{item.pk}}-{{geodata.pk}}" + class="map-ol-{{item.SLUG}}-{{item.pk}}" id="map-ol-{{item.SLUG}}-{{item.pk}}-{{geodata.pk}}" {% if not forloop.counter0 %}checked{% endif %} > @@ -17,95 +18,54 @@ <strong>{{geodata.data_type}}</strong></label><br/> {{geodata.name}} </li>{% endfor %} + {% if geo_item.SLUG == "operation" %} + <li> + <input type="checkbox" name="map-ol-{{item.SLUG}}-{{item.pk}}-crs" + class="map-ol-{{item.SLUG}}-{{item.pk}}" + id="map-ol-{{item.SLUG}}-{{item.pk}}-crs"> + <label for="map-ol-{{item.SLUG}}-{{item.pk}}-crs"> + <strong>{% trans "Associated context records" %}</strong></label> + </li> + {% endif %} + {% if geo_item.SLUG == "operation" or geo_item.SLUG == "contextrecord" %} + <li> + <input type="checkbox" name="map-ol-{{item.SLUG}}-{{item.pk}}-finds" + class="map-ol-{{item.SLUG}}-{{item.pk}}" + id="map-ol-{{item.SLUG}}-{{item.pk}}-finds"> + <label for="map-ol-{{item.SLUG}}-{{item.pk}}-finds"> + <strong>{% trans "Associated finds" %}</strong></label> + </li> + {% endif %} </ul> </div> <script type="text/javascript"> - 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); + let idx = "{{item.SLUG}}-{{item.pk}}"; + let geodata_list = { {% for geodata in geodata_list %} + "{{item.SLUG}}-{{item.pk}}-{{geodata.pk}}": ["{{geodata.geometry_type}}", {{geodata.geojson|safe}}]{% if not forloop.last %},{% endif %} + {% endfor %} }; + let url{% if geo_item.SLUG == "operation" or geo_item.SLUG == "contextrecord" %} = "{% url 'api-get-geo' %}"{% endif %}; + let attrs{% if geo_item.SLUG == "operation" %} = {"operation_id": "{{geo_item.pk}}"}{% elif geo_item.SLUG == "contextrecord" %} = {"context_record_id": "{{geo_item.pk}}"}{% endif %}; + refresh_map(idx, geodata_list, url, attrs); + display_lines_and_polys("map-{{window_id}}-" + idx, _geo_other[idx], first_init); + display_points("map-{{window_id}}-" + idx, _geo_points[idx], 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); 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( + $(".map-ol-{{item.SLUG}}-{{item.pk}}").change( function(){ refresh_map_{{item.SLUG}}_{{item.pk}}(false); } ); - {% endfor %} } 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) { - if (disp_cr || disp_bf) { - const get_poly = (get_polygons === "polygons"); - let url = null; - if (get_poly) { - url = "{% url 'api-get-geo-polygons' %}"; - } - else { - url = "{% url 'api-get-geo-points' %}"; - } - display_geo_items("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", url, "{{geo_item.SLUG}}", - "{{geo_item.pk}}", disp_cr, disp_bf, get_poly); - } -} -let geo_items_displayed_once = false; -const disp_bf = $("#disp-bf-for-{{geo_item.SLUG}}-{{geo_item.pk}}"); -const get_polygons = $("#get-poly-for-{{geo_item.SLUG}}-{{geo_item.pk}}"); - -{% if geo_item.SLUG == "operation" %} -const disp_cr = $("#disp-cr-for-{{geo_item.SLUG}}-{{geo_item.pk}}"); -const event_func_disp_geo_items = function () { - if (geo_items_displayed_once) { - disp_map(); - } - else { geo_items_displayed_once = true; } - disp_geo_items(disp_cr.prop('checked'), disp_bf.prop('checked'), get_polygons.val()); -} -disp_cr.change( event_func_disp_geo_items ); -disp_bf.change( event_func_disp_geo_items ); -get_polygons.change( function () { - disp_map(); - disp_geo_items(disp_cr.prop('checked'), disp_bf.prop('checked'), get_polygons.val()); -}) -{% else %} -const event_func_disp_geo_items = function () { - if (geo_items_displayed_once) { - disp_map(); - } - else { geo_items_displayed_once = true; } - disp_geo_items(false, disp_bf.prop('checked'), get_polygons.val()); -} -disp_bf.change( event_func_disp_geo_items ); -get_polygons.change( function () { - disp_map(); - disp_geo_items(false, disp_bf.prop('checked'), get_polygons.val()); -}) -{% endif %} -{% endif %} - </script> {% endwith %} {% endif %} |