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-15 09:13:23 +02:00
|
|
|
import Drawer from 'rebass/dist/Drawer'
|
|
|
|
import Container from 'rebass/dist/Container'
|
|
|
|
import Block from 'rebass/dist/Block'
|
|
|
|
import Fixed from 'rebass/dist/Fixed'
|
|
|
|
|
2016-09-10 22:08:26 +02:00
|
|
|
import { Map } from './map.jsx'
|
2016-09-09 00:10:54 +02:00
|
|
|
import {Toolbar} from './toolbar.jsx'
|
2016-09-21 08:41:02 +02:00
|
|
|
import style from './style.js'
|
2016-12-03 23:28:43 +01:00
|
|
|
import { loadDefaultStyle, SettingsStore } from './stylestore.js'
|
|
|
|
import { emptyStyle, ApiStyleStore } from './apistore.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'
|
2016-11-23 21:02:04 +01:00
|
|
|
import './index.scss'
|
2015-06-15 15:21:19 +02:00
|
|
|
|
|
|
|
export default class App extends React.Component {
|
2016-09-10 15:15:17 +02:00
|
|
|
static childContextTypes = {
|
|
|
|
rebass: React.PropTypes.object,
|
2016-09-08 19:47:29 +02:00
|
|
|
reactIconBase: React.PropTypes.object
|
2016-09-10 15:15:17 +02:00
|
|
|
}
|
2016-09-08 19:47:29 +02:00
|
|
|
|
2016-09-09 00:10:54 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
2016-12-03 23:28:43 +01:00
|
|
|
this.styleStore = new ApiStyleStore()
|
2016-09-10 16:26:39 +02:00
|
|
|
this.settingsStore = new SettingsStore()
|
2016-09-09 00:10:54 +02:00
|
|
|
this.state = {
|
2016-09-10 16:26:39 +02:00
|
|
|
accessToken: this.settingsStore.accessToken,
|
2016-09-09 17:09:13 +02:00
|
|
|
workContext: "layers",
|
2016-12-03 23:28:43 +01:00
|
|
|
currentStyle: emptyStyle
|
2016-09-09 00:10:54 +02:00
|
|
|
}
|
2016-12-03 23:28:43 +01:00
|
|
|
|
|
|
|
this.styleStore.latestStyle(mapStyle => {
|
|
|
|
this.onStyleUpload(mapStyle)
|
|
|
|
})
|
|
|
|
/*
|
2016-09-21 08:25:10 +02:00
|
|
|
if(this.state.currentStyle.get('layers').size === 0) {
|
|
|
|
loadDefaultStyle(mapStyle => this.onStyleUpload(mapStyle))
|
|
|
|
}
|
2016-12-03 23:28:43 +01:00
|
|
|
*/
|
2016-09-09 00:10:54 +02:00
|
|
|
}
|
|
|
|
|
2016-09-21 08:34:48 +02:00
|
|
|
onReset() {
|
|
|
|
this.styleStore.purge()
|
|
|
|
loadDefaultStyle(mapStyle => this.onStyleUpload(mapStyle))
|
|
|
|
}
|
|
|
|
|
2016-09-10 15:15:17 +02:00
|
|
|
getChildContext() {
|
|
|
|
return {
|
2016-09-09 23:25:06 +02:00
|
|
|
rebass: theme,
|
|
|
|
reactIconBase: { size: 20 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 16:58:48 +02:00
|
|
|
onStyleDownload() {
|
2016-09-21 08:41:02 +02:00
|
|
|
const mapStyle = style.toJSON(this.state.currentStyle)
|
|
|
|
const blob = new Blob([JSON.stringify(mapStyle, null, 4)], {type: "application/json;charset=utf-8"});
|
2016-09-09 23:25:06 +02:00
|
|
|
saveAs(blob, mapStyle.id + ".json");
|
2016-09-10 21:29:18 +02:00
|
|
|
this.onStyleSave()
|
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-10 14:47:06 +02:00
|
|
|
onStyleSave() {
|
|
|
|
const snapshotStyle = this.state.currentStyle.set('modified', new Date().toJSON())
|
2016-09-10 21:29:18 +02:00
|
|
|
this.setState({ currentStyle: snapshotStyle })
|
2016-12-03 23:28:43 +01:00
|
|
|
console.log('Save')
|
2016-09-21 08:25:10 +02:00
|
|
|
this.styleStore.save(snapshotStyle)
|
2016-09-10 14:47:06 +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() {
|
2016-09-10 15:15:17 +02:00
|
|
|
this.setState({ workContext: "settings" })
|
2016-09-09 17:09:13 +02:00
|
|
|
}
|
|
|
|
|
2016-09-19 20:49:16 +02:00
|
|
|
onOpenAbout() {
|
|
|
|
this.setState({ workContext: "about" })
|
|
|
|
}
|
|
|
|
|
2016-09-09 23:25:06 +02:00
|
|
|
onOpenLayers() {
|
|
|
|
this.setState({ workContext: "layers", })
|
2016-09-08 19:47:29 +02:00
|
|
|
}
|
|
|
|
|
2016-09-10 22:08:26 +02:00
|
|
|
onOpenSources() {
|
|
|
|
this.setState({ workContext: "sources", })
|
|
|
|
}
|
|
|
|
|
2016-09-10 16:26:39 +02:00
|
|
|
onAccessTokenChanged(newToken) {
|
|
|
|
this.settingsStore.accessToken = newToken
|
|
|
|
this.setState({ accessToken: newToken })
|
|
|
|
}
|
|
|
|
|
2016-09-10 15:15:17 +02:00
|
|
|
render() {
|
|
|
|
return <div style={{ fontFamily: theme.fontFamily, color: theme.color, fontWeight: 300 }}>
|
2016-09-09 17:09:13 +02:00
|
|
|
<Toolbar
|
2016-09-10 14:56:59 +02:00
|
|
|
styleAvailable={this.state.currentStyle.get('layers').size > 0}
|
2016-09-10 14:47:06 +02:00
|
|
|
onStyleSave={this.onStyleSave.bind(this)}
|
2016-09-09 17:09:13 +02:00
|
|
|
onStyleUpload={this.onStyleUpload.bind(this)}
|
|
|
|
onStyleDownload={this.onStyleDownload.bind(this)}
|
|
|
|
onOpenSettings={this.onOpenSettings.bind(this)}
|
2016-09-19 20:49:16 +02:00
|
|
|
onOpenAbout={this.onOpenAbout.bind(this)}
|
2016-09-09 17:09:13 +02:00
|
|
|
onOpenLayers={this.onOpenLayers.bind(this)}
|
2016-09-10 22:08:26 +02:00
|
|
|
onOpenSources={this.onOpenSources.bind(this)}
|
2016-09-09 17:09:13 +02:00
|
|
|
/>
|
2016-09-09 23:25:06 +02:00
|
|
|
<WorkspaceDrawer
|
|
|
|
onStyleChanged={this.onStyleChanged.bind(this)}
|
2016-09-21 08:34:48 +02:00
|
|
|
onReset={this.onReset.bind(this)}
|
2016-09-09 23:25:06 +02:00
|
|
|
workContext={this.state.workContext}
|
2016-09-10 13:42:23 +02:00
|
|
|
mapStyle={this.state.currentStyle}
|
2016-09-10 16:26:39 +02:00
|
|
|
accessToken={this.state.accessToken}
|
|
|
|
onAccessTokenChanged={this.onAccessTokenChanged.bind(this)}
|
|
|
|
/>
|
|
|
|
<Map
|
|
|
|
mapStyle={this.state.currentStyle}
|
|
|
|
accessToken={this.state.accessToken}
|
2016-09-09 23:25:06 +02:00
|
|
|
/>
|
2016-09-09 00:10:54 +02:00
|
|
|
</div>
|
2016-09-10 15:15:17 +02:00
|
|
|
}
|
2016-09-08 19:47:29 +02:00
|
|
|
}
|
2016-09-21 08:41:02 +02:00
|
|
|
|