Fix bug setting layout/paint props directly on layer

This commit is contained in:
Lukas Martinelli 2016-12-20 14:13:37 +01:00
parent 7ca48add75
commit 9374ff29e7
4 changed files with 32 additions and 34 deletions

View file

@ -9,12 +9,17 @@ import { margins } from '../../config/scales'
/** Extract field spec by {@fieldName} from the {@layerType} in the /** Extract field spec by {@fieldName} from the {@layerType} in the
* style specification from either the paint or layout group */ * style specification from either the paint or layout group */
function getFieldSpec(layerType, fieldName) { function getFieldSpec(layerType, fieldName) {
const groupName = getGroupName(layerType, fieldName)
const group = GlSpec[groupName + '_' + layerType]
return group[fieldName]
}
function getGroupName(layerType, fieldName) {
const paint = GlSpec['paint_' + layerType] || {} const paint = GlSpec['paint_' + layerType] || {}
const layout = GlSpec['layout_' + layerType] || {}
if (fieldName in paint) { if (fieldName in paint) {
return paint[fieldName] return 'paint'
} else { } else {
return layout[fieldName] return 'layout'
} }
} }
@ -25,12 +30,17 @@ export default class PropertyGroup extends React.Component {
onChange: React.PropTypes.func.isRequired, onChange: React.PropTypes.func.isRequired,
} }
onPropertyChange(property, newValue) {
const group = getGroupName(this.props.layer.get('type'), property)
this.props.onChange(group , property ,newValue)
}
render() { render() {
const fields = this.props.groupFields.map(fieldName => { const fields = this.props.groupFields.map(fieldName => {
const fieldSpec = getFieldSpec(this.props.layer.get('type'), fieldName) const fieldSpec = getFieldSpec(this.props.layer.get('type'), fieldName)
const fieldValue = this.props.layer.getIn(['paint', fieldName], this.props.layer.getIn(['layout', fieldName])) const fieldValue = this.props.layer.getIn(['paint', fieldName], this.props.layer.getIn(['layout', fieldName]))
return <ZoomSpecField return <ZoomSpecField
onChange={this.props.onChange} onChange={this.onPropertyChange.bind(this)}
key={fieldName} key={fieldName}
fieldName={fieldName} fieldName={fieldName}
value={fieldValue} value={fieldValue}

View file

@ -41,60 +41,43 @@ export default class SpecField extends React.Component {
style: React.PropTypes.object, style: React.PropTypes.object,
} }
onValueChanged(property, value) {
return this.props.onChange(property, value)
}
render() { render() {
const commonProps = {
doc: this.props.fieldSpec.doc,
style: this.props.style,
value: this.props.value,
name: this.props.fieldName,
onChange: newValue => this.props.onChange(this.props.fieldName, newValue)
}
switch(this.props.fieldSpec.type) { switch(this.props.fieldSpec.type) {
case 'number': return ( case 'number': return (
<NumberField <NumberField
onChange={this.onValueChanged.bind(this, this.props.fieldName)} {...commonProps}
value={this.props.value}
name={this.props.fieldName}
default={this.props.fieldSpec.default} default={this.props.fieldSpec.default}
min={this.props.fieldSpec.min} min={this.props.fieldSpec.min}
max={this.props.fieldSpec.max} max={this.props.fieldSpec.max}
unit={this.props.fieldSpec.unit} unit={this.props.fieldSpec.unit}
doc={this.props.fieldSpec.doc}
style={this.props.style}
/> />
) )
case 'enum': return ( case 'enum': return (
<EnumField <EnumField
onChange={this.onValueChanged.bind(this, this.props.fieldName)} {...commonProps}
value={this.props.value}
name={this.props.fieldName}
allowedValues={Object.keys(this.props.fieldSpec.values)} allowedValues={Object.keys(this.props.fieldSpec.values)}
doc={this.props.fieldSpec.doc}
style={this.props.style}
/> />
) )
case 'string': return ( case 'string': return (
<StringField <StringField
onChange={this.onValueChanged.bind(this, this.props.fieldName)} {...commonProps}
value={this.props.value}
name={this.props.fieldName}
doc={this.props.fieldSpec.doc}
style={this.props.style}
/> />
) )
case 'color': return ( case 'color': return (
<ColorField <ColorField
onChange={this.onValueChanged.bind(this, this.props.fieldName)} {...commonProps}
value={this.props.value}
name={this.props.fieldName}
doc={this.props.fieldSpec.doc}
style={this.props.style}
/> />
) )
case 'boolean': return ( case 'boolean': return (
<BooleanField <BooleanField
onChange={this.onValueChanged.bind(this, this.props.fieldName)} {...commonProps}
value={this.props.value}
name={this.props.fieldName}
doc={this.props.fieldSpec.doc}
style={this.props.style}
/> />
) )
default: return null default: return null

View file

@ -75,7 +75,11 @@ class SingleFilterEditor extends React.Component {
static propTypes = { static propTypes = {
filter: React.PropTypes.array.isRequired, filter: React.PropTypes.array.isRequired,
onChange: React.PropTypes.func.isRequired, onChange: React.PropTypes.func.isRequired,
properties: React.PropTypes.instanceOf(Immutable.Map).isRequired, properties: React.PropTypes.instanceOf(Immutable.Map),
}
static defaultProps = {
properties: Immutable.Map(),
} }
onFilterPartChanged(filterOp, propertyName, filterArgs) { onFilterPartChanged(filterOp, propertyName, filterArgs) {

View file

@ -61,6 +61,7 @@ export default class LayerEditor extends React.Component {
onPropertyChange(group, property, newValue) { onPropertyChange(group, property, newValue) {
const layer = this.props.layer const layer = this.props.layer
console.log(group, property, newValue)
const changedLayer = layer.setIn([group, property], newValue) const changedLayer = layer.setIn([group, property], newValue)
this.props.onLayerChanged(changedLayer) this.props.onLayerChanged(changedLayer)
} }