2016-12-19 20:15:30 +01:00
|
|
|
import React from 'react'
|
|
|
|
import Immutable from 'immutable'
|
|
|
|
import GlSpec from 'mapbox-gl-style-spec/reference/latest.min.js'
|
|
|
|
|
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 = {
|
|
|
|
layer: React.PropTypes.instanceOf(Immutable.Map).isRequired,
|
|
|
|
groupFields: React.PropTypes.instanceOf(Immutable.OrderedSet).isRequired,
|
|
|
|
onChange: React.PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
2016-12-20 14:13:37 +01:00
|
|
|
onPropertyChange(property, newValue) {
|
|
|
|
const group = getGroupName(this.props.layer.get('type'), property)
|
|
|
|
this.props.onChange(group , property ,newValue)
|
|
|
|
}
|
|
|
|
|
2016-12-19 20:15:30 +01:00
|
|
|
render() {
|
|
|
|
const fields = this.props.groupFields.map(fieldName => {
|
|
|
|
const fieldSpec = getFieldSpec(this.props.layer.get('type'), fieldName)
|
|
|
|
const fieldValue = this.props.layer.getIn(['paint', fieldName], this.props.layer.getIn(['layout', fieldName]))
|
|
|
|
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}
|
|
|
|
/>
|
|
|
|
}).toIndexedSeq()
|
|
|
|
|
|
|
|
return <div style={{
|
2016-12-20 11:44:22 +01:00
|
|
|
padding: margins[2],
|
2016-12-19 20:15:30 +01:00
|
|
|
paddingRight: 0,
|
2016-12-20 11:44:22 +01:00
|
|
|
backgroundColor: colors.black,
|
|
|
|
marginBottom: margins[2],
|
2016-12-19 20:15:30 +01:00
|
|
|
}}>
|
|
|
|
{fields}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|