Support id and type switching

This commit is contained in:
Lukas Martinelli 2016-12-22 15:49:36 +01:00
parent 3cc9f45085
commit c674436267
4 changed files with 30 additions and 24 deletions

View file

@ -78,7 +78,20 @@ export default class App extends React.Component {
this.setState({ mapStyle: changedStyle }) this.setState({ mapStyle: changedStyle })
} }
onLayerIdChange(oldId, newId) {
const changedLayers = this.state.mapStyle.layers.slice(0)
const idx = style.indexOfLayer(changedLayers, oldId)
changedLayers[idx] = {
...changedLayers[idx],
id: newId
}
this.onLayersChange(changedLayers)
}
onLayerChanged(layer) { onLayerChanged(layer) {
console.log('layer changed', layer)
const changedLayers = this.state.mapStyle.layers.slice(0) const changedLayers = this.state.mapStyle.layers.slice(0)
const idx = style.indexOfLayer(changedLayers, layer.id) const idx = style.indexOfLayer(changedLayers, layer.id)
changedLayers[idx] = layer changedLayers[idx] = layer
@ -133,6 +146,7 @@ export default class App extends React.Component {
sources={this.layerWatcher.sources} sources={this.layerWatcher.sources}
vectorLayers={this.layerWatcher.vectorLayers} vectorLayers={this.layerWatcher.vectorLayers}
onLayerChanged={this.onLayerChanged.bind(this)} onLayerChanged={this.onLayerChanged.bind(this)}
onLayerIdChange={this.onLayerIdChange.bind(this)}
/> : null /> : null
return <Layout return <Layout

View file

@ -1,5 +1,4 @@
import React from 'react' import React from 'react'
import PureRenderMixin from 'react-addons-pure-render-mixin';
import GlSpec from 'mapbox-gl-style-spec/reference/latest.min.js' import GlSpec from 'mapbox-gl-style-spec/reference/latest.min.js'
import input from '../../config/input.js' import input from '../../config/input.js'
@ -133,11 +132,6 @@ export default class CombiningFilterEditor extends React.Component {
onChange: React.PropTypes.func.isRequired, onChange: React.PropTypes.func.isRequired,
} }
constructor(props) {
super(props);
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
}
// Convert filter to combining filter // Convert filter to combining filter
combiningFilter() { combiningFilter() {
let combiningOp = this.props.filter[0] let combiningOp = this.props.filter[0]

View file

@ -24,10 +24,12 @@ export default class LayerEditor extends React.Component {
sources: React.PropTypes.object, sources: React.PropTypes.object,
vectorLayers: React.PropTypes.object, vectorLayers: React.PropTypes.object,
onLayerChanged: React.PropTypes.func, onLayerChanged: React.PropTypes.func,
onLayerIdChange: React.PropTypes.func,
} }
static defaultProps = { static defaultProps = {
onLayerChanged: () => {}, onLayerChanged: () => {},
onLayerIdChange: () => {},
onLayerDestroyed: () => {}, onLayerDestroyed: () => {},
} }
@ -74,14 +76,20 @@ export default class LayerEditor extends React.Component {
* to a {@newValue}. * to a {@newValue}.
*/ */
onPropertyChange(group, property, newValue) { onPropertyChange(group, property, newValue) {
const changedLayer = { if(group) {
...this.props.layer, this.props.onLayerChanged({
[group]: { ...this.props.layer,
...this.props.layer[group], [group]: {
...this.props.layer[group],
[property]: newValue
}
})
} else {
this.props.onLayerChanged({
...this.props.layer,
[property]: newValue [property]: newValue
} })
} }
this.props.onLayerChanged(changedLayer)
} }
onFilterChange(newValue) { onFilterChange(newValue) {
@ -107,6 +115,8 @@ export default class LayerEditor extends React.Component {
case 'settings': return <LayerSettings case 'settings': return <LayerSettings
id={this.props.layer.id} id={this.props.layer.id}
type={this.props.layer.type} type={this.props.layer.type}
onTypeChange={v => this.onPropertyChange(null, 'type', v)}
onIdChange={newId => this.props.onLayerIdChange(this.props.layer.id, newId)}
/> />
case 'source': return <div> case 'source': return <div>
<FilterEditor <FilterEditor
@ -136,7 +146,6 @@ export default class LayerEditor extends React.Component {
} }
render() { render() {
console.log('editor groups', this.state.editorGroups)
const layerType = this.props.layer.type const layerType = this.props.layer.type
const layoutGroups = layout[layerType].groups.filter(group => { const layoutGroups = layout[layerType].groups.filter(group => {
return !(this.props.layer.type === 'background' && group.type === 'source') return !(this.props.layer.type === 'background' && group.type === 'source')

View file

@ -1,5 +1,4 @@
import React from 'react' import React from 'react'
import PureRenderMixin from 'react-addons-pure-render-mixin';
import cloneDeep from 'lodash.clonedeep' import cloneDeep from 'lodash.clonedeep'
import LayerListItem from './LayerListItem' import LayerListItem from './LayerListItem'
@ -24,11 +23,6 @@ class LayerListContainer extends React.Component {
onLayerSelect: () => {}, onLayerSelect: () => {},
} }
constructor(props) {
super(props)
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
}
onLayerDestroy(layerId) { onLayerDestroy(layerId) {
const remainingLayers = this.props.layers.slice(0) const remainingLayers = this.props.layers.slice(0)
const idx = style.indexOfLayer(remainingLayers, layerId) const idx = style.indexOfLayer(remainingLayers, layerId)
@ -87,11 +81,6 @@ class LayerListContainer extends React.Component {
export default class LayerList extends React.Component { export default class LayerList extends React.Component {
static propTypes = {...layerListPropTypes} static propTypes = {...layerListPropTypes}
constructor(props) {
super(props)
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
}
onSortEnd(move) { onSortEnd(move) {
const { oldIndex, newIndex } = move const { oldIndex, newIndex } = move
if(oldIndex === newIndex) return if(oldIndex === newIndex) return