2016-12-19 20:15:30 +01:00
|
|
|
import React from 'react'
|
2016-12-25 19:00:21 +01:00
|
|
|
import GlSpec from 'mapbox-gl-style-spec/reference/latest.js'
|
2016-12-19 20:15:30 +01:00
|
|
|
|
2016-12-20 11:44:22 +01:00
|
|
|
import ZoomSpecField from './ZoomSpecField'
|
|
|
|
import colors from '../../config/colors'
|
|
|
|
import { margins } from '../../config/scales'
|
2016-12-19 20:15:30 +01:00
|
|
|
|
2016-12-20 11:44:22 +01:00
|
|
|
/** Extract field spec by {@fieldName} from the {@layerType} in the
|
|
|
|
* style specification from either the paint or layout group */
|
2016-12-19 20:15:30 +01:00
|
|
|
function getFieldSpec(layerType, fieldName) {
|
2016-12-20 14:13:37 +01:00
|
|
|
const groupName = getGroupName(layerType, fieldName)
|
|
|
|
const group = GlSpec[groupName + '_' + layerType]
|
|
|
|
return group[fieldName]
|
|
|
|
}
|
|
|
|
|
|
|
|
function getGroupName(layerType, fieldName) {
|
2016-12-19 20:15:30 +01:00
|
|
|
const paint = GlSpec['paint_' + layerType] || {}
|
|
|
|
if (fieldName in paint) {
|
2016-12-20 14:13:37 +01:00
|
|
|
return 'paint'
|
2016-12-19 20:15:30 +01:00
|
|
|
} else {
|
2016-12-20 14:13:37 +01:00
|
|
|
return 'layout'
|
2016-12-19 20:15:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class PropertyGroup extends React.Component {
|
|
|
|
static propTypes = {
|
2016-12-20 14:50:38 +01:00
|
|
|
layer: React.PropTypes.object.isRequired,
|
2016-12-20 16:08:49 +01:00
|
|
|
groupFields: React.PropTypes.array.isRequired,
|
2016-12-19 20:15:30 +01:00
|
|
|
onChange: React.PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
2016-12-20 14:13:37 +01:00
|
|
|
onPropertyChange(property, newValue) {
|
2016-12-20 14:50:38 +01:00
|
|
|
const group = getGroupName(this.props.layer.type, property)
|
2016-12-30 16:18:53 +01:00
|
|
|
this.props.onChange(group , property, newValue)
|
2016-12-20 14:13:37 +01:00
|
|
|
}
|
|
|
|
|
2016-12-19 20:15:30 +01:00
|
|
|
render() {
|
|
|
|
const fields = this.props.groupFields.map(fieldName => {
|
2016-12-20 14:50:38 +01:00
|
|
|
const fieldSpec = getFieldSpec(this.props.layer.type, fieldName)
|
|
|
|
|
|
|
|
const paint = this.props.layer.paint || {}
|
|
|
|
const layout = this.props.layer.layout || {}
|
2016-12-30 16:18:53 +01:00
|
|
|
const fieldValue = fieldName in paint ? paint[fieldName] : layout[fieldName]
|
2016-12-20 14:50:38 +01:00
|
|
|
|
2016-12-19 20:15:30 +01:00
|
|
|
return <ZoomSpecField
|
2016-12-20 14:13:37 +01:00
|
|
|
onChange={this.onPropertyChange.bind(this)}
|
2016-12-19 20:15:30 +01:00
|
|
|
key={fieldName}
|
|
|
|
fieldName={fieldName}
|
|
|
|
value={fieldValue}
|
|
|
|
fieldSpec={fieldSpec}
|
|
|
|
/>
|
2016-12-20 16:08:49 +01:00
|
|
|
})
|
2016-12-19 20:15:30 +01:00
|
|
|
|
2016-12-30 20:01:14 +01:00
|
|
|
return <div>
|
2016-12-19 20:15:30 +01:00
|
|
|
{fields}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|