Use layout component

This commit is contained in:
Lukas Martinelli 2016-12-20 16:37:35 +01:00
parent 36c4032063
commit 6a129fcf3f
2 changed files with 97 additions and 60 deletions

View file

@ -6,25 +6,20 @@ import Container from 'rebass/dist/Container'
import Block from 'rebass/dist/Block' import Block from 'rebass/dist/Block'
import Fixed from 'rebass/dist/Fixed' import Fixed from 'rebass/dist/Fixed'
import MapboxGlMap from './map/MapboxGlMap.jsx' import MapboxGlMap from './map/MapboxGlMap'
import OpenLayers3Map from './map/OpenLayers3Map.jsx' import OpenLayers3Map from './map/OpenLayers3Map'
import LayerList from './layers/LayerList.jsx' import LayerList from './layers/LayerList'
import LayerEditor from './layers/LayerEditor.jsx' import LayerEditor from './layers/LayerEditor'
import Toolbar from './Toolbar.jsx' import Toolbar from './Toolbar'
import Layout from './Layout'
import style from '../libs/style.js' import style from '../libs/style.js'
import { loadDefaultStyle, SettingsStore, StyleStore } from '../libs/stylestore.js' import { loadDefaultStyle, SettingsStore, StyleStore } from '../libs/stylestore'
import { ApiStyleStore } from '../libs/apistore.js' import { ApiStyleStore } from '../libs/apistore'
import LayerWatcher from '../libs/layerwatcher.js' import LayerWatcher from '../libs/layerwatcher'
import theme from '../config/rebass.js'
import colors from '../config/colors.js'
export default class App extends React.Component { export default class App extends React.Component {
static childContextTypes = {
rebass: React.PropTypes.object,
reactIconBase: React.PropTypes.object
}
constructor(props) { constructor(props) {
super(props) super(props)
@ -51,13 +46,6 @@ export default class App extends React.Component {
loadDefaultStyle(mapStyle => this.onStyleUpload(mapStyle)) loadDefaultStyle(mapStyle => this.onStyleUpload(mapStyle))
} }
getChildContext() {
return {
rebass: theme,
reactIconBase: { size: 20 }
}
}
onStyleDownload() { onStyleDownload() {
const mapStyle = this.state.mapStyle const mapStyle = this.state.mapStyle
const blob = new Blob([JSON.stringify(mapStyle, null, 4)], {type: "application/json;charset=utf-8"}); const blob = new Blob([JSON.stringify(mapStyle, null, 4)], {type: "application/json;charset=utf-8"});
@ -138,45 +126,33 @@ export default class App extends React.Component {
const layers = this.state.mapStyle.layers || [] const layers = this.state.mapStyle.layers || []
const selectedLayer = layers.length > 0 ? layers[this.state.selectedLayerIndex] : null const selectedLayer = layers.length > 0 ? layers[this.state.selectedLayerIndex] : null
return <div style={{ fontFamily: theme.fontFamily, color: theme.color, fontWeight: 300 }}> const toolbar = <Toolbar
<Toolbar mapStyle={this.state.mapStyle}
mapStyle={this.state.mapStyle} onStyleChanged={this.onStyleChanged.bind(this)}
onStyleChanged={this.onStyleChanged.bind(this)} onStyleSave={this.onStyleSave.bind(this)}
onStyleSave={this.onStyleSave.bind(this)} onStyleUpload={this.onStyleUpload.bind(this)}
onStyleUpload={this.onStyleUpload.bind(this)} onStyleDownload={this.onStyleDownload.bind(this)}
onStyleDownload={this.onStyleDownload.bind(this)} />
/>
<div style={{ const layerList = <LayerList
position: 'absolute', onLayersChanged={this.onLayersChanged.bind(this)}
bottom: 0, onLayerSelected={this.onLayerSelected.bind(this)}
height: "100%", layers={layers}
top: 50, />
left: 0,
zIndex: 100, const layerEditor = selectedLayer ? <LayerEditor
width: 180, layer={selectedLayer}
overflow: "hidden", onLayerChanged={this.onLayerChanged.bind(this)}
backgroundColor: colors.gray sources={this.layerWatcher.sources}
}}> vectorLayers={this.layerWatcher.vectorLayers}
<LayerList /> : null
onLayersChanged={this.onLayersChanged.bind(this)}
onLayerSelected={this.onLayerSelected.bind(this)} return <Layout
layers={layers} toolbar={toolbar}
/> layerList={layerList}
</div> layerEditor={layerEditor}
<div style={{ map={this.mapRenderer()}
position: 'absolute', />
bottom: 0,
height: "100%",
top: 50,
left: 180,
zIndex: 100,
width: 300,
backgroundColor: colors.gray}
}>
{selectedLayer && <LayerEditor layer={selectedLayer} onLayerChanged={this.onLayerChanged.bind(this)} sources={this.layerWatcher.sources} vectorLayers={this.layerWatcher.vectorLayers}/>}
</div>
{this.mapRenderer()}
</div>
} }
} }

61
src/components/Layout.jsx Normal file
View file

@ -0,0 +1,61 @@
import React from 'react'
import theme from '../config/rebass'
import colors from '../config/colors'
export default class Layout extends React.Component {
static propTypes = {
toolbar: React.PropTypes.element.isRequired,
layerList: React.PropTypes.element.isRequired,
layerEditor: React.PropTypes.element,
map: React.PropTypes.element.isRequired,
}
static childContextTypes = {
rebass: React.PropTypes.object,
reactIconBase: React.PropTypes.object
}
getChildContext() {
return {
rebass: theme,
reactIconBase: { size: 20 }
}
}
render() {
return <div style={{
fontFamily: theme.fontFamily,
color: theme.color,
fontWeight: 300
}}>
{this.props.toolbar}
<div style={{
position: 'absolute',
bottom: 0,
height: "100%",
top: 50,
left: 0,
zIndex: 100,
width: 180,
overflow: "hidden",
backgroundColor: colors.gray
}}>
{this.props.layerList}
</div>
<div style={{
position: 'absolute',
bottom: 0,
height: "100%",
top: 50,
left: 180,
zIndex: 100,
width: 300,
backgroundColor: colors.gray}
}>
{this.props.layerEditor}
</div>
{this.props.map}
</div>
}
}