summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-09-10 18:09:22 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:18 +0100
commit0581887d6b27dd5aab1e7580a513bb4ea5a87b99 (patch)
treed9431fccf5508b2b3fb30b77eba2a065c0c74d8e
parent50c15f91626b0f2e2a564ddf9eba1e3abdc78b09 (diff)
downloadIshtar-0581887d6b27dd5aab1e7580a513bb4ea5a87b99.tar.bz2
Ishtar-0581887d6b27dd5aab1e7580a513bb4ea5a87b99.zip
Geo: fix zoom to extent - fix item counts
-rw-r--r--ishtar_common/static/js/ishtar-map.js40
-rw-r--r--ishtar_common/static/js/ishtar.js32
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_map.html5
3 files changed, 44 insertions, 33 deletions
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index e2090eec6..c21cd890e 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -720,9 +720,9 @@ var display_map = function(map_id, points, lines_and_polys, layers){
} else {
initialize_base_map(map_id, layers);
}
- if (lines_and_polys) display_lines_and_polys(map_id, lines_and_polys, true);
- if (points) display_points(map_id, points, true);
-
+ if (lines_and_polys) display_lines_and_polys(map_id, lines_and_polys);
+ if (points) display_points(map_id, points);
+ zoom_to_extent(map_id);
init_popup(map_id);
map[map_id].on('click', manage_click_on_map(map_id));
@@ -733,7 +733,7 @@ var display_map = function(map_id, points, lines_and_polys, layers){
}
};
-var display_points = function(map_id, points, first_init){
+var display_points = function(map_id, points){
if (!points) return;
point_features[map_id] = geojson_format.readFeatures(points);
if (!cluster_source[map_id]){
@@ -742,15 +742,9 @@ var display_points = function(map_id, points, first_init){
reinit_clustering(map_id);
}
cluster_source[map_id].getSource().addFeatures(point_features[map_id]);
- 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() > 14){
- map_view[map_id].setZoom(14);
- }
- }
};
-var display_lines_and_polys = function(map_id, lines_and_polys, first_init){
+var display_lines_and_polys = function(map_id, lines_and_polys){
if (!lines_and_polys) return;
vector_features[map_id] = geojson_format.readFeatures(lines_and_polys);
if (!vector_source[map_id]){
@@ -766,11 +760,29 @@ var display_lines_and_polys = function(map_id, lines_and_polys, first_init){
});
map[map_id].addLayer(vector_layer[map_id]);
- if (first_init && lines_and_polys.features && lines_and_polys.features.length){
- map_view[map_id].fit(vector_source[map_id].getExtent());
- }
};
+var zoom_to_extent = function(map_id){
+ let extent;
+ if (cluster_source[map_id]) extent = cluster_source[map_id].getSource().getExtent();
+ if (vector_source[map_id]){
+ let vector_extent = vector_source[map_id].getExtent();
+ if (vector_extent){
+ if (extent){
+ ol.extent.extend(extent, vector_extent);
+ } else {
+ extent = vector_extent;
+ }
+ }
+ }
+ if (extent) {
+ map_view[map_id].fit(extent);
+ if (map_view[map_id].getZoom() > 14){
+ map_view[map_id].setZoom(14);
+ }
+ }
+}
+
var _geo_points = new Array();
var _geo_other = new Array();
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js
index e59ce4f2c..2a2b4fa9f 100644
--- a/ishtar_common/static/js/ishtar.js
+++ b/ishtar_common/static/js/ishtar.js
@@ -1456,29 +1456,27 @@ var register_map = function(map_id, result){
}
$(".search_button").click();
});
- if (points){
- var lbl = "";
- if (points['features'].length){
- lbl += displayed_map_msg.format(
- number_with_commas(points['features'].length)
- );
- }
- if (points['no-geo'].length){
- if (points['features'].length){
- lbl += " - ";
+ if (points || line_and_polys){
+ let lbl = "";
+ let feature_nb = 0;
+ if (points && points['features'].length) feature_nb = points['features'].length;
+ if (line_and_polys && line_and_polys['features'].length) feature_nb += line_and_polys['features'].length;
+
+ if (feature_nb > 0) lbl += displayed_map_msg.format(number_with_commas(feature_nb));
+ if (result['no-geo'].length){
+ if (lbl != ""){
+ lbl += "<br>";
}
- lbl += non_displayed_map_msg.format(
- number_with_commas(points['no-geo'].length)
- );
+ lbl += non_displayed_map_msg.format(number_with_commas(result['no-geo'].length));
lbl += " <a href='#' id='no-geo-" + map_id + "'>" + non_displayed_map_link_msg + "</a>";
}
$("#ishtar-map-info-" + map_id).html(lbl);
no_geo_window_content = "<ul>";
- for (var idx in points['no-geo']){
- no_geo = points['no-geo'][idx];
- var link = link_template[map_id].replace("<pk>", no_geo["id"]);
- var txt = "<li>" + link + " " + no_geo['name'] + "</li>";
+ for (const idx in result['no-geo']){
+ no_geo = result['no-geo'][idx];
+ let link = link_template[map_id].replace("<pk>", no_geo["id"]);
+ let txt = "<li>" + link + " " + no_geo['name'] + "</li>";
no_geo_window_content += txt;
}
no_geo_window_content += "</ul>";
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_map.html b/ishtar_common/templates/ishtar/blocks/sheet_map.html
index 4a380ed13..954a7337d 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_map.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_map.html
@@ -47,8 +47,9 @@ const refresh_map_{{geo_item.SLUG}}_{{geo_item.pk}} = function(first_init) {
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);
+ display_lines_and_polys("map-{{window_id}}-" + idx, _geo_other[idx]);
+ display_points("map-{{window_id}}-" + idx, _geo_points[idx]);
+ if (first_init) zoom_to_extent("map-{{window_id}}-" + idx);
}
const display_map_{{geo_item.SLUG}}_{{geo_item.pk}} = function() {