maputnik/src/app.jsx

74 lines
1.7 KiB
React
Raw Normal View History

import React from 'react'
2016-09-09 16:58:48 +02:00
import {saveAs} from 'file-saver'
2016-09-08 19:47:29 +02:00
import { Drawer, Container, Block, Fixed } from 'rebass'
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 17:09:13 +02:00
import { WorkspaceDrawer } from './workspace.jsx'
import theme from './theme.js'
import layout from './layout.scss'
2016-09-09 15:49:23 +02:00
import 'react-virtualized/styles.css'
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
}
constructor(props) {
super(props)
this.state = {
2016-09-09 15:49:23 +02:00
styleManager: new StyleManager(),
2016-09-09 17:09:13 +02:00
workContext: "layers",
}
}
2016-09-09 16:58:48 +02:00
onStyleDownload() {
const mapStyle = this.state.styleManager.exportStyle()
const blob = new Blob([mapStyle], {type: "application/json;charset=utf-8"});
saveAs(blob, "glstyle.json");
}
2016-09-09 15:49:23 +02:00
onStyleUpload(newStyle) {
this.setState({ styleManager: new StyleManager(newStyle) })
}
2016-09-09 17:09:13 +02:00
onOpenSettings() {
this.setState({
workContext: "settings",
})
}
onOpenLayers() {
this.setState({
workContext: "layers",
})
}
getChildContext() {
2016-09-08 19:47:29 +02:00
return {
rebass: theme,
reactIconBase: {
size: 20,
}
}
}
2015-06-15 15:21:19 +02:00
render() {
2016-09-09 11:29:18 +02:00
return <div style={{ fontFamily: theme.fontFamily, color: theme.color }}>
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)}
/>
<WorkspaceDrawer workContext={this.state.workContext} styleManager={this.state.styleManager}/>
<div className={layout.map}>
2016-09-09 15:49:23 +02:00
<Map styleManager={this.state.styleManager} />
</div>
</div>
2015-06-15 15:21:19 +02:00
}
2016-09-08 19:47:29 +02:00
}