Show layer editor side by side

This commit is contained in:
Lukas Martinelli 2016-12-17 15:44:42 +01:00
parent 04ebd25773
commit f2564e4ddb
2 changed files with 149 additions and 147 deletions

View file

@ -9,6 +9,7 @@ import Fixed from 'rebass/dist/Fixed'
import { MapboxGlMap } from './gl.jsx' import { MapboxGlMap } from './gl.jsx'
import { OpenLayers3Map } from './ol3.jsx' import { OpenLayers3Map } from './ol3.jsx'
import { LayerList } from './layers/list.jsx' import { LayerList } from './layers/list.jsx'
import { LayerEditor } from './layers/editor.jsx'
import {Toolbar} from './toolbar.jsx' import {Toolbar} from './toolbar.jsx'
import style from './style.js' import style from './style.js'
import { loadDefaultStyle, SettingsStore, StyleStore } from './stylestore.js' import { loadDefaultStyle, SettingsStore, StyleStore } from './stylestore.js'
@ -39,9 +40,7 @@ export default class App extends React.Component {
this.settingsStore = new SettingsStore() this.settingsStore = new SettingsStore()
this.state = { this.state = {
accessToken: this.settingsStore.accessToken, accessToken: this.settingsStore.accessToken,
workContext: "layers", mapStyle: style.emptyStyle,
currentStyle: style.emptyStyle,
mapRenderer: 'gl',
} }
} }
@ -58,7 +57,7 @@ export default class App extends React.Component {
} }
onStyleDownload() { onStyleDownload() {
const mapStyle = style.toJSON(this.state.currentStyle) const mapStyle = style.toJSON(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"});
saveAs(blob, mapStyle.id + ".json"); saveAs(blob, mapStyle.id + ".json");
this.onStyleSave() this.onStyleSave()
@ -66,33 +65,18 @@ export default class App extends React.Component {
onStyleUpload(newStyle) { onStyleUpload(newStyle) {
const savedStyle = this.styleStore.save(newStyle) const savedStyle = this.styleStore.save(newStyle)
this.setState({ currentStyle: savedStyle }) this.setState({ mapStyle: savedStyle })
} }
onStyleSave() { onStyleSave() {
const snapshotStyle = this.state.currentStyle.set('modified', new Date().toJSON()) const snapshotStyle = this.state.mapStyle.set('modified', new Date().toJSON())
this.setState({ currentStyle: snapshotStyle }) this.setState({ mapStyle: snapshotStyle })
console.log('Save') console.log('Save')
this.styleStore.save(snapshotStyle) this.styleStore.save(snapshotStyle)
} }
onStyleChanged(newStyle) { onStyleChanged(newStyle) {
this.setState({ currentStyle: newStyle }) this.setState({ mapStyle: newStyle })
}
onOpenSettings() {
//TODO: open settings modal
//this.setState({ workContext: "settings" })
}
onOpenAbout() {
//TODO: open about modal
//this.setState({ workContext: "about" })
}
onOpenSources() {
//TODO: open sources modal
//this.setState({ workContext: "sources", })
} }
onAccessTokenChanged(newToken) { onAccessTokenChanged(newToken) {
@ -107,10 +91,10 @@ export default class App extends React.Component {
mapRenderer() { mapRenderer() {
const mapProps = { const mapProps = {
mapStyle: this.state.currentStyle, mapStyle: this.state.mapStyle,
accessToken: this.state.accessToken, accessToken: this.state.accessToken,
} }
const renderer = this.state.currentStyle.getIn(['metadata', 'maputnik:renderer'], 'mbgljs') const renderer = this.state.mapStyle.getIn(['metadata', 'maputnik:renderer'], 'mbgljs')
if(renderer === 'ol3') { if(renderer === 'ol3') {
return <OpenLayers3Map {...mapProps} /> return <OpenLayers3Map {...mapProps} />
} else { } else {
@ -119,9 +103,11 @@ export default class App extends React.Component {
} }
render() { render() {
const layers = this.state.mapStyle.get('layers').keySeq()
console.log(layers.size)
return <div style={{ fontFamily: theme.fontFamily, color: theme.color, fontWeight: 300 }}> return <div style={{ fontFamily: theme.fontFamily, color: theme.color, fontWeight: 300 }}>
<Toolbar <Toolbar
mapStyle={this.state.currentStyle} 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)}
@ -132,15 +118,26 @@ export default class App extends React.Component {
top: 50, top: 50,
left: 0, left: 0,
zIndex: 100, zIndex: 100,
width: 300, width: 200,
overflow: "hidden", overflow: "hidden",
backgroundColor: colors.gray backgroundColor: colors.gray
}}> }}>
<LayerList <LayerList
onLayersChanged={this.onLayersChanged.bind(this)} onLayersChanged={this.onLayersChanged.bind(this)}
layers={this.state.currentStyle.get('layers')} layers={this.state.mapStyle.get('layers')}
/> />
</div> </div>
<div style={{
...fullHeight,
top: 50,
left: 200,
zIndex: 100,
width: 300,
overflow: "hidden",
backgroundColor: colors.gray}
}>
{layers.size > 0 && <LayerEditor layer={this.state.mapStyle.get('layers').get(layers.get(0))} />}
</div>
{this.mapRenderer()} {this.mapRenderer()}
</div> </div>
} }

View file

@ -27,8 +27,13 @@ class UnsupportedLayer extends React.Component {
export class LayerEditor extends React.Component { export class LayerEditor extends React.Component {
static propTypes = { static propTypes = {
layer: React.PropTypes.object.isRequired, layer: React.PropTypes.object.isRequired,
onLayerChanged: React.PropTypes.func.isRequired, onLayerChanged: React.PropTypes.func,
onLayerDestroyed: React.PropTypes.func.isRequired, onLayerDestroyed: React.PropTypes.func,
}
static defaultProps = {
onLayerChanged: () => {},
onLayerDestroyed: () => {},
} }
static childContextTypes = { static childContextTypes = {