From a8d8513c6c365d09eb663722b29740d3231d2c56 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 9 Sep 2022 12:38:46 +0200 Subject: Geo: display associated context records and associated finds on sheet map (refactor and fixes) --- ishtar_common/models_common.py | 46 ++++++++++++++++++++++ ishtar_common/static/js/ishtar-map.js | 2 +- .../templates/ishtar/blocks/sheet_map.html | 46 +++++++++++----------- 3 files changed, 70 insertions(+), 24 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 9d71ae0dc..b72251f02 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2359,6 +2359,52 @@ class GeoVectorData(Imported, OwnPerms): profile = get_current_profile() return profile.srs + @classmethod + def _get_geo_item_list(cls, q, current_geodata, url, precision, rounded): + collection_id = [] + items_id = [] + q = q.values("main_geodata", "id") + for item in q.distinct().all(): + geodata_id = item["main_geodata"] + if geodata_id not in current_geodata: + collection_id.append(geodata_id) + items_id.append(item["id"]) + current_geodata.append(geodata_id) + + collection = [] + for idx in range(len(collection_id)): + geo = json.loads(GeoVectorData.objects.get(pk=collection_id[idx]).geojson) + geo_type = geo.get("type", None) + url_geo = url.format(items_id[idx]) + if geo_type == "FeatureCollection": + for feat in geo["features"]: + if "properties" in feat: + feat["properties"]["url"] = url_geo + collection += geo["features"] + elif geo_type: + if "properties" in geo: + geo["properties"]["url"] = url_geo + collection.append(geo) + + if not precision and rounded: + precision = 6 + r = re.compile(r"(\d+)\.(\d{6})(\d*)") + new_collection = [] + for feat in collection: + geom_type = feat["geometry"].get("type", None) + if geom_type == "Point": + if precision is not None: + feat["geometry"]["coordinates"] = [ + round(feat["geometry"]["coordinates"][0], precision), + round(feat["geometry"]["coordinates"][1], precision), + ] + if not (-90 <= feat["geometry"]["coordinates"][1] <= 90) or not ( + -180 <= feat["geometry"]["coordinates"][0] <= 180): + # probably a bad projection + continue + new_collection.append(feat) + return new_collection + def get_geo_items(self, rounded=5): dct = {"type": "Feature", "geometry": {}, "properties": {"label": str(self)}} diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js index 8ffe399d6..67d29cc48 100644 --- a/ishtar_common/static/js/ishtar-map.js +++ b/ishtar_common/static/js/ishtar-map.js @@ -716,7 +716,7 @@ var display_map = function(map_id, points, lines_and_polys, layers){ } else { initialize_base_map(map_id, layers); } - display_points(map_id, points); + display_points(map_id, points, true); init_popup(map_id); diff --git a/ishtar_common/templates/ishtar/blocks/sheet_map.html b/ishtar_common/templates/ishtar/blocks/sheet_map.html index 11780ae8a..4a380ed13 100644 --- a/ishtar_common/templates/ishtar/blocks/sheet_map.html +++ b/ishtar_common/templates/ishtar/blocks/sheet_map.html @@ -9,40 +9,40 @@

{% trans "Geographic data" %}

-- cgit v1.2.3