From 77014e7c392e152a45f10a8ee48779772153de0e Mon Sep 17 00:00:00 2001 From: achung Date: Fri, 23 Jun 2023 14:36:23 -0700 Subject: [PATCH] Add listener for toggleSeparatedTool --- docs/pages/APIs/JavaScript/Main/Main.md | 2 +- src/essence/Basics/ToolController_/ToolController_.js | 9 +++++++++ src/essence/mmgisAPI/mmgisAPI.js | 7 ++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/pages/APIs/JavaScript/Main/Main.md b/docs/pages/APIs/JavaScript/Main/Main.md index cb6ff721..f87be052 100644 --- a/docs/pages/APIs/JavaScript/Main/Main.md +++ b/docs/pages/APIs/JavaScript/Main/Main.md @@ -597,7 +597,7 @@ window.mmgisAPI.updateLayersTime(); ### addEventListener(eventName, functionReference) -This function adds a map event or MMGIS action listener added using the MMGIS API. This function takes in one of the following events: `onPan`, `onZoom`, `onClick`, `toolChange`, `layerVisibilityChange`. The MMGIS action listener (`toolChange`, `layerVisibilityChange`, `websocketChange`) functions are called with an `event` parameter. +This function adds a map event or MMGIS action listener added using the MMGIS API. This function takes in one of the following events: `onPan`, `onZoom`, `onClick`, `toolChange`, `layerVisibilityChange`. The MMGIS action listener (`toolChange`, `layerVisibilityChange`, `websocketChange`, `toggleSeparatedTool`) functions are called with an `event` parameter. #### Function parameters diff --git a/src/essence/Basics/ToolController_/ToolController_.js b/src/essence/Basics/ToolController_/ToolController_.js index fdac756d..b0df9ba7 100644 --- a/src/essence/Basics/ToolController_/ToolController_.js +++ b/src/essence/Basics/ToolController_/ToolController_.js @@ -96,6 +96,15 @@ let ToolController_ = { `toolContentSeparated_${ToolController_.tools[i].name}` ) else tM.destroy() + + // Dispatch `toggleSeparatedTool` event + let _event = new CustomEvent('toggleSeparatedTool', { + detail: { + toggledToolName: ToolController_.tools[i].js, + visible: tM.made, + }, + }) + document.dispatchEvent(_event) } } })(i) diff --git a/src/essence/mmgisAPI/mmgisAPI.js b/src/essence/mmgisAPI/mmgisAPI.js index ce6eae52..6a171dbc 100644 --- a/src/essence/mmgisAPI/mmgisAPI.js +++ b/src/essence/mmgisAPI/mmgisAPI.js @@ -389,6 +389,7 @@ var mmgisAPI_ = { 'toolChange', 'layerVisibilityChange', 'websocketChange', + 'toggleSeparatedTool', ] return validEvents.includes(eventName) }, @@ -649,7 +650,7 @@ var mmgisAPI = { getVisibleLayers: mmgisAPI_.getVisibleLayers, /** addEventListener - adds map event or MMGIS action listener. - * @param {string} - eventName - name of event to add listener to. Available events: onPan, onZoom, onClick, toolChange, layerVisibilityChange + * @param {string} - eventName - name of event to add listener to. Available events: onPan, onZoom, onClick, toolChange, layerVisibilityChange, toggleSeparatedTool * @param {function} - functionReference - function reference to listener event callback function. null value removes all functions for a given eventName @@ -657,7 +658,7 @@ var mmgisAPI = { addEventListener: mmgisAPI_.addEventListener, /** removeEventListener - removes map event or MMGIS action listener added using the MMGIS API. - * @param {string} - eventName - name of event to add listener to. Available events: onPan, onZoom, onClick, toolChange, layerVisibilityChange + * @param {string} - eventName - name of event to add listener to. Available events: onPan, onZoom, onClick, toolChange, layerVisibilityChange, toggleSeparatedTool * @param {function} - functionReference - function reference to listener event callback function. null value removes all functions for a given eventName */ removeEventListener: mmgisAPI_.removeEventListener, @@ -691,7 +692,7 @@ var mmgisAPI = { */ toggleLayer: mmgisAPI_.toggleLayer, - /** overwriteLegends - overwrite the contents displayed in the LegendTool; useful when used with `toolChange` event listener in mmgisAPI + /** overwriteLegends - overwrite the contents displayed in the LegendTool; useful when used with `toggleSeparatedTool` event listener in mmgisAPI * @param {array} - legends - an array of objects, where each object must contain the following keys: legend, layerUUID, display_name, opacity. The value for the legend key should be in the same format as what is stored in the layers data under the `_legend` key (i.e. `L_.layers.data[layerName]._legend`). layerUUID and display_name should be strings and opacity should be a number between 0 and 1. */ overwriteLegends: LegendTool.overwriteLegends,