diff --git a/arches/app/datatypes/base.py b/arches/app/datatypes/base.py index 99de186407e..1cb743bac8c 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}"), 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): 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