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

Add event listener for toggleSeparatedTool in MMGIS API #388

Merged
merged 1 commit into from
Jun 23, 2023
Merged
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
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