maputnik/src/app.jsx

79 lines
2 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 23:25:06 +02:00
import { StyleStore } from './stylestore.js'
2016-09-09 17:09:13 +02:00
import { WorkspaceDrawer } from './workspace.jsx'
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
}
constructor(props) {
super(props)
this.styleStore = new StyleStore()
this.state = {
2016-09-09 17:09:13 +02:00
workContext: "layers",
currentStyle: this.styleStore.latestStyle(),
}
}
2016-09-09 23:25:06 +02:00
getChildContext() {
return {
rebass: theme,
reactIconBase: { size: 20 }
}
}
2016-09-09 16:58:48 +02:00
onStyleDownload() {
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) {
const savedStyle = this.styleStore.save(newStyle)
this.setState({ currentStyle: savedStyle })
}
2016-09-09 23:25:06 +02:00
onStyleChanged(newStyle) {
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}
mapStyle={this.state.currentStyle}
2016-09-09 23:25:06 +02:00
/>
<div className={layout.map}>
<Map mapStyle={this.state.currentStyle} />
</div>
</div>
2015-06-15 15:21:19 +02:00
}
2016-09-08 19:47:29 +02:00
}