diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-09-09 16:17:47 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:18 +0100 |
commit | 50c15f91626b0f2e2a564ddf9eba1e3abdc78b09 (patch) | |
tree | accfa612be208535b7c0d4872f6648318a7945a9 /ishtar_common/static/js | |
parent | 63d58db063173e1068b7619e6c569f497ec7a083 (diff) | |
download | Ishtar-50c15f91626b0f2e2a564ddf9eba1e3abdc78b09.tar.bz2 Ishtar-50c15f91626b0f2e2a564ddf9eba1e3abdc78b09.zip |
Geo: display lines and polygons on search
Diffstat (limited to 'ishtar_common/static/js')
-rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 9 | ||||
-rw-r--r-- | ishtar_common/static/js/ishtar.js | 53 |
2 files changed, 53 insertions, 9 deletions
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js index 67d29cc48..e2090eec6 100644 --- a/ishtar_common/static/js/ishtar-map.js +++ b/ishtar_common/static/js/ishtar-map.js @@ -58,12 +58,16 @@ var _map_submit_search = function(query_vars, name, source, extra){ url += "&limit=" + current_map_limit; use_map_limit = true; } + var display_polygons = false; + if(data.indexOf("display_polygon=true") != -1){ + display_polygons = true; + } $.getJSON(url, function(data) { var timestamp = Math.floor(Date.now() / 1000); var map_id = "map-" + extra + "-" + timestamp; $('.modal-progress .modal-header').html("{% trans 'Render map...' %}"); - var html = render_map(map_id, use_map_limit); + var html = render_map(map_id, use_map_limit, false, display_polygons); $("#tab-content-map-" + name + " #map-" + name + "-" + extra).html(html); $("#id_" + name + "-length_map").change(map_submit_search); if ($('.modal-progress').length > 0){ @@ -716,7 +720,8 @@ var display_map = function(map_id, points, lines_and_polys, layers){ } else { initialize_base_map(map_id, layers); } - display_points(map_id, points, true); + if (lines_and_polys) display_lines_and_polys(map_id, lines_and_polys, true); + if (points) display_points(map_id, points, true); init_popup(map_id); diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index b865c7153..e59ce4f2c 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -1384,14 +1384,16 @@ var render_map_list_modal = function(map_id){ }; var limit_map_msg = "Limit to {0} items"; +var display_poly_map_msg = "Display lines, polygons"; var limit_map_help_msg = "Unchecking this limit on a poorly performing device may result in web browser freeze"; var limit_map_nb = 50000; var current_map_limit = limit_map_nb; +var display_polygon_on_map = false; var displayed_map_msg = "{0} items displayed on the map"; var non_displayed_map_msg = "{0} items not displayed"; var non_displayed_map_link_msg = "(list)"; -var render_map = function(map_id, use_map_limit, hide_limit){ +var render_map = function(map_id, use_map_limit, hide_limit, display_polygons){ var html = ""; if (!hide_limit){ html += "<div class='ishtar-map-top row'>"; @@ -1403,6 +1405,14 @@ var render_map = function(map_id, use_map_limit, hide_limit){ html += "<label class='form-check-label' for='ishtar-map-limit-" + map_id + "'>"; html += limit_map_msg.format(number_with_commas(limit_map_nb)); html += " <i class='fa fa-question-circle' title=\""+ limit_map_help_msg +"\" aria-hidden='true'></i></label>"; + html += "</div>"; + html += "<div class='ishtar-map-limit col-sm form-check'>"; + html += "<input class='form-check-input' type='checkbox' id='ishtar-map-poly-" + map_id + "' "; + if (display_polygons) html += " checked='checked'"; + html += "/> "; + html += "<label class='form-check-label' for='ishtar-map-poly-" + map_id + "'>"; + html += display_poly_map_msg; + html += " </label>"; html += "</div></div>"; } @@ -1415,8 +1425,21 @@ var render_map = function(map_id, use_map_limit, hide_limit){ var no_geo_window_content = ""; -var register_map = function(map_id, points){ - display_map(map_id, points); +var register_map = function(map_id, result){ + let points = {}; + Object.assign(points, result); + points["features"] = new Array(); + let line_and_polys = {}; + Object.assign(line_and_polys, result); + line_and_polys["features"] = new Array(); + for (const feature of result["features"]){ + if (feature["geometry"] && feature["geometry"]["type"] === "Point"){ + points["features"].push(feature); + } else { + line_and_polys["features"].push(feature); + } + } + display_map(map_id, points, line_and_polys); $('#ishtar-map-limit-' + map_id).change(function() { if ($(this).prop('checked')) { current_map_limit = limit_map_nb; @@ -1425,6 +1448,14 @@ var register_map = function(map_id, points){ } $(".search_button").click(); }); + $('#ishtar-map-poly-' + map_id).change(function() { + if ($(this).prop('checked')) { + display_polygon_on_map = true; + } else { + display_polygon_on_map = false; + } + $(".search_button").click(); + }); if (points){ var lbl = ""; if (points['features'].length){ @@ -1493,10 +1524,18 @@ var search_get_query_data = function(query_vars, table_name){ if (data) data += "&"; data += "start=" + ((current_image_page - 1) * $(id_select).val()); } - if (current_tab == "map" && !current_map_limit){ - if (data) data += "&"; - data += "no_limit=true"; + if (current_tab == "map"){ + if (!current_map_limit){ + if (data) data += "&"; + data += "no_limit=true"; + } + if (display_polygon_on_map){ + if (data) data += "&"; + data += "display_polygon=true"; + } } + + return data; }; @@ -1919,4 +1958,4 @@ var redraw_plots = function(name, key){ $('#chart-' + name + "-" + key).width($('#charts-' + name + "-" + key).width()* 0.96); stats_current_graph[key].replot({resetAxes: true}); } -};
\ No newline at end of file +}; |