Add source layer support

This commit is contained in:
lukasmartinelli
2016-09-10 22:08:26 +02:00
parent 95ae8892f4
commit 890169751b
6 changed files with 150 additions and 3 deletions

86
src/sources/editor.jsx Normal file
View File

@@ -0,0 +1,86 @@
import React from 'react'
import Immutable from 'immutable'
import { Input, Toolbar, NavItem, Space} from 'rebass'
import Collapse from 'react-collapse'
import PureRenderMixin from 'react-addons-pure-render-mixin';
import theme from '../theme.js'
class UnsupportedSource extends React.Component {
render() {
return <div></div>
}
}
class VectorSource extends React.Component {
static propTypes = {
source: React.PropTypes.instanceOf(Immutable.Map).isRequired,
}
constructor(props) {
super(props);
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
}
render() {
return <div>
<Input name="url" label="TileJSON url" value={this.props.source.get("url")} />
<Input name="minzoom" label="Minimum zoom level" value={this.props.source.get("minzoom")} />
<Input name="maxzoom" label="Maximum zoom level" value={this.props.source.get("maxzoom")} />
</div>
}
}
export class SourceEditor extends React.Component {
static propTypes = {
sourceId: React.PropTypes.string.isRequired,
source: React.PropTypes.instanceOf(Immutable.Map).isRequired,
}
constructor(props) {
super(props);
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
this.state = {
isOpened: false,
}
}
toggleLayer() {
this.setState({isOpened: !this.state.isOpened})
}
sourceFromType(type) {
if (type === "vector") {
return <VectorSource
source={this.props.source}
/>
}
return <UnsupportedSource />
}
render() {
return <div style={{
padding: theme.scale[0],
borderBottom: 1,
borderTop: 1,
borderLeft: 2,
borderRight: 0,
borderStyle: "solid",
borderColor: theme.borderColor,
}}>
<Toolbar onClick={this.toggleLayer.bind(this)}>
<NavItem style={{fontWeight: 400}}>
#{this.props.sourceId}
</NavItem>
<Space auto x={1} />
</Toolbar>
<Collapse isOpened={this.state.isOpened}>
<div style={{padding: theme.scale[2], paddingRight: 0, backgroundColor: theme.colors.black}}>
{this.sourceFromType(this.props.source.get('type'))}
</div>
</Collapse>
</div>
}
}

38
src/sources/list.jsx Normal file
View File

@@ -0,0 +1,38 @@
import React from 'react'
import Immutable from 'immutable'
import { Heading, Toolbar, NavItem, Space} from 'rebass'
import { SourceEditor } from './editor.jsx'
import scrollbars from '../scrollbars.scss'
import PureRenderMixin from 'react-addons-pure-render-mixin';
// List of collapsible layer editors
export class SourceList extends React.Component {
static propTypes = {
sources: React.PropTypes.instanceOf(Immutable.Map).isRequired,
}
constructor(props) {
super(props)
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
}
render() {
const sourceEditors = this.props.sources.map((source, sourceId) => {
return <SourceEditor
key={sourceId}
sourceId={sourceId}
source={source}
/>
}).toIndexedSeq()
return <div>
<Toolbar style={{marginRight: 20}}>
<NavItem>
<Heading>Layers</Heading>
</NavItem>
<Space auto x={1} />
</Toolbar>
{sourceEditors}
</div>
}
}