mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-14 17:03:31 +01:00
Collapsible layer groups #66
This commit is contained in:
parent
26a865bb50
commit
abceb457c9
3 changed files with 30 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import classnames from 'classnames'
|
||||||
import cloneDeep from 'lodash.clonedeep'
|
import cloneDeep from 'lodash.clonedeep'
|
||||||
|
|
||||||
import Button from '../Button'
|
import Button from '../Button'
|
||||||
|
@ -31,6 +32,7 @@ class LayerListContainer extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
|
collapsedGroups: {},
|
||||||
isOpen: {
|
isOpen: {
|
||||||
add: false,
|
add: false,
|
||||||
}
|
}
|
||||||
|
@ -92,37 +94,42 @@ class LayerListContainer extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleLayerGroup(groupPrefix) {
|
toggleLayerGroup(groupPrefix) {
|
||||||
groupedLayers().forEach(layers => {
|
const newGroups = { ...this.state.collapsedGroups }
|
||||||
if(groupPrefix === layerPrefix(layers[0].id)) {
|
if(groupPrefix in this.state.collapsedGroups) {
|
||||||
layers.forEach(layer => {
|
newGroups[groupPrefix] = !this.state.collapsedGroups[groupPrefix]
|
||||||
//HACK
|
} else {
|
||||||
//In this case it is ok to modify the metadata
|
newGroups[groupPrefix] = true
|
||||||
//because no one else depends on it
|
}
|
||||||
layer.metadata = {
|
this.setState({
|
||||||
...layer.metadata,
|
collapsedGroups: newGroups
|
||||||
'maputnik:visible': false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const isCollapsed = groupPrefix => {
|
||||||
|
const collapsed = this.state.collapsedGroups[groupPrefix]
|
||||||
|
return collapsed === undefined ? false : collapsed
|
||||||
|
}
|
||||||
|
|
||||||
const listItems = []
|
const listItems = []
|
||||||
let idx = 0
|
let idx = 0
|
||||||
this.groupedLayers().forEach(layers => {
|
this.groupedLayers().forEach(layers => {
|
||||||
|
const groupPrefix = layerPrefix(layers[0].id)
|
||||||
if(layers.length > 1) {
|
if(layers.length > 1) {
|
||||||
const groupPrefix = layerPrefix(layers[0].id)
|
|
||||||
const grp = <LayerListGroup
|
const grp = <LayerListGroup
|
||||||
key={'group-'+groupPrefix}
|
key={'group-' + groupPrefix + '-' + idx}
|
||||||
title={groupPrefix}
|
title={groupPrefix}
|
||||||
isActive={true}
|
isActive={!isCollapsed(groupPrefix)}
|
||||||
|
onActiveToggle={this.toggleLayerGroup.bind(this, groupPrefix)}
|
||||||
/>
|
/>
|
||||||
listItems.push(grp)
|
listItems.push(grp)
|
||||||
}
|
}
|
||||||
|
|
||||||
layers.forEach(layer => {
|
layers.forEach(layer => {
|
||||||
const listItem = <LayerListItem
|
const listItem = <LayerListItem
|
||||||
|
className={classnames({
|
||||||
|
'maputnik-layer-list-item-collapsed': isCollapsed(groupPrefix)
|
||||||
|
})}
|
||||||
index={idx}
|
index={idx}
|
||||||
key={layer.id}
|
key={layer.id}
|
||||||
layerId={layer.id}
|
layerId={layer.id}
|
||||||
|
|
|
@ -61,6 +61,7 @@ class LayerListItem extends React.Component {
|
||||||
layerType: React.PropTypes.string.isRequired,
|
layerType: React.PropTypes.string.isRequired,
|
||||||
isSelected: React.PropTypes.bool,
|
isSelected: React.PropTypes.bool,
|
||||||
visibility: React.PropTypes.string,
|
visibility: React.PropTypes.string,
|
||||||
|
className: React.PropTypes.string,
|
||||||
|
|
||||||
onLayerSelect: React.PropTypes.func.isRequired,
|
onLayerSelect: React.PropTypes.func.isRequired,
|
||||||
onLayerCopy: React.PropTypes.func,
|
onLayerCopy: React.PropTypes.func,
|
||||||
|
@ -93,6 +94,7 @@ class LayerListItem extends React.Component {
|
||||||
className={classnames({
|
className={classnames({
|
||||||
"maputnik-layer-list-item": true,
|
"maputnik-layer-list-item": true,
|
||||||
"maputnik-layer-list-item-selected": this.props.isSelected,
|
"maputnik-layer-list-item-selected": this.props.isSelected,
|
||||||
|
[this.props.className]: true,
|
||||||
})}>
|
})}>
|
||||||
<LayerTypeDragHandle type={this.props.layerType} />
|
<LayerTypeDragHandle type={this.props.layerType} />
|
||||||
<span className="maputnik-layer-list-item-id">{this.props.layerId}</span>
|
<span className="maputnik-layer-list-item-id">{this.props.layerId}</span>
|
||||||
|
|
|
@ -62,6 +62,12 @@
|
||||||
color: $color-white;
|
color: $color-white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-item-collapsed {
|
||||||
|
height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
&-item-id {
|
&-item-id {
|
||||||
width: 115px;
|
width: 115px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
Loading…
Reference in a new issue