From 41a1418f3d74d07e5cdcb6e3ede95beacc38ad9b Mon Sep 17 00:00:00 2001 From: Galen Date: Sat, 9 Mar 2024 17:56:21 -0800 Subject: [PATCH 1/3] adds query_layer kwarg to get_map_source method to pass along kwargs to mvt endpoint re #10655 --- arches/app/datatypes/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arches/app/datatypes/base.py b/arches/app/datatypes/base.py index 23425368f03..bf06a1d3fe2 100644 --- a/arches/app/datatypes/base.py +++ b/arches/app/datatypes/base.py @@ -99,15 +99,18 @@ def clean(self, tile, nodeid): if tile.data[nodeid] == "": tile.data[nodeid] = None - def get_map_source(self, node=None, preview=False): + def get_map_source(self, node=None, preview=False, query_layer=None): """ Gets the map source definition to add to the map for a given node should be a dictionary including (as in map_sources table): name, source (json) + query_layer = { "label": string, "targetnodeid": nodeid, "targetvalue": string} """ tileserver_url = urllib.parse.unquote(reverse("mvt", args=(node.nodeid, "{z}", "{x}", "{y}"))) if node is None: return None + if query_layer: + tileserver_url = urllib.parse.unquote(reverse("mvt", args=(node.nodeid, "{z}", "{x}", "{y}", query_layer["targetnodeid"], query_layer["targetvalue"]))) source_config = {"type": "vector", "tiles": [tileserver_url]} count = None if preview == True: From b8dfdbf4e73b15b686e56017794586d3afbf9780 Mon Sep 17 00:00:00 2001 From: Galen Date: Sat, 9 Mar 2024 17:57:43 -0800 Subject: [PATCH 2/3] includes querylayer sources in base context re #10655 --- arches/app/views/base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arches/app/views/base.py b/arches/app/views/base.py index 7b2d799f80e..9627005e5a9 100644 --- a/arches/app/views/base.py +++ b/arches/app/views/base.py @@ -117,6 +117,10 @@ def get_context_data(self, **kwargs): map_layer = datatype.get_map_layer(node) if map_layer is not None: resource_layers.append(map_layer) + # check node config for query layers + if "querylayers" in node.config: + for query_layer in node.config["querylayers"]: + resource_sources.append(datatype.get_map_source(node, query_layer=query_layer)) context["geom_nodes"] = geom_nodes context["resource_map_layers"] = resource_layers From 4652d4a37706d0ba8c8db6a77435caaca39b47b1 Mon Sep 17 00:00:00 2001 From: Galen Date: Fri, 3 May 2024 23:45:03 +0900 Subject: [PATCH 3/3] commits kwarg targetnodevalue to mvt url if query_layer, creates new cache key, re #10655 --- arches/app/datatypes/base.py | 2 +- arches/app/views/api.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arches/app/datatypes/base.py b/arches/app/datatypes/base.py index b4aa7b05922..1cb743bac8c 100644 --- a/arches/app/datatypes/base.py +++ b/arches/app/datatypes/base.py @@ -110,7 +110,7 @@ def get_map_source(self, node=None, preview=False, query_layer=None): if node is None: return None if query_layer: - tileserver_url = urllib.parse.unquote(reverse("mvt", args=(node.nodeid, "{z}", "{x}", "{y}", query_layer["targetnodeid"], query_layer["targetvalue"]))) + tileserver_url = urllib.parse.unquote(reverse("mvt", args=(node.nodeid, "{z}", "{x}", "{y}"), kwargs={"targetvalue": query_layer["targetvalue"]})) source_config = {"type": "vector", "tiles": [tileserver_url]} count = None if preview == True: diff --git a/arches/app/views/api.py b/arches/app/views/api.py index 1c2b4ef6f34..255351329cb 100644 --- a/arches/app/views/api.py +++ b/arches/app/views/api.py @@ -270,7 +270,7 @@ class MVT(APIBase): EARTHCIRCUM = 40075016.6856 PIXELSPERTILE = 256 - def get(self, request, nodeid, zoom, x, y): + def get(self, request, nodeid, zoom, x, y, **kwargs): if hasattr(request.user, "userprofile") is not True: models.UserProfile.objects.create(user=request.user) viewable_nodegroups = request.user.userprofile.viewable_nodegroups @@ -280,7 +280,8 @@ def get(self, request, nodeid, zoom, x, y): raise Http404() search_geom_count = 0 config = node.config - cache_key = MVT.create_mvt_cache_key(node, zoom, x, y, request.user) + target_nodevalue = kwargs.pop("targetvalue", None) + cache_key = MVT.create_mvt_cache_key(node, zoom, x, y, request.user, target_nodevalue) tile = cache.get(cache_key) if tile is None: resource_ids = get_restricted_instances(request.user, allresources=True) @@ -398,8 +399,11 @@ def get(self, request, nodeid, zoom, x, y): raise Http404() return HttpResponse(tile, content_type="application/x-protobuf") - def create_mvt_cache_key(node, zoom, x, y, user): - return f"mvt_{str(node.nodeid)}_{zoom}_{x}_{y}_{user.id}" + def create_mvt_cache_key(node, zoom, x, y, user, target_nodevalue): + if target_nodevalue: + return f"mvt_{str(node.nodeid)}_{zoom}_{x}_{y}_{user.id}_{target_nodevalue}" + else: + return f"mvt_{str(node.nodeid)}_{zoom}_{x}_{y}_{user.id}" @method_decorator(csrf_exempt, name="dispatch") class Graphs(APIBase):