2016-09-10 14:10:25 +02:00
|
|
|
import React from 'react'
|
2016-09-10 16:53:58 +02:00
|
|
|
import Immutable from 'immutable'
|
|
|
|
|
2016-09-15 09:13:23 +02:00
|
|
|
import Toolbar from 'rebass/dist/Toolbar'
|
|
|
|
import NavItem from 'rebass/dist/NavItem'
|
|
|
|
import Space from 'rebass/dist/Space'
|
2016-12-19 15:40:11 +01:00
|
|
|
import Tabs from 'react-simpletabs'
|
2016-09-15 09:13:23 +02:00
|
|
|
|
2016-12-20 11:44:22 +01:00
|
|
|
import SourceEditor from './SourceEditor'
|
|
|
|
import FilterEditor from '../filter/FilterEditor'
|
|
|
|
import PropertyGroup from '../fields/PropertyGroup'
|
2016-12-19 15:40:11 +01:00
|
|
|
|
2016-09-10 14:47:06 +02:00
|
|
|
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'
|
2016-09-10 21:35:21 +02:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
2016-09-10 14:47:06 +02:00
|
|
|
|
2016-12-20 11:44:22 +01:00
|
|
|
import ScrollContainer from '../ScrollContainer'
|
|
|
|
|
|
|
|
import layout from '../../config/layout.json'
|
|
|
|
import theme from '../../config/rebass.js'
|
2016-12-17 20:19:01 +01:00
|
|
|
|
2016-09-10 14:10:25 +02:00
|
|
|
class UnsupportedLayer extends React.Component {
|
2016-12-17 15:44:42 +01:00
|
|
|
render() {
|
|
|
|
return <div></div>
|
|
|
|
}
|
2016-09-10 14:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Layer editor supporting multiple types of layers. */
|
2016-12-20 11:44:22 +01:00
|
|
|
export default class LayerEditor extends React.Component {
|
2016-12-17 15:44:42 +01:00
|
|
|
static propTypes = {
|
|
|
|
layer: React.PropTypes.object.isRequired,
|
2016-12-18 18:58:33 +01:00
|
|
|
sources: React.PropTypes.instanceOf(Immutable.Map),
|
2016-12-20 11:44:22 +01:00
|
|
|
vectorLayers: React.PropTypes.instanceOf(Immutable.Map),
|
2016-12-17 15:44:42 +01:00
|
|
|
onLayerChanged: React.PropTypes.func,
|
|
|
|
onLayerDestroyed: React.PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
onLayerChanged: () => {},
|
|
|
|
onLayerDestroyed: () => {},
|
|
|
|
}
|
|
|
|
|
|
|
|
static childContextTypes = {
|
|
|
|
reactIconBase: React.PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
getChildContext () {
|
|
|
|
return {
|
|
|
|
reactIconBase: {
|
|
|
|
size: theme.fontSizes[4],
|
|
|
|
color: theme.colors.lowgray,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 20:15:30 +01:00
|
|
|
onPropertyChange(group, property, newValue) {
|
|
|
|
const layer = this.props.layer
|
|
|
|
const changedLayer = layer.setIn([group, property], newValue)
|
2016-12-17 15:44:42 +01:00
|
|
|
this.props.onLayerChanged(changedLayer)
|
|
|
|
}
|
|
|
|
|
2016-12-19 20:15:30 +01:00
|
|
|
onFilterChange(newValue) {
|
2016-12-19 14:56:10 +01:00
|
|
|
let layer = this.props.layer
|
|
|
|
const changedLayer = layer.set('filter', newValue)
|
|
|
|
this.props.onLayerChanged(changedLayer)
|
|
|
|
}
|
|
|
|
|
2016-12-17 15:44:42 +01:00
|
|
|
toggleVisibility() {
|
|
|
|
if(this.props.layer.has('layout') && this.props.layer.getIn(['layout', 'visibility']) === 'none') {
|
|
|
|
this.onLayoutChanged('visibility', 'visible')
|
|
|
|
} else {
|
|
|
|
this.onLayoutChanged('visibility', 'none')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-12-19 20:15:30 +01:00
|
|
|
const layerType = this.props.layer.get('type')
|
|
|
|
const groups = layout[layerType].groups
|
|
|
|
const propertyGroups = groups.map(group => {
|
|
|
|
return <PropertyGroup
|
2016-12-20 11:44:22 +01:00
|
|
|
key={this.props.group}
|
2016-12-19 20:15:30 +01:00
|
|
|
layer={this.props.layer}
|
|
|
|
groupFields={Immutable.OrderedSet(group.fields)}
|
|
|
|
onChange={this.onPropertyChange.bind(this)}
|
|
|
|
/>
|
|
|
|
})
|
|
|
|
|
2016-12-20 11:44:22 +01:00
|
|
|
console.log(this.props.layer.toJSON())
|
2016-12-17 15:44:42 +01:00
|
|
|
let visibleIcon = <MdVisibilityOff />
|
|
|
|
if(this.props.layer.has('layout') && this.props.layer.getIn(['layout', 'visibility']) === 'none') {
|
|
|
|
visibleIcon = <MdVisibility />
|
|
|
|
}
|
|
|
|
return <div style={{
|
|
|
|
padding: theme.scale[0],
|
2016-12-19 20:15:30 +01:00
|
|
|
}}>
|
2016-12-17 16:09:37 +01:00
|
|
|
<Toolbar>
|
2016-12-17 15:44:42 +01:00
|
|
|
<NavItem style={{fontWeight: 400}}>
|
2016-12-19 20:15:30 +01:00
|
|
|
{this.props.layer.get('id')}
|
2016-12-17 15:44:42 +01:00
|
|
|
</NavItem>
|
|
|
|
<Space auto x={1} />
|
|
|
|
<NavItem onClick={this.toggleVisibility.bind(this)}>
|
|
|
|
{visibleIcon}
|
|
|
|
</NavItem>
|
|
|
|
<NavItem onClick={(e) => this.props.onLayerDestroyed(this.props.layer)}>
|
|
|
|
<MdDelete />
|
|
|
|
</NavItem>
|
|
|
|
</Toolbar>
|
2016-12-19 20:15:30 +01:00
|
|
|
{propertyGroups}
|
2016-12-19 15:40:11 +01:00
|
|
|
<FilterEditor
|
|
|
|
filter={this.props.layer.get('filter', Immutable.List()).toJSON()}
|
2016-12-20 11:44:22 +01:00
|
|
|
properties={this.props.vectorLayers.get(this.props.layer.get('source-layer'))}
|
2016-12-19 20:15:30 +01:00
|
|
|
onChange={f => this.onFilterChange(Immutable.fromJS(f))}
|
2016-12-19 15:40:11 +01:00
|
|
|
/>
|
2016-12-19 20:15:30 +01:00
|
|
|
{this.props.layer.get('type') !== 'background'
|
|
|
|
&& <SourceEditor
|
2016-12-19 15:40:11 +01:00
|
|
|
source={this.props.layer.get('source')}
|
|
|
|
sourceLayer={this.props.layer.get('source-layer')}
|
|
|
|
sources={this.props.sources}
|
|
|
|
onSourceChange={console.log}
|
|
|
|
onSourceLayerChange={console.log}
|
|
|
|
/>}
|
2016-12-17 15:44:42 +01:00
|
|
|
</div>
|
|
|
|
}
|
2016-09-10 14:10:25 +02:00
|
|
|
}
|