Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10655 query layer #10671

Draft
wants to merge 4 commits into
base: dev/7.6.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion arches/app/datatypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions arches/app/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions arches/app/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading