diff options
Diffstat (limited to 'ishtar_common/static/js/ishtar-map.js')
-rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 40 |
1 files changed, 26 insertions, 14 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(); |