Example how to display fields from spec

This commit is contained in:
lukasmartinelli 2016-09-10 22:58:15 +02:00
parent 890169751b
commit 61d24fdb2b
4 changed files with 59 additions and 4 deletions

18
src/fields/enum.jsx Normal file
View file

@ -0,0 +1,18 @@
import React from 'react'
import { Select, Input } from 'rebass'
export default class EnumField extends React.Component {
static propTypes = {
name: React.PropTypes.string.isRequired,
values: React.PropTypes.array.isRequired,
value: React.PropTypes.string.isRequired,
doc: React.PropTypes.string,
}
render() {
const options = this.props.values.map(val => {
return {children: val, value: val}
})
return <Select name={this.props.name} options={options} label={this.props.name} />
}
}

View file

@ -91,11 +91,15 @@ export class LayerEditor extends React.Component {
} }
if (type === "line") { if (type === "line") {
return <LineLayer /> return <LineLayer
layer={this.props.layer}
/>
} }
if (type === "symbol") { if (type === "symbol") {
return <SymbolLayer /> return <SymbolLayer
layer={this.props.layer}
/>
} }
return <UnsupportedLayer /> return <UnsupportedLayer />

View file

@ -1,10 +1,11 @@
import React from 'react' import React from 'react'
import Immutable from 'immutable'
import { Checkbox, Input } from 'rebass' import { Checkbox, Input } from 'rebass'
import PureRenderMixin from 'react-addons-pure-render-mixin'; import PureRenderMixin from 'react-addons-pure-render-mixin';
export default class FillLayer extends React.Component { export default class FillLayer extends React.Component {
static propTypes = { static propTypes = {
layer: React.PropTypes.object.isRequired, layer: React.PropTypes.instanceOf(Immutable.Map).isRequired,
onPaintChanged: React.PropTypes.func.isRequired onPaintChanged: React.PropTypes.func.isRequired
} }

View file

@ -1,7 +1,39 @@
import React from 'react' import React from 'react'
import Immutable from 'immutable'
import spec from 'mapbox-gl-style-spec/reference/latest.min.js'
import EnumField from '../fields/enum.jsx'
export default class LineLayer extends React.Component { export default class LineLayer extends React.Component {
static propTypes = {
layer: React.PropTypes.instanceOf(Immutable.Map).isRequired,
}
render() { render() {
return <div></div> const enumFieldFromType = (key, field) => {
if(field.type === 'enum') {
return <EnumField
key={key}
name={key}
values={field.values}
value={this.props.layer.getIn(['layout', key], field.default)}
doc={field.doc}/>
}
}
const layoutLineFields = () => {
const type = spec["layout_line"]
return Object.keys(type).map(key => {
return enumFieldFromType(key, type[key])
})
}
const paintLineFields = () => {
const type = spec["paint_line"]
return Object.keys(type).map(key => {
return enumFieldFromType(key, type[key])
})
}
return <div>{layoutLineFields()}{paintLineFields()}</div>
} }
} }