2016-09-09 00:10:54 +02:00
|
|
|
import React from 'react'
|
2016-09-09 16:58:48 +02:00
|
|
|
import {saveAs} from 'file-saver'
|
2016-09-09 00:10:54 +02:00
|
|
|
|
2016-09-08 19:47:29 +02:00
|
|
|
import { Drawer, Container, Block, Fixed } from 'rebass'
|
2016-09-09 00:10:54 +02:00
|
|
|
import {Map} from './map.jsx'
|
|
|
|
import {Toolbar} from './toolbar.jsx'
|
2016-09-09 15:49:23 +02:00
|
|
|
import { StyleManager } from './style.js'
|
2016-09-09 23:25:06 +02:00
|
|
|
import { StyleStore } from './stylestore.js'
|
2016-09-09 17:09:13 +02:00
|
|
|
import { WorkspaceDrawer } from './workspace.jsx'
|
2016-09-09 00:10:54 +02:00
|
|
|
|
|
|
|
import theme from './theme.js'
|
|
|
|
import layout from './layout.scss'
|
2015-06-15 15:21:19 +02:00
|
|
|
|
|
|
|
export default class App extends React.Component {
|
2016-09-08 19:47:29 +02:00
|
|
|
static childContextTypes = {
|
|
|
|
rebass: React.PropTypes.object,
|
|
|
|
reactIconBase: React.PropTypes.object
|
|
|
|
}
|
|
|
|
|
2016-09-09 00:10:54 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
2016-09-10 13:42:23 +02:00
|
|
|
this.styleStore = new StyleStore()
|
2016-09-09 00:10:54 +02:00
|
|
|
this.state = {
|
2016-09-09 17:09:13 +02:00
|
|
|
workContext: "layers",
|
2016-09-10 13:42:23 +02:00
|
|
|
currentStyle: this.styleStore.latestStyle(),
|
2016-09-09 00:10:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 23:25:06 +02:00
|
|
|
getChildContext() {
|
|
|
|
return {
|
|
|
|
rebass: theme,
|
|
|
|
reactIconBase: { size: 20 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 16:58:48 +02:00
|
|
|
onStyleDownload() {
|
2016-09-10 13:42:23 +02:00
|
|
|
this.styleStore.save(newStyle)
|
|
|
|
const mapStyle = JSON.stringify(this.state.currentStyle.toJS(), null, 4)
|
2016-09-09 16:58:48 +02:00
|
|
|
const blob = new Blob([mapStyle], {type: "application/json;charset=utf-8"});
|
2016-09-09 23:25:06 +02:00
|
|
|
saveAs(blob, mapStyle.id + ".json");
|
2016-09-09 16:58:48 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 15:49:23 +02:00
|
|
|
onStyleUpload(newStyle) {
|
2016-09-10 13:42:23 +02:00
|
|
|
const savedStyle = this.styleStore.save(newStyle)
|
|
|
|
this.setState({ currentStyle: savedStyle })
|
2016-09-09 00:10:54 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 23:25:06 +02:00
|
|
|
onStyleChanged(newStyle) {
|
2016-09-10 13:42:23 +02:00
|
|
|
this.setState({ currentStyle: newStyle })
|
2016-09-09 17:09:13 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 23:25:06 +02:00
|
|
|
onOpenSettings() {
|
|
|
|
this.setState({ workContext: "settings", })
|
2016-09-09 17:09:13 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 23:25:06 +02:00
|
|
|
onOpenLayers() {
|
|
|
|
this.setState({ workContext: "layers", })
|
2016-09-08 19:47:29 +02:00
|
|
|
}
|
|
|
|
|
2015-06-15 15:21:19 +02:00
|
|
|
render() {
|
2016-09-09 18:53:57 +02:00
|
|
|
return <div style={{ fontFamily: theme.fontFamily, color: theme.color, fontWeight: 300 }}>
|
2016-09-09 17:09:13 +02:00
|
|
|
<Toolbar
|
|
|
|
onStyleUpload={this.onStyleUpload.bind(this)}
|
|
|
|
onStyleDownload={this.onStyleDownload.bind(this)}
|
|
|
|
onOpenSettings={this.onOpenSettings.bind(this)}
|
|
|
|
onOpenLayers={this.onOpenLayers.bind(this)}
|
|
|
|
/>
|
2016-09-09 23:25:06 +02:00
|
|
|
<WorkspaceDrawer
|
|
|
|
onStyleChanged={this.onStyleChanged.bind(this)}
|
|
|
|
workContext={this.state.workContext}
|
2016-09-10 13:42:23 +02:00
|
|
|
mapStyle={this.state.currentStyle}
|
2016-09-09 23:25:06 +02:00
|
|
|
/>
|
2016-09-09 00:10:54 +02:00
|
|
|
<div className={layout.map}>
|
2016-09-10 13:42:23 +02:00
|
|
|
<Map mapStyle={this.state.currentStyle} />
|
2016-09-09 00:10:54 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2015-06-15 15:21:19 +02:00
|
|
|
}
|
2016-09-08 19:47:29 +02:00
|
|
|
}
|