2016-09-10 14:10:25 +02:00
|
|
|
import React from 'react'
|
2016-09-10 16:53:58 +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-21 11:24:32 +01:00
|
|
|
import LayerEditorGroup from './LayerEditorGroup'
|
2016-12-22 13:40:23 +01:00
|
|
|
import LayerSettings from './LayerSettings'
|
2016-12-19 15:40:11 +01:00
|
|
|
|
2016-12-20 11:44:22 +01:00
|
|
|
import layout from '../../config/layout.json'
|
2016-12-21 14:46:51 +01:00
|
|
|
import { margins, fontSizes } from '../../config/scales'
|
|
|
|
import colors from '../../config/colors'
|
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-20 16:08:49 +01:00
|
|
|
sources: React.PropTypes.object,
|
|
|
|
vectorLayers: React.PropTypes.object,
|
2016-12-17 15:44:42 +01:00
|
|
|
onLayerChanged: React.PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
onLayerChanged: () => {},
|
|
|
|
onLayerDestroyed: () => {},
|
|
|
|
}
|
|
|
|
|
|
|
|
static childContextTypes = {
|
|
|
|
reactIconBase: React.PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
2016-12-21 11:24:32 +01:00
|
|
|
super(props)
|
|
|
|
|
|
|
|
//TODO: Clean this up and refactor into function
|
|
|
|
const editorGroups = {}
|
|
|
|
layout[this.props.layer.type].groups.forEach(group => {
|
|
|
|
editorGroups[group.title] = true
|
|
|
|
})
|
|
|
|
editorGroups['Source'] = true
|
2016-12-22 13:40:23 +01:00
|
|
|
editorGroups['Settings'] = true
|
2016-12-21 11:24:32 +01:00
|
|
|
|
|
|
|
this.state = { editorGroups }
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
const additionalGroups = { ...this.state.editorGroups }
|
|
|
|
|
|
|
|
layout[nextProps.layer.type].groups.forEach(group => {
|
|
|
|
if(!(group.title in additionalGroups)) {
|
|
|
|
additionalGroups[group.title] = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
editorGroups: additionalGroups
|
|
|
|
})
|
2016-12-17 15:44:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getChildContext () {
|
|
|
|
return {
|
|
|
|
reactIconBase: {
|
2016-12-21 14:46:51 +01:00
|
|
|
size: fontSizes[4],
|
|
|
|
color: colors.lowgray,
|
2016-12-17 15:44:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-20 14:50:38 +01:00
|
|
|
/** A {@property} in either the paint our layout {@group} has changed
|
|
|
|
* to a {@newValue}.
|
|
|
|
*/
|
2016-12-19 20:15:30 +01:00
|
|
|
onPropertyChange(group, property, newValue) {
|
2016-12-20 14:50:38 +01:00
|
|
|
const changedLayer = {
|
|
|
|
...this.props.layer,
|
|
|
|
[group]: {
|
|
|
|
...this.props.layer[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-20 14:50:38 +01:00
|
|
|
const changedLayer = {
|
|
|
|
...this.props.layer,
|
|
|
|
filter: newValue
|
|
|
|
}
|
2016-12-19 14:56:10 +01:00
|
|
|
this.props.onLayerChanged(changedLayer)
|
|
|
|
}
|
|
|
|
|
2016-12-21 11:24:32 +01:00
|
|
|
onGroupToggle(groupTitle, active) {
|
|
|
|
const changedActiveGroups = {
|
|
|
|
...this.state.editorGroups,
|
|
|
|
[groupTitle]: active,
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
editorGroups: changedActiveGroups
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-17 15:44:42 +01:00
|
|
|
render() {
|
2016-12-21 11:24:32 +01:00
|
|
|
console.log('editor groups', this.state.editorGroups)
|
2016-12-20 14:50:38 +01:00
|
|
|
const layerType = this.props.layer.type
|
2016-12-19 20:15:30 +01:00
|
|
|
const groups = layout[layerType].groups
|
|
|
|
const propertyGroups = groups.map(group => {
|
2016-12-21 11:24:32 +01:00
|
|
|
return <LayerEditorGroup
|
|
|
|
key={group.title}
|
|
|
|
title={group.title}
|
|
|
|
isActive={this.state.editorGroups[group.title]}
|
|
|
|
onActiveToggle={this.onGroupToggle.bind(this, group.title)}
|
|
|
|
>
|
|
|
|
<PropertyGroup
|
|
|
|
layer={this.props.layer}
|
|
|
|
groupFields={group.fields}
|
|
|
|
onChange={this.onPropertyChange.bind(this)}
|
|
|
|
/>
|
|
|
|
</LayerEditorGroup>
|
2016-12-19 20:15:30 +01:00
|
|
|
})
|
|
|
|
|
2016-12-21 11:24:32 +01:00
|
|
|
let dataGroup = null
|
|
|
|
if(this.props.layer.type !== 'background') {
|
|
|
|
dataGroup = <LayerEditorGroup
|
|
|
|
title="Source"
|
|
|
|
isActive={this.state.editorGroups['Source']}
|
|
|
|
onActiveToggle={this.onGroupToggle.bind(this, 'Source')}
|
|
|
|
>
|
|
|
|
<FilterEditor
|
|
|
|
filter={this.props.layer.filter}
|
|
|
|
properties={this.props.vectorLayers[this.props.layer['source-layer']]}
|
|
|
|
onChange={f => this.onFilterChange(f)}
|
|
|
|
/>
|
|
|
|
<SourceEditor
|
|
|
|
source={this.props.layer.source}
|
|
|
|
sourceLayer={this.props.layer['source-layer']}
|
|
|
|
sources={this.props.sources}
|
|
|
|
onSourceChange={console.log}
|
|
|
|
onSourceLayerChange={console.log}
|
|
|
|
/>
|
|
|
|
</LayerEditorGroup>
|
|
|
|
}
|
|
|
|
|
2016-12-22 13:40:23 +01:00
|
|
|
const settingsGroup = <LayerEditorGroup
|
|
|
|
title="Settings"
|
|
|
|
isActive={this.state.editorGroups['Settings']}
|
|
|
|
onActiveToggle={this.onGroupToggle.bind(this, 'Settings')}
|
|
|
|
>
|
|
|
|
<LayerSettings
|
|
|
|
id={this.props.layer.id}
|
|
|
|
type={this.props.layer.type}
|
|
|
|
/>
|
|
|
|
</LayerEditorGroup>
|
|
|
|
|
2016-12-22 12:06:04 +01:00
|
|
|
return <div>
|
2016-12-22 13:40:23 +01:00
|
|
|
{settingsGroup}
|
2016-12-21 11:24:32 +01:00
|
|
|
{dataGroup}
|
2016-12-22 13:40:23 +01:00
|
|
|
{propertyGroups}
|
2016-12-17 15:44:42 +01:00
|
|
|
</div>
|
|
|
|
}
|
2016-09-10 14:10:25 +02:00
|
|
|
}
|