mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-11-10 10:57:45 +01:00
Add expand/collapse all layer groups feature (#130)
This commit is contained in:
parent
ddb3bcde43
commit
06554b83dc
2 changed files with 45 additions and 6 deletions
|
@ -49,6 +49,7 @@ class LayerListContainer extends React.Component {
|
|||
super(props)
|
||||
this.state = {
|
||||
collapsedGroups: {},
|
||||
areAllGroupsExpanded: false,
|
||||
isOpen: {
|
||||
add: false,
|
||||
}
|
||||
|
@ -94,6 +95,31 @@ class LayerListContainer extends React.Component {
|
|||
})
|
||||
}
|
||||
|
||||
toggleLayers() {
|
||||
let idx=0
|
||||
|
||||
let newGroups=[]
|
||||
|
||||
this.groupedLayers().forEach(layers => {
|
||||
const groupPrefix = layerPrefix(layers[0].id)
|
||||
const lookupKey = [groupPrefix, idx].join('-')
|
||||
|
||||
|
||||
if (layers.length > 1) {
|
||||
newGroups[lookupKey] = this.state.areAllGroupsExpanded
|
||||
}
|
||||
|
||||
layers.forEach((layer) => {
|
||||
idx += 1
|
||||
})
|
||||
});
|
||||
|
||||
this.setState({
|
||||
collapsedGroups: newGroups,
|
||||
areAllGroupsExpanded: !this.state.areAllGroupsExpanded
|
||||
})
|
||||
}
|
||||
|
||||
groupedLayers() {
|
||||
const groups = []
|
||||
for (let i = 0; i < this.props.layers.length; i++) {
|
||||
|
@ -176,12 +202,25 @@ class LayerListContainer extends React.Component {
|
|||
/>
|
||||
<header className="maputnik-layer-list-header">
|
||||
<span className="maputnik-layer-list-header-title">Layers</span>
|
||||
<div className="maputnik-default-property">
|
||||
<div className="maputnik-multibutton">
|
||||
<a
|
||||
onClick={this.toggleLayers.bind(this)}
|
||||
className="maputnik-button">
|
||||
{this.state.areAllGroupsExpanded === true ? "Collapse" : "Expand"}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<span className="maputnik-space" />
|
||||
<Button
|
||||
onClick={this.toggleModal.bind(this, 'add')}
|
||||
className="maputnik-add-layer">
|
||||
Add Layer
|
||||
</Button>
|
||||
<div className="maputnik-default-property">
|
||||
<div className="maputnik-multibutton">
|
||||
<a
|
||||
onClick={this.toggleModal.bind(this, 'add')}
|
||||
className="maputnik-button maputnik-button-selected">
|
||||
Add Layer
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<ul className="maputnik-layer-list-container">
|
||||
{listItems}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// LAYER LIST
|
||||
.maputnik-layer-list {
|
||||
&-header {
|
||||
padding: $margin-2;
|
||||
padding: $margin-2 $margin-2 $margin-3;
|
||||
|
||||
@include flex-row;
|
||||
|
||||
|
|
Loading…
Reference in a new issue