import React from 'react' import cloneDeep from 'lodash.clonedeep' import Button from '../Button' import LayerListItem from './LayerListItem' import AddIcon from 'react-icons/lib/md/add-circle-outline' import style from '../../libs/style.js' import {SortableContainer, SortableHandle, arrayMove} from 'react-sortable-hoc'; const layerListPropTypes = { layers: React.PropTypes.array.isRequired, selectedLayerIndex: React.PropTypes.number.isRequired, onLayersChange: React.PropTypes.func.isRequired, onLayerSelect: React.PropTypes.func, } // List of collapsible layer editors @SortableContainer class LayerListContainer extends React.Component { static propTypes = {...layerListPropTypes} static defaultProps = { onLayerSelect: () => {}, } onLayerDestroy(layerId) { const remainingLayers = this.props.layers.slice(0) const idx = style.indexOfLayer(remainingLayers, layerId) remainingLayers.splice(idx, 1); this.props.onLayersChange(remainingLayers) } onLayerCopy(layerId) { const changedLayers = this.props.layers.slice(0) const idx = style.indexOfLayer(changedLayers, layerId) const clonedLayer = cloneDeep(changedLayers[idx]) clonedLayer.id = clonedLayer.id + "-copy" changedLayers.splice(idx, 0, clonedLayer) this.props.onLayersChange(changedLayers) } onLayerVisibilityToggle(layerId) { const changedLayers = this.props.layers.slice(0) const idx = style.indexOfLayer(changedLayers, layerId) const layer = { ...changedLayers[idx] } const changedLayout = 'layout' in layer ? {...layer.layout} : {} changedLayout.visibility = changedLayout.visibility === 'none' ? 'visible' : 'none' layer.layout = changedLayout changedLayers[idx] = layer this.props.onLayersChange(changedLayers) } render() { const layerPanels = this.props.layers.map((layer, index) => { const layerId = layer.id return }) return
Layers
} } export default class LayerList extends React.Component { static propTypes = {...layerListPropTypes} onSortEnd(move) { const { oldIndex, newIndex } = move if(oldIndex === newIndex) return let layers = this.props.layers.slice(0) layers = arrayMove(layers, oldIndex, newIndex) this.props.onLayersChange(layers) } render() { return } }