Skip to content

Commit

Permalink
Add event listener for toggleSeparatedTool in MMGIS API (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
ac-61 authored Jun 23, 2023
1 parent 68d9a02 commit 8759f54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/pages/APIs/JavaScript/Main/Main.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions src/essence/Basics/ToolController_/ToolController_.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/essence/mmgisAPI/mmgisAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ var mmgisAPI_ = {
'toolChange',
'layerVisibilityChange',
'websocketChange',
'toggleSeparatedTool',
]
return validEvents.includes(eventName)
},
Expand Down Expand Up @@ -649,15 +650,15 @@ 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
*/
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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8759f54

Please sign in to comment.