import React from 'react' import Immutable from 'immutable' import { Toolbar, NavItem, Space} from 'rebass' import Collapse from 'react-collapse' import theme from '../theme.js' import FillLayer from './fill.jsx' import LineLayer from './line.jsx' import SymbolLayer from './line.jsx' import BackgroundLayer from './background.jsx' import MdVisibility from 'react-icons/lib/md/visibility' import MdVisibilityOff from 'react-icons/lib/md/visibility-off' import MdDelete from 'react-icons/lib/md/delete' class UnsupportedLayer extends React.Component { render() { return
} } /** Layer editor supporting multiple types of layers. */ export class LayerEditor extends React.Component { static propTypes = { layer: React.PropTypes.object.isRequired, onLayerChanged: React.PropTypes.func.isRequired, onLayerDestroyed: React.PropTypes.func.isRequired, } static childContextTypes = { reactIconBase: React.PropTypes.object } constructor(props) { super(props); this.state = { isOpened: false, } } getChildContext () { return { reactIconBase: { size: theme.fontSizes[4], color: theme.colors.lowgray, } } } onPaintChanged(property, newValue) { let layer = this.props.layer //TODO: by using immutable records we can avoid this checking if object exists if(!layer.has('paint')) { layer = layer.set('paint', Immutable.Map()) } const changedLayer = layer.setIn(['paint', property], newValue) this.props.onLayerChanged(changedLayer) } onLayoutChanged(property, newValue) { let layer = this.props.layer //TODO: by using immutable records we can avoid this checking if object exists if(!layer.has('layout')) { layer = layer.set('layout', Immutable.Map()) } const changedLayer = layer.setIn(['layout', property], newValue) this.props.onLayerChanged(changedLayer) } toggleLayer() { this.setState({isOpened: !this.state.isOpened}) } layerFromType(type) { if (type === "fill") { return } if (type === "background") { return } if (type === "line") { return } if (type === "symbol") { return } return } toggleVisibility() { if(this.props.layer.has('layout') && this.props.layer.getIn(['layout', 'visibility']) === 'none') { this.onLayoutChanged('visibility', 'visible') } else { this.onLayoutChanged('visibility', 'none') } } render() { let visibleIcon = if(this.props.layer.has('layout') && this.props.layer.getIn(['layout', 'visibility']) === 'none') { visibleIcon = } return
#{this.props.layer.get('id')} {visibleIcon} this.props.onLayerDestroyed(this.props.layer)}>
{this.layerFromType(this.props.layer.get('type'))}
} }