Skip to content

Commit fd984f6

Browse files
authored
Merge pull request #331 from BenediktSeidlSWM/layertree-onlygroups
Introduce option in LayerTree to only show groups
2 parents ac30fc3 + cc14f98 commit fd984f6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

doc/plugins.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ with containing a container element with id=legendcontainer.
469469
| groupTogglesSublayers | `bool` | Whether toggling a group also toggles all sublayers. | `false` |
470470
| infoInSettings | `bool` | Whether to display the layer info button inside the layer settings menu rather than next to the layer title. | `true` |
471471
| layerInfoGeometry | `{`<br />`  initialWidth: number,`<br />`  initialHeight: number,`<br />`  initialX: number,`<br />`  initialY: number,`<br />`  initiallyDocked: bool,`<br />`}` | Default layer info window geometry with size, position and docking status. | `{`<br />`  initialWidth: 480,`<br />`  initialHeight: 480,`<br />`  initialX: null,`<br />`  initialY: null,`<br />`  initiallyDocked: false`<br />`}` |
472+
| onlyGroups | `bool` | Whether to only display layer groups but not individual layers in layertree. | `false` |
472473
| scaleDependentLegend | `{bool, string}` | Whether to display a scale dependent legend. Can be `true|false|"theme"`, latter means only for theme layers. | `undefined` |
473474
| showLegendIcons | `bool` | Whether to display legend icons. | `true` |
474475
| showQueryableIcon | `bool` | Whether to display the queryable icon to indicate that a layer is identifyable. | `true` |

plugins/LayerTree.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class LayerTree extends React.Component {
8989
mapScale: PropTypes.number,
9090
mapTipsEnabled: PropTypes.bool,
9191
mobile: PropTypes.bool,
92+
/** Whether to only display layer groups but not individual layers in layertree. */
93+
onlyGroups: PropTypes.bool,
9294
removeLayer: PropTypes.func,
9395
reorderLayer: PropTypes.func,
9496
/** Whether to display a scale dependent legend. Can be `true|false|"theme"`, latter means only for theme layers. */
@@ -136,6 +138,7 @@ class LayerTree extends React.Component {
136138
},
137139
bboxDependentLegend: false,
138140
flattenGroups: false,
141+
onlyGroups: false,
139142
width: "25em",
140143
enableLegendPrint: true,
141144
enableVisibleFilter: true,
@@ -223,6 +226,8 @@ class LayerTree extends React.Component {
223226
checkboxstate = 'radio_' + checkboxstate;
224227
}
225228
const expanderstate = group.expanded ? 'tree_minus' : 'tree_plus';
229+
const onlyGroups = ConfigUtils.getConfigProp("showOnlyLayerGroups", this.props.theme) || this.props.onlyGroups;
230+
const showExpander = !onlyGroups || (group.sublayers || []).some((sublayer) => sublayer.sublayers);
226231
const itemclasses = {
227232
"layertree-item": true,
228233
"layertree-item-disabled": (!this.props.groupTogglesSublayers && !enabled) || (this.props.grayUnchecked && !visibility)
@@ -241,7 +246,7 @@ class LayerTree extends React.Component {
241246
return (
242247
<div className="layertree-item-container" data-id={JSON.stringify({layer: layer.uuid, path: path})} key={group.uuid}>
243248
<div className={classnames(itemclasses)}>
244-
<Icon className="layertree-item-expander" icon={expanderstate} onClick={() => this.groupExpandedToggled(layer, path, group.expanded)} />
249+
{showExpander ? (<Icon className="layertree-item-expander" icon={expanderstate} onClick={() => this.groupExpandedToggled(layer, path, group.expanded)} />) : (<span className="layertree-item-expander" />)}
245250
<Icon className="layertree-item-checkbox" icon={checkboxstate} onClick={() => this.itemVisibilityToggled(layer, path, visibility)} />
246251
<span className="layertree-item-title" title={group.title}>{group.title}</span>
247252
{LayerUtils.hasQueryableSublayers(group) && this.props.allowSelectIdentifyableLayers ? (<Icon className={"layertree-item-identifyable " + identifyableClassName} icon="info-sign" onClick={() => this.itemOmitQueryableToggled(layer, path, omitqueryable)} />) : null}
@@ -257,6 +262,10 @@ class LayerTree extends React.Component {
257262
);
258263
};
259264
renderLayer = (layer, sublayer, path, enabled = true, inMutuallyExclusiveGroup = false, skipExpanderPlaceholder = false) => {
265+
const onlyGroups = ConfigUtils.getConfigProp("showOnlyLayerGroups", this.props.theme) || this.props.onlyGroups;
266+
if (onlyGroups) {
267+
return null;
268+
}
260269
if (this.state.filtervisiblelayers && !sublayer.visibility) {
261270
return null;
262271
}

0 commit comments

Comments
 (0)