diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-09-01 12:08:11 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:18 +0100 |
commit | d69e4e26fc10223ad4c2648b23b319902c16afb0 (patch) | |
tree | 3d9fc261943e56b46c70a9236713909b9761648d /ishtar_common/static | |
parent | b86863ff5ac6c3106ec8b243615becb983435b04 (diff) | |
download | Ishtar-d69e4e26fc10223ad4c2648b23b319902c16afb0.tar.bz2 Ishtar-d69e4e26fc10223ad4c2648b23b319902c16afb0.zip |
Geo: select geo item to display on the sheet
Diffstat (limited to 'ishtar_common/static')
-rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 40 |
1 files changed, 28 insertions, 12 deletions
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()); } }; |