mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-27 11:55:27 +01:00
Merge pull request #185 from gregorywolanski/130
Add expand/collapse all layer groups feature (#130)
This commit is contained in:
commit
6e86c60f89
2 changed files with 45 additions and 6 deletions
|
@ -50,6 +50,7 @@ class LayerListContainer extends React.Component {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
collapsedGroups: {},
|
collapsedGroups: {},
|
||||||
|
areAllGroupsExpanded: false,
|
||||||
isOpen: {
|
isOpen: {
|
||||||
add: false,
|
add: false,
|
||||||
}
|
}
|
||||||
|
@ -95,6 +96,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() {
|
groupedLayers() {
|
||||||
const groups = []
|
const groups = []
|
||||||
for (let i = 0; i < this.props.layers.length; i++) {
|
for (let i = 0; i < this.props.layers.length; i++) {
|
||||||
|
@ -178,11 +204,24 @@ class LayerListContainer extends React.Component {
|
||||||
<header className="maputnik-layer-list-header">
|
<header className="maputnik-layer-list-header">
|
||||||
<span className="maputnik-layer-list-header-title">Layers</span>
|
<span className="maputnik-layer-list-header-title">Layers</span>
|
||||||
<span className="maputnik-space" />
|
<span className="maputnik-space" />
|
||||||
<Button
|
<div className="maputnik-default-property">
|
||||||
onClick={this.toggleModal.bind(this, 'add')}
|
<div className="maputnik-multibutton">
|
||||||
className="maputnik-add-layer">
|
<a
|
||||||
Add Layer
|
onClick={this.toggleLayers.bind(this)}
|
||||||
</Button>
|
className="maputnik-button">
|
||||||
|
{this.state.areAllGroupsExpanded === true ? "Collapse" : "Expand"}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<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>
|
</header>
|
||||||
<ul className="maputnik-layer-list-container">
|
<ul className="maputnik-layer-list-container">
|
||||||
{listItems}
|
{listItems}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// LAYER LIST
|
// LAYER LIST
|
||||||
.maputnik-layer-list {
|
.maputnik-layer-list {
|
||||||
&-header {
|
&-header {
|
||||||
padding: $margin-2;
|
padding: $margin-2 $margin-2 $margin-3;
|
||||||
|
|
||||||
@include flex-row;
|
@include flex-row;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue