diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 9 | ||||
-rw-r--r-- | ishtar_common/static/js/ishtar.js | 53 | ||||
-rw-r--r-- | ishtar_common/templates/base.html | 1 | ||||
-rw-r--r-- | ishtar_common/version.py | 4 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 67 |
5 files changed, 105 insertions, 29 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 +}; diff --git a/ishtar_common/templates/base.html b/ishtar_common/templates/base.html index 12e8567a1..3fa049215 100644 --- a/ishtar_common/templates/base.html +++ b/ishtar_common/templates/base.html @@ -90,6 +90,7 @@ var geoloc_activated_msg = "{% trans "Geolocation activated" %}"; var geoloc_disabled_msg = "{% trans "Geolocation disabled" %}"; var limit_map_msg = "{% trans "Limit to {0} items" %}"; + var display_poly_map_msg = "{% trans "Display lines, polygons" %}"; var limit_map_help_msg = "{% trans "Unchecking this limit on a poorly performing device may result in web browser freeze" %}"; var displayed_map_msg = "{% trans "{0} items displayed on the map" %}"; var non_displayed_map_msg = "{% trans "{0} items not displayed" %}"; diff --git a/ishtar_common/version.py b/ishtar_common/version.py index 078a6a72c..ace27fa8a 100644 --- a/ishtar_common/version.py +++ b/ishtar_common/version.py @@ -1,5 +1,5 @@ -# 4.0.15 -VERSION = (4, 0, 15) +# 4.0.16 +VERSION = (4, 0, 16) def get_version(): diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index d06613b19..b8cc24fb4 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -1337,7 +1337,7 @@ def _format_val(val): return str(val) -def _format_geojson(rows, link_template): +def _format_geojson(rows, link_template, display_polygon): data = { "type": "FeatureCollection", "crs": {"type": "name", "properties": {"name": "EPSG:4326"}}, @@ -1347,23 +1347,45 @@ def _format_geojson(rows, link_template): } if not rows: return data + """ + Columns: + base: ['id', 'cached_label', 'main_geodata__cached_x', + 'main_geodata__cached_y', 'point_x', 'point_y', + 'locked', 'lock_user_id'] + poly: ['id', 'cached_label', 'main_geodata__cached_x', + 'main_geodata__cached_y', + 'main_geodata__multi_line', 'main_geodata__multi_polygon', + 'point_x', 'point_y', + 'locked', 'lock_user_id'] + """ + delta = 2 if display_polygon else 0 for row in rows: - feat = {"id": row[0], "name": row[1]} - x, y = row[2], row[3] - if not x or not y or x < -180 or x > 180 or y < -90 or y > 90: - data["no-geo"].append(feat) - continue - feature = { + properties = {"id": row[0], "name": row[1]} + feature = None + base_feature = { "type": "Feature", - "properties": feat, - "geometry": {"type": "Point", "coordinates": [x, y]}, + "properties": properties, } + if display_polygon: + if row[4]: # lines + feature = base_feature + feature["geometry"] = json.loads(row[4].geojson) + elif row[5]: # polygons + feature = base_feature + feature["geometry"] = json.loads(row[5].geojson) + if not feature: + x, y = row[4 + delta], row[5 + delta] + if not x or not y or x < -180 or x > 180 or y < -90 or y > 90: + data["no-geo"].append(properties) + continue + feature = base_feature + feature["geometry"] = {"type": "Point", "coordinates": [x, y]} data["features"].append(feature) return data def _get_data_from_query(items, query_table_cols, extra_request_keys, - point_fields=None): + geo_fields=None): # TODO: manage data json field for query_keys in query_table_cols: if not isinstance(query_keys, (tuple, list)): @@ -1381,21 +1403,21 @@ def _get_data_from_query(items, query_table_cols, extra_request_keys, query_key.replace(".", "__") # class style to query values = ["id"] + query_table_cols - if point_fields: + if geo_fields: profile = get_current_profile() precision = profile.point_precision if precision is not None: exp_x = ExpressionWrapper( - Round(point_fields[0], precision), + Round(geo_fields[0], precision), output_field=FloatField(), ) exp_y = ExpressionWrapper( - Round(point_fields[1], precision), + Round(geo_fields[1], precision), output_field=FloatField(), ) else: - exp_x = F(point_fields[0]) - exp_y = F(point_fields[1]) + exp_x = F(geo_fields[0]) + exp_y = F(geo_fields[1]) items = items.annotate(point_x=exp_x) items = items.annotate(point_y=exp_y) values += ["point_x", "point_y"] @@ -1797,6 +1819,9 @@ def get_item( data_type == "json-map" and request_items.get("no_limit", False) ): row_nb = None + display_polygon = False + if data_type == "json-map" and request_items.get("display_polygon", False): + display_polygon = True dct_request_items = {} @@ -2105,6 +2130,9 @@ def get_item( base_query_key + "cached_y"] table_cols += [base_query_key + "cached_x", base_query_key + "cached_y"] + if display_polygon: + query_table_cols += [base_query_key + "multi_line", + base_query_key + "multi_polygon"] # manage sort tables manual_sort_key = None @@ -2194,10 +2222,13 @@ def get_item( items = [item.get_previous(old) for item in items] if data_type == "json-map": - point_fields = query_table_cols[-2:] + if display_polygon: + geo_fields = query_table_cols[-4:] + else: + geo_fields = query_table_cols[-2:] datas = _get_data_from_query( items, query_table_cols, my_extra_request_keys, - point_fields=point_fields + geo_fields=geo_fields ) elif data_type != "csv" and getattr(model, "NEW_QUERY_ENGINE", False): datas = _get_data_from_query(items, query_table_cols, my_extra_request_keys) @@ -2262,7 +2293,7 @@ def get_item( lnk = lnk.replace("999999", "<pk>") if not has_locks: lnk = lnk.replace("<lock>", "") - data = json.dumps(_format_geojson(datas, lnk)) + data = json.dumps(_format_geojson(datas, lnk, display_polygon)) return HttpResponse(data, content_type="application/json") for data in datas: res = { |