diff options
-rw-r--r-- | CHANGES.md | 5 | ||||
-rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 39 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/sheet_map.html | 5 |
3 files changed, 18 insertions, 31 deletions
diff --git a/CHANGES.md b/CHANGES.md index 18be7cbaa..84488897b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,8 +1,11 @@ --- title: Ishtar changelog -date: 2022-10-17 +date: 2022-10-19 --- +### Features ### +- Geo data: zoom to extent + v4.0.22 - 2022-10-14 -------------------- diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js index 2fce7f6e6..394b27feb 100644 --- a/ishtar_common/static/js/ishtar-map.js +++ b/ishtar_common/static/js/ishtar-map.js @@ -892,20 +892,7 @@ const refresh_map = function(idx, geodata_list, url, attrs) { ol.proj.transform(geojson["features"][0]["geometry"]["coordinates"], 'EPSG:4326', 'EPSG:3857'), 1000 ).getExtent(); - _geo_extents[key] = new ol.geom.Circle( - geojson["features"][0]["geometry"]["coordinates"], - 0.01 - ).getExtent(); - _geo_extents[key] = [parseFloat(_geo_extents[key][0]), - parseFloat(_geo_extents[key][1]), - parseFloat(_geo_extents[key][2]), - parseFloat(_geo_extents[key][3])]; - // console.log(key); - // console.log(_geo_extents[key]); - // console.log(_geo_extents[key][0]); register_zoom_on_map("#map-zoom-" + key); - - } } else { Array.prototype.push.apply( @@ -913,21 +900,18 @@ const refresh_map = function(idx, geodata_list, url, attrs) { if (_geo_extents[idx].indexOf(key) === -1){ let feat = BASE_GEOJSON; feat["features"] = geojson["features"]; - _geo_extents[key] = new ol.source.Vector( - {features: new ol.format.GeoJSON().readFeatures(feat)} + let extent = new ol.source.Vector( + {features: new ol.format.GeoJSON().readFeatures(feat)} ).getExtent(); + let coords_1 = ol.proj.transform([extent[0], extent[1]], 'EPSG:4326', 'EPSG:3857'); + let coords_2 = ol.proj.transform([extent[2], extent[3]], 'EPSG:4326', 'EPSG:3857'); + _geo_extents[key] = [ + coords_1[0], coords_1[1], + coords_2[0], coords_2[1] + ]; register_zoom_on_map("#map-zoom-" + key); } } - if (_geo_extents[idx].indexOf(key) === -1){ - let feat = BASE_GEOJSON; - feat["features"] = geojson["features"]; - _geo_extents[key] = new ol.source.Vector( - {features: new ol.format.GeoJSON().readFeatures(feat)} - ).getExtent(); - /// console.log(_geo_extents[key]); - register_zoom_on_map("#map-zoom-" + key); - } $("#map-zoom-" + key).attr('aria-disabled', 'false'); } else { $("#map-zoom-" + key).attr('aria-disabled', 'true'); @@ -952,10 +936,9 @@ const register_zoom_on_map = function(){ click_delay = Date.now(); let feat_key = $(this).attr("data-geo-id"); let map_idx = $(this).attr("data-map-id"); - console.log(feat_key); - console.log(_geo_extents[feat_key]); - console.log(_geo_extents[feat_key][0]); - map_view[map_idx].fit(_geo_extents[feat_key]); + if (! ol.extent.isEmpty(_geo_extents[feat_key])) { + map_view[map_idx].fit(_geo_extents[feat_key]); + } return false; } ) diff --git a/ishtar_common/templates/ishtar/blocks/sheet_map.html b/ishtar_common/templates/ishtar/blocks/sheet_map.html index 50ebbd85d..74182a2e1 100644 --- a/ishtar_common/templates/ishtar/blocks/sheet_map.html +++ b/ishtar_common/templates/ishtar/blocks/sheet_map.html @@ -9,13 +9,14 @@ <h4>{% trans "Geographic data" %}</h4> <ul>{% for geodata in geodata_list %} <li> - <!-- <a role="link" href="#" aria-disabled="true" class="map-zoom-link" + <a role="link" href="#" aria-disabled="true" class="map-zoom-link" id="map-zoom-{{geo_item.SLUG}}-{{geo_item.pk}}-{{geodata.pk}}" data-map-id="map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}" data-geo-id="{{geo_item.SLUG}}-{{geo_item.pk}}-{{geodata.pk}}" > <i class="fa fa-search" aria-hidden="true"></i> - </a> --> + </a> + <input type="checkbox" name="map-ol-{{geo_item.SLUG}}-{{geo_item.pk}}-{{geodata.pk}}" class="map-ol-{{geo_item.SLUG}}-{{geo_item.pk}}" id="map-ol-{{geo_item.SLUG}}-{{geo_item.pk}}-{{geodata.pk}}" |