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 global style selector button #353

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jblanchg
Copy link
Contributor

Hi! I'm not sure if this might be interesting to you, but since you can change the layer style individually from the LayerTree, I added an extra button to the title bar that allows the user to select a style and apply it to all layers (if the layer has that style available).

image

image

What do you thinkg?

Thanks!

plugins/LayerTree.jsx Fixed Show fixed Hide fixed
plugins/LayerTree.jsx Fixed Show fixed Hide fixed
plugins/LayerTree.jsx Fixed Show fixed Hide fixed
plugins/LayerTree.jsx Fixed Show fixed Hide fixed
plugins/LayerTree.jsx Fixed Show fixed Hide fixed
plugins/LayerTree.jsx Fixed Show fixed Hide fixed
@manisandro
Copy link
Member

Interesting! Would it also be an idea to place the selector on the toplevel WMS group layer (assumes you have "show root layer" enabled)? Rationale would be that, when adding additional themes, it might be desireable to switch styles for the themes separately - it is I guess pretty unlikely that separate themes will be sharing style names in general.

@jblanchg
Copy link
Contributor Author

Hi!

I applied the changes to add the button to the toplevel WMS group layer and to have the same style as the button to change the style of a layer individually.

image

image

if (layer.sublayers && layer.sublayers.length > 0) {
collectStyles(layer.sublayers);
}
if (layer.styles && Object.keys(layer.styles).length > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole block could be shortened to

const styleList = {};
Object.assign(styleList, layer.styles);

@@ -246,9 +249,14 @@ class LayerTree extends React.Component {
"layertree-item-menubutton": true,
"layertree-item-menubutton-active": this.state.activemenu === group.uuid
});
const styleMenuClasses = classnames({
"layertree-item-menubutton": true,
"layertree-item-menubutton-active": this.state.activestyleselector === group.uuid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can re-use activestylemenu instead of adding a new activestyleselector state variable.

@@ -257,10 +265,12 @@ class LayerTree extends React.Component {
<span className="layertree-item-title" onClick={() => this.itemVisibilityToggled(layer, path, visibility)} 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}
<span className="layertree-item-spacer" />
{isTopLevelWMSGroup ? (<Icon className={styleMenuClasses} icon="paint" onClick={() => this.manageStyleSelector(group.uuid)}/>) : null}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally you'd show the menu only if styles are available. I'd collect the layer styles at this stage and only show the menu if styles are available. You can then directly pass the styles to the style selector rendering function, without storing them in the state.

collectStyles(layerList);
return Array.from(styleList);
};
renderStyleSelector = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could potentially re-use renderStyleMenu by modifying the renderStyleMenu arguments to also take the list of styles to render as well as the callback.

}
}
};
setStyle(this.props.layers);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only want to apply the style to the one layer, not all layers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants