From 22bc8928d4697ea3a0eac98999f1ec9c2e8e3e8b Mon Sep 17 00:00:00 2001
From: Christian Schiffer <c.schiffer@fz-juelich.de>
Date: Fri, 29 Jan 2021 08:17:25 +0100
Subject: [PATCH] Added support for color maps

---
 atlas_server/src/app.py   | 16 +++++++++++++++-
 microdraw/src/atlas_ui.js |  4 +++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/atlas_server/src/app.py b/atlas_server/src/app.py
index efede18..acbd640 100644
--- a/atlas_server/src/app.py
+++ b/atlas_server/src/app.py
@@ -352,6 +352,8 @@ class TaskTileServerConfig(Resource):
 
         # Download the base file
         base_file = base64.b64decode(base_file_b64).decode("utf-8")
+        # Split get parameters
+        base_file, *get_params = base_file.split("&")
         result = requests.get(url=base_file)
         if result.status_code >= 400:
             abort(404, f"Could not find base file {base_file}")
@@ -383,6 +385,18 @@ class TaskTileServerConfig(Resource):
             abort(404, f"Failed to find predictions")
             return
 
+        # Parse get params
+        get_param_dict = {}
+        for get_param in get_params:
+            key, value = get_param.split("=")
+            get_param_dict[key] = value
+
+        cmap = get_param_dict.get("cmap")
+        if cmap:
+            cmap_args = f"&cmap={cmap}"
+        else:
+            cmap_args = ""
+
         overlays = base_file_content.get("overlays", {})
         overlay_name = f"{project.name} - {task.name}"
         for prediction in result.json():
@@ -390,7 +404,7 @@ class TaskTileServerConfig(Resource):
             h, w = prediction["shape"]
             section = f"{get_section_number_from_string(path):04d}"
             section_overlays = overlays.get(section, {})
-            url = "function(level, x, y){return '" + f"{TILE_SERVER_HOST}/get_tile?level=' + level + '&y=' + y + '&x=' + x + '&ts=256&img={path}&dataset=/'" + ";}"
+            url = "function(level, x, y){return '" + f"{TILE_SERVER_HOST}/get_tile?level=' + level + '&y=' + y + '&x=' + x + '&ts=256&img={path}&dataset=/{cmap_args}'" + ";}"
             section_overlays[overlay_name] = {
                 "getTileUrl": url,
                 "height": h,
diff --git a/microdraw/src/atlas_ui.js b/microdraw/src/atlas_ui.js
index 4eb350a..3f0ebc5 100644
--- a/microdraw/src/atlas_ui.js
+++ b/microdraw/src/atlas_ui.js
@@ -528,10 +528,12 @@ var app = new Vue({
 			let protocol = window.location.protocol;
 			let directory = path.substring(0, path.lastIndexOf("/"));
 			let source = params.source;
+			let cmap = params.cmap;
+			console.log(cmap);
 			// Note: This should match the format atlas_server uses for storing the overlays"
 			let overlay = `${project.name} - ${task.name}`
 
-			let target = `${protocol}//${host}${directory}/${source}`
+			let target = `${protocol}//${host}${directory}/${source}&cmap=${cmap}`
 			let encoded_target = encodeURIComponent(btoa(target));
 
 			let section = task.annotations[0].section;
-- 
GitLab