From 2eb8c717b5e81867ef6e8c3a677f29efc79a3e14 Mon Sep 17 00:00:00 2001 From: tariqksoliman Date: Thu, 11 May 2023 14:17:54 -0700 Subject: [PATCH] #378 Legend formatting, reacts to layer toggles --- src/essence/Basics/Layers_/Layers_.js | 13 +++++++++++++ .../Basics/ToolController_/ToolController_.js | 1 + src/essence/Basics/Viewer_/Viewer_.js | 2 ++ src/essence/Tools/Legend/LegendTool.js | 7 ++++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/essence/Basics/Layers_/Layers_.js b/src/essence/Basics/Layers_/Layers_.js index 2ad7bc83..73b6b619 100644 --- a/src/essence/Basics/Layers_/Layers_.js +++ b/src/essence/Basics/Layers_/Layers_.js @@ -188,6 +188,15 @@ const L_ = { } } else console.log('Failure updating to new site') }, + _onLayerToggleSubscriptions: {}, + subscribeOnLayerToggle: function (fid, func) { + if (typeof func === 'function') + L_._onLayerToggleSubscriptions[fid] = func + }, + unsubscribeOnLayerToggle: function (fid) { + if (L_._onLayerToggleSubscriptions[fid] != null) + delete L_._onLayerToggleSubscriptions[fid] + }, //Takes in config layer obj //Toggles a layer on and off and accounts for sublayers //Takes in a config layer object @@ -198,6 +207,10 @@ const L_ = { else on = false await L_.toggleLayerHelper(s, on) + + Object.keys(L_._onLayerToggleSubscriptions).forEach((k) => { + L_._onLayerToggleSubscriptions[k](s.name, !on) + }) }, toggleLayerHelper: async function (s, on, ignoreToggleStateChange) { if (s.type !== 'header') { diff --git a/src/essence/Basics/ToolController_/ToolController_.js b/src/essence/Basics/ToolController_/ToolController_.js index 638a546d..fdac756d 100644 --- a/src/essence/Basics/ToolController_/ToolController_.js +++ b/src/essence/Basics/ToolController_/ToolController_.js @@ -51,6 +51,7 @@ let ToolController_ = { this.toolModuleNames.push(tools[i].js) if (tools[i].separatedTool) { + d3.select('#viewerToolBar').style('padding-left', '36px') let sep = this.separatedDiv .append('div') .attr('id', `toolSeparated_${tools[i].name}`) diff --git a/src/essence/Basics/Viewer_/Viewer_.js b/src/essence/Basics/Viewer_/Viewer_.js index 13076bd3..7b952081 100644 --- a/src/essence/Basics/Viewer_/Viewer_.js +++ b/src/essence/Basics/Viewer_/Viewer_.js @@ -407,6 +407,7 @@ var Viewer_ = { function buildToolBar() { d3.select('#viewerToolBar').html('') + Viewer_.toolBar = d3 .select('#viewerToolBar') .append('div') @@ -415,6 +416,7 @@ function buildToolBar() { .style('display', 'flex') .style('justify-content', 'space-between') .style('padding', '0px 5px') + //.style() let left = Viewer_.toolBar.append('div') diff --git a/src/essence/Tools/Legend/LegendTool.js b/src/essence/Tools/Legend/LegendTool.js index c7eff9cd..f31c2a9c 100644 --- a/src/essence/Tools/Legend/LegendTool.js +++ b/src/essence/Tools/Legend/LegendTool.js @@ -18,12 +18,16 @@ var LegendTool = { this.MMWebGISInterface = new interfaceWithMMWebGIS() this.activeLayerNames = [] + L_.subscribeOnLayerToggle('LegendTool', () => { + this.MMWebGISInterface = new interfaceWithMMWebGIS() + }) + this.made = true }, destroy: function () { this.MMWebGISInterface.separateFromMMWebGIS() this.targetId = null - + L_.unsubscribeOnLayerToggle('LegendTool') this.made = false }, overwriteLegends: overwriteLegends, @@ -34,6 +38,7 @@ function interfaceWithMMWebGIS() { this.separateFromMMWebGIS = function () { separateFromMMWebGIS() } + separateFromMMWebGIS() let tools = drawLegendHeader()