diff --git a/src/app.jsx b/src/app.jsx index f06891c0..fc0d92ed 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -4,17 +4,21 @@ import { Drawer, Container, Block, Fixed } from 'rebass' import {Map} from './map.jsx' import {Toolbar} from './toolbar.jsx' import { LayerEditor } from './layers.jsx' +import { StyleManager } from './style.js' import theme from './theme.js' import layout from './layout.scss' -import 'react-virtualized/styles.css'; +import 'react-virtualized/styles.css' export class WorkspaceDrawer extends React.Component { + static propTypes = { + styleManager: React.PropTypes.object.isRequired + } + render() { let editor = null - - if(this.props.mapStyle) { - editor = + if(this.props.styleManager.mapStyle) { + editor = } return
- - + +
- +
} diff --git a/src/layers.jsx b/src/layers.jsx index 49d5dda7..ee26e6dd 100644 --- a/src/layers.jsx +++ b/src/layers.jsx @@ -8,17 +8,25 @@ import theme from './theme.js' import scrollbars from './scrollbars.scss' export class FillLayer extends React.Component { + static propTypes = { + layer: React.PropTypes.object.isRequired, + onPaintChanged: React.PropTypes.func.isRequired + } + + onPaintChanged(property, e) { + this.props.onPaintChanged(property, e.target.value) + } + render() { + const paint = this.props.layer.paint return
- - - - - - + + + + + +
- - } } @@ -34,16 +42,30 @@ export class SymbolLayer extends React.Component { } } +export class NoLayer extends React.Component { + render() { + return
+ } +} + export class LayerPanel extends React.Component { + static propTypes = { + layer: React.PropTypes.object.isRequired, + styleManager: React.PropTypes.object.isRequired + } + static childContextTypes = { reactIconBase: React.PropTypes.object } constructor(props) { super(props); - this.toggleLayer = this.toggleLayer.bind(this); this.state = { - isOpened: false + isOpened: false, + //TODO: Is that bad practice? + //however I want to keep the layer state local herere + //otherwise the style always would, propagate around? + layer: this.props.layer } } @@ -56,18 +78,38 @@ export class LayerPanel extends React.Component { } } + onPaintChanged(property, newValue) { + let layer = this.state.layer + layer.paint[property] = newValue; + + this.props.styleManager.changeStyle({ + command: 'setPaintProperty', + args: [layer.id, property, newValue] + }) + + this.setState({ layer }); + } + toggleLayer() { this.setState({isOpened: !this.state.isOpened}) } - render() { - let layer = - if (this.props.layer.type === "line") { - layer = - } else if (this.props.layer.type === "symbol") { - layer = + layerFromType(type) { + if (type === "fill") { + return } + if (type === "line") { + return + } + + if (type === "symbol") { + return + } + return + } + + render() { return
- + - #{this.props.layer.id} + #{this.state.layer.id} @@ -91,7 +133,7 @@ export class LayerPanel extends React.Component {
- {layer} + {this.layerFromType(this.state.layer.type)}
@@ -99,10 +141,16 @@ export class LayerPanel extends React.Component { } export class LayerEditor extends React.Component { + static propTypes = { + styleManager: React.PropTypes.object.isRequired + } + render() { - const layerPanels = this.props.layers.map(layer => { - return + const layers = this.props.styleManager.layers() + const layerPanels = layers.map(layer => { + return }); + return
diff --git a/src/map.jsx b/src/map.jsx index c13710b4..c2bd229a 100644 --- a/src/map.jsx +++ b/src/map.jsx @@ -4,14 +4,29 @@ import ReactMapboxGl, { ZoomControl } from "react-mapbox-gl" import theme from './theme.js' export class Map extends React.Component { + static propTypes = { + styleManager: React.PropTypes.object.isRequired + } + constructor(props) { - super(props) + super(props) + this.map = null + } + + onStyleChange(change) { + this.map[change.command].apply(this.map, change.args); + } + + onMapLoaded(map) { + this.map = map; + this.props.styleManager.onStyleChange(this.onStyleChange.bind(this)) } render() { - if (this.props.mapStyle) { + if (this.props.styleManager.mapStyle) { return @@ -19,4 +34,3 @@ export class Map extends React.Component { return
} } - diff --git a/src/style.js b/src/style.js index 8ff89055..8f3cbf50 100644 --- a/src/style.js +++ b/src/style.js @@ -1,27 +1,31 @@ import React from 'react'; -// A wrapper around Mapbox GL style -export class Style { - constructor() { - this.styleHistory = []; - this.renderers = []; +// A wrapper around Mapbox GL style to publish +// and subscribe to map changes +export class StyleManager { + constructor(mapStyle) { + this.commandHistory = []; + this.subscribers = []; + this.mapStyle = mapStyle; } - load(style) { - this.currentStyle = style; + onStyleChange(cb) { + this.subscribers.push(cb); } - onRender(cb) { - this.renderers.push(cb); + changeStyle(command) { + this.commandHistory.push(command) + this.subscribers.forEach(f => f(command)) + console.log(command) } - update(style) { - this.styleHistory.push(this.currentStyle); - this.currentStyle = style; - this.renderers.forEach(r => r(this.currentStyle)) + layer(layerId) { + console.log(this.mapStyle) + return this.mapStyle.layers[layerId] } layers() { - return this.currentStyle.layers; + if(this.mapStyle) return this.mapStyle.layers + return [] } }