summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-10-19 11:07:45 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:19 +0100
commit13a3311ff045b53dbdced2b03dce7295d3c1a398 (patch)
treeec0ce3d3ab0f7f5c9cc989b131405c327237138e
parent4d2730f4003347eab7c25a5f0b3f01918e522d5a (diff)
downloadIshtar-13a3311ff045b53dbdced2b03dce7295d3c1a398.tar.bz2
Ishtar-13a3311ff045b53dbdced2b03dce7295d3c1a398.zip
Geodata - Sheet : zoom to extent
-rw-r--r--CHANGES.md5
-rw-r--r--ishtar_common/static/js/ishtar-map.js39
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_map.html5
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> -->&nbsp;
+ </a>
+ &nbsp;
<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}}"