Skip to content

Commit

Permalink
#572 mmgisAPI.getActiveTools (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Jul 2, 2024
1 parent 318a72e commit 95742cc
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
21 changes: 21 additions & 0 deletions docs/pages/APIs/JavaScript/Main/Main.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The `src/essence/mmgisAPI/mmgisAPI.js` file exposes functions that can be called
- [writeCoordinateURL()](#writecoordinateurl)
- [onLoaded(onLoadCallback)](#onloadedonloadcallback)
- [getActiveTool()](#getactivetool)
- [getActiveTools()](#getactivetools)
- [setLoginToken(username, token)](#setlogintoken)
- [project(lnglat)](#projectlnglat)
- [unproject(xy)](#unprojectxy)
Expand Down Expand Up @@ -831,6 +832,26 @@ The following is an example of how to call the `getActiveTool` function:
window.mmgisAPI.getActiveTool();
```

### getActiveTools()

This function returns an object with the currently active tool and the name of the active tool in addition to any active separated tools (such as the Identifier and Legend Tools).

The following is an example of how to call the `getActiveTools` function:

```javascript
window.mmgisAPI.getActiveTools();
/* returns (example)
{
activeToolNames: ['InfoTool', 'LegendTool', 'IdentifierTool']
activeTools: [
{activeTool: {…}, activeToolName: 'InfoTool'},
{activeTool: {…}, activeToolName: 'LegendTool'},
{activeTool: {…}, activeToolName: 'IdentifierTool'}
]
}
*/
```

### initialLogin()

Performs the initial login call to relogin returning users. Pairable with the ENV `SKIP_CLIENT_INITIAL_LOGIN=`.
Expand Down
8 changes: 8 additions & 0 deletions src/css/mmgis.css
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ body {
.toolButton:hover {
background: var(--color-a1-5) !important;
}

.toolButtonSep.active {
color: var(--color-c) !important;
border-bottom: 2px solid var(--color-c);
}
.toolButtonSep#toolButtonSeparated_Legend.active {
border-bottom: none !important;
}
.toolButtonSep:hover {
color: var(--color-c) !important;
}
Expand Down
1 change: 1 addition & 0 deletions src/essence/Basics/Map_/Map_.js
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ function allLayersLoaded() {
ToolController_.toolModules['LegendTool'].make(
'toolContentSeparated_Legend'
)
ToolController_.activeSeparatedTools.push('LegendTool')
let _event = new CustomEvent('toggleSeparatedTool', {
detail: {
toggledToolName: 'LegendTool',
Expand Down
26 changes: 24 additions & 2 deletions src/essence/Basics/ToolController_/ToolController_.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let ToolController_ = {
incToolsDiv: null,
excToolsDiv: null,
separatedDiv: null,
activeSeparatedTools: [],
toolModuleNames: [],
toolModules: toolModules,
activeTool: null,
Expand Down Expand Up @@ -90,11 +91,32 @@ let ToolController_ = {
`${ToolController_.tools[i].name}Tool`
]
if (tM) {
if (tM.made === false)
if (tM.made === false) {
tM.make(
`toolContentSeparated_${ToolController_.tools[i].name}`
)
else tM.destroy()
ToolController_.activeSeparatedTools.push(
ToolController_.tools[i].name +
'Tool'
)
$(
`#toolButtonSeparated_${tools[i].name}`
).addClass('active')
} else {
tM.destroy()
ToolController_.activeSeparatedTools =
ToolController_.activeSeparatedTools.filter(
(a) =>
a !=
ToolController_.tools[i]
.name +
'Tool'
)

$(
`#toolButtonSeparated_${tools[i].name}`
).removeClass('active')
}

// Dispatch `toggleSeparatedTool` event
let _event = new CustomEvent(
Expand Down
26 changes: 26 additions & 0 deletions src/essence/mmgisAPI/mmgisAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,27 @@ var mmgisAPI_ = {
}
return null
},
getActiveTools: function () {
if (ToolController_) {
const activeTool = mmgisAPI_.getActiveTool()
return {
activeToolNames: [ToolController_.activeToolName]
.concat(ToolController_.activeSeparatedTools)
.filter(Boolean),
activeTools: [activeTool.activeTool != null ? activeTool : null]
.concat(
ToolController_.activeSeparatedTools.map((a) => {
return {
activeTool: ToolController_.getTool(a),
activeToolName: a,
}
})
)
.filter(Boolean),
}
}
return null
},
getLayerConfigs: function (match) {
if (match) {
const matchedLayers = {}
Expand Down Expand Up @@ -641,6 +662,11 @@ var mmgisAPI = {
*/
getActiveTool: mmgisAPI_.getActiveTool,

/** getActiveTools - returns the currently active tool
* @returns {object} - The currently active tool and the name of the active tool as an object.
*/
getActiveTools: mmgisAPI_.getActiveTools,

/** getLayerConfigs - returns an object with the visibility state of all layers
* @returns {object} - an object containing the visibility state of each layer
*/
Expand Down

0 comments on commit 95742cc

Please sign in to comment.