From 890169751b2ee33df4ee18e498416d8cfbfba585 Mon Sep 17 00:00:00 2001 From: lukasmartinelli Date: Sat, 10 Sep 2016 22:08:26 +0200 Subject: [PATCH] Add source layer support --- src/app.jsx | 7 +++- src/sources/editor.jsx | 86 ++++++++++++++++++++++++++++++++++++++++++ src/sources/list.jsx | 38 +++++++++++++++++++ src/style.js | 2 +- src/toolbar.jsx | 11 ++++++ src/workspace.jsx | 9 ++++- 6 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 src/sources/editor.jsx create mode 100644 src/sources/list.jsx diff --git a/src/app.jsx b/src/app.jsx index 9401c903..7648b61b 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -2,7 +2,7 @@ import React from 'react' import {saveAs} from 'file-saver' import { Drawer, Container, Block, Fixed } from 'rebass' -import {Map} from './map.jsx' +import { Map } from './map.jsx' import {Toolbar} from './toolbar.jsx' import { StyleManager } from './style.js' import { loadDefaultStyle, SettingsStore, StyleStore } from './stylestore.js' @@ -67,6 +67,10 @@ export default class App extends React.Component { this.setState({ workContext: "layers", }) } + onOpenSources() { + this.setState({ workContext: "sources", }) + } + onAccessTokenChanged(newToken) { this.settingsStore.accessToken = newToken this.setState({ accessToken: newToken }) @@ -81,6 +85,7 @@ export default class App extends React.Component { onStyleDownload={this.onStyleDownload.bind(this)} onOpenSettings={this.onOpenSettings.bind(this)} onOpenLayers={this.onOpenLayers.bind(this)} + onOpenSources={this.onOpenSources.bind(this)} /> + } +} + +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
+ + + +
+ } +} + +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 + } + return + } + + render() { + return
+ + + #{this.props.sourceId} + + + + +
+ {this.sourceFromType(this.props.source.get('type'))} +
+
+
+ } +} + diff --git a/src/sources/list.jsx b/src/sources/list.jsx new file mode 100644 index 00000000..3cbee9df --- /dev/null +++ b/src/sources/list.jsx @@ -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 + }).toIndexedSeq() + + return
+ + + Layers + + + + {sourceEditors} +
+ } +} diff --git a/src/style.js b/src/style.js index 13d1abe8..a38f2b9b 100644 --- a/src/style.js +++ b/src/style.js @@ -26,7 +26,7 @@ function fromJSON(jsonStyle) { if(key === "layers") { return [key, Immutable.OrderedMap(val.map(l => [l.id, Immutable.fromJS(l)]))] } else if(key === "sources" || key === "metadata" || key === "transition") { - return [key, Immutable.Map(val)] + return [key, Immutable.fromJS(val)] } else { return [key, val] } diff --git a/src/toolbar.jsx b/src/toolbar.jsx index 11297b91..99973daa 100644 --- a/src/toolbar.jsx +++ b/src/toolbar.jsx @@ -9,6 +9,8 @@ import MdFileUpload from 'react-icons/lib/md/file-upload' import MdSettings from 'react-icons/lib/md/settings' import MdLayers from 'react-icons/lib/md/layers' import MdSave from 'react-icons/lib/md/save' +import MdMap from 'react-icons/lib/md/map' + import { GlStyle } from './style.js' import { fullHeight } from './theme.js' @@ -24,6 +26,8 @@ export class Toolbar extends React.Component { onStyleSave: React.PropTypes.func, // Open settings drawer onOpenSettings: React.PropTypes.func, + // Open sources drawer + onOpenSources: React.PropTypes.func, // Open layers drawer onOpenLayers: React.PropTypes.func, // Whether a style is available for download or saving @@ -94,6 +98,13 @@ export class Toolbar extends React.Component { + + +