Skip to content

Commit

Permalink
Introduce option in LayerTree to only show groups
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktSeidlSWM committed Jul 22, 2024
1 parent 0cd42c8 commit cc14f98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ with containing a container element with id=legendcontainer.
| groupTogglesSublayers | `bool` | Whether toggling a group also toggles all sublayers. | `false` |
| infoInSettings | `bool` | Whether to display the layer info button inside the layer settings menu rather than next to the layer title. | `true` |
| 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 />`}` |
| onlyGroups | `bool` | Whether to only display layer groups but not individual layers in layertree. | `false` |
| scaleDependentLegend | `{bool, string}` | Whether to display a scale dependent legend. Can be `true|false|"theme"`, latter means only for theme layers. | `undefined` |
| showLegendIcons | `bool` | Whether to display legend icons. | `true` |
| showQueryableIcon | `bool` | Whether to display the queryable icon to indicate that a layer is identifyable. | `true` |
Expand Down
11 changes: 10 additions & 1 deletion plugins/LayerTree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class LayerTree extends React.Component {
mapScale: PropTypes.number,
mapTipsEnabled: PropTypes.bool,
mobile: PropTypes.bool,
/** Whether to only display layer groups but not individual layers in layertree. */
onlyGroups: PropTypes.bool,
removeLayer: PropTypes.func,
reorderLayer: PropTypes.func,
/** Whether to display a scale dependent legend. Can be `true|false|"theme"`, latter means only for theme layers. */
Expand Down Expand Up @@ -136,6 +138,7 @@ class LayerTree extends React.Component {
},
bboxDependentLegend: false,
flattenGroups: false,
onlyGroups: false,
width: "25em",
enableLegendPrint: true,
enableVisibleFilter: true,
Expand Down Expand Up @@ -223,6 +226,8 @@ class LayerTree extends React.Component {
checkboxstate = 'radio_' + checkboxstate;
}
const expanderstate = group.expanded ? 'tree_minus' : 'tree_plus';
const onlyGroups = ConfigUtils.getConfigProp("showOnlyLayerGroups", this.props.theme) || this.props.onlyGroups;
const showExpander = !onlyGroups || (group.sublayers || []).some((sublayer) => sublayer.sublayers);
const itemclasses = {
"layertree-item": true,
"layertree-item-disabled": (!this.props.groupTogglesSublayers && !enabled) || (this.props.grayUnchecked && !visibility)
Expand All @@ -241,7 +246,7 @@ class LayerTree extends React.Component {
return (
<div className="layertree-item-container" data-id={JSON.stringify({layer: layer.uuid, path: path})} key={group.uuid}>
<div className={classnames(itemclasses)}>
<Icon className="layertree-item-expander" icon={expanderstate} onClick={() => this.groupExpandedToggled(layer, path, group.expanded)} />
{showExpander ? (<Icon className="layertree-item-expander" icon={expanderstate} onClick={() => this.groupExpandedToggled(layer, path, group.expanded)} />) : (<span className="layertree-item-expander" />)}
<Icon className="layertree-item-checkbox" icon={checkboxstate} onClick={() => this.itemVisibilityToggled(layer, path, visibility)} />
<span className="layertree-item-title" title={group.title}>{group.title}</span>
{LayerUtils.hasQueryableSublayers(group) && this.props.allowSelectIdentifyableLayers ? (<Icon className={"layertree-item-identifyable " + identifyableClassName} icon="info-sign" onClick={() => this.itemOmitQueryableToggled(layer, path, omitqueryable)} />) : null}
Expand All @@ -257,6 +262,10 @@ class LayerTree extends React.Component {
);
};
renderLayer = (layer, sublayer, path, enabled = true, inMutuallyExclusiveGroup = false, skipExpanderPlaceholder = false) => {
const onlyGroups = ConfigUtils.getConfigProp("showOnlyLayerGroups", this.props.theme) || this.props.onlyGroups;
if (onlyGroups) {
return null;
}
if (this.state.filtervisiblelayers && !sublayer.visibility) {
return null;
}
Expand Down

0 comments on commit cc14f98

Please sign in to comment.