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-11-25 13:31:41 +01:00
|
|
|
import { MapboxGlMap } from './gl.jsx'
|
|
|
|
import { OpenLayers3Map } from './ol3.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-16 14:49:25 +01:00
|
|
|
import { loadDefaultStyle, SettingsStore, StyleStore } from './stylestore.js'
|
|
|
|
import { 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-12-16 14:49:25 +01:00
|
|
|
static childContextTypes = {
|
|
|
|
rebass: React.PropTypes.object,
|
|
|
|
reactIconBase: React.PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.styleStore = new ApiStyleStore()
|
|
|
|
this.styleStore.supported(isSupported => {
|
|
|
|
if(!isSupported) {
|
|
|
|
console.log('Falling back to local storage for storing styles')
|
|
|
|
this.styleStore = new StyleStore()
|
|
|
|
}
|
|
|
|
this.styleStore.latestStyle(mapStyle => this.onStyleUpload(mapStyle))
|
2016-12-03 23:28:43 +01:00
|
|
|
})
|
2016-12-16 14:49:25 +01:00
|
|
|
|
|
|
|
this.settingsStore = new SettingsStore()
|
|
|
|
this.state = {
|
|
|
|
accessToken: this.settingsStore.accessToken,
|
|
|
|
workContext: "layers",
|
2016-12-16 15:14:20 +01:00
|
|
|
currentStyle: style.emptyStyle,
|
|
|
|
mapRenderer: 'gl',
|
2016-12-16 14:49:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onReset() {
|
|
|
|
this.styleStore.purge()
|
|
|
|
loadDefaultStyle(mapStyle => this.onStyleUpload(mapStyle))
|
|
|
|
}
|
|
|
|
|
|
|
|
getChildContext() {
|
|
|
|
return {
|
|
|
|
rebass: theme,
|
|
|
|
reactIconBase: { size: 20 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onStyleDownload() {
|
|
|
|
const mapStyle = style.toJSON(this.state.currentStyle)
|
|
|
|
const blob = new Blob([JSON.stringify(mapStyle, null, 4)], {type: "application/json;charset=utf-8"});
|
|
|
|
saveAs(blob, mapStyle.id + ".json");
|
|
|
|
this.onStyleSave()
|
|
|
|
}
|
|
|
|
|
|
|
|
onStyleUpload(newStyle) {
|
|
|
|
const savedStyle = this.styleStore.save(newStyle)
|
|
|
|
this.setState({ currentStyle: savedStyle })
|
|
|
|
}
|
|
|
|
|
|
|
|
onStyleSave() {
|
|
|
|
const snapshotStyle = this.state.currentStyle.set('modified', new Date().toJSON())
|
|
|
|
this.setState({ currentStyle: snapshotStyle })
|
2016-12-03 23:28:43 +01:00
|
|
|
console.log('Save')
|
2016-12-16 14:49:25 +01:00
|
|
|
this.styleStore.save(snapshotStyle)
|
|
|
|
}
|
|
|
|
|
|
|
|
onStyleChanged(newStyle) {
|
|
|
|
this.setState({ currentStyle: newStyle })
|
|
|
|
}
|
|
|
|
|
|
|
|
onOpenSettings() {
|
2016-12-16 14:52:44 +01:00
|
|
|
//TODO: open settings modal
|
|
|
|
//this.setState({ workContext: "settings" })
|
2016-12-16 14:49:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onOpenAbout() {
|
2016-12-16 14:52:44 +01:00
|
|
|
//TODO: open about modal
|
|
|
|
//this.setState({ workContext: "about" })
|
2016-12-16 14:49:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onOpenSources() {
|
2016-12-16 14:52:44 +01:00
|
|
|
//TODO: open sources modal
|
|
|
|
//this.setState({ workContext: "sources", })
|
2016-12-16 14:49:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onAccessTokenChanged(newToken) {
|
|
|
|
this.settingsStore.accessToken = newToken
|
|
|
|
this.setState({ accessToken: newToken })
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-12-16 17:13:05 +01:00
|
|
|
const renderer = this.state.currentStyle.getIn(['metadata', 'maputnik:renderer'], 'mbgljs')
|
2016-12-16 15:14:20 +01:00
|
|
|
const mapProps = {
|
|
|
|
mapStyle: this.state.currentStyle,
|
|
|
|
accessToken: this.state.accessToken,
|
|
|
|
}
|
2016-12-16 14:49:25 +01:00
|
|
|
return <div style={{ fontFamily: theme.fontFamily, color: theme.color, fontWeight: 300 }}>
|
|
|
|
<Toolbar
|
2016-12-16 16:52:16 +01:00
|
|
|
mapStyle={this.state.currentStyle}
|
|
|
|
onStyleChanged={this.onStyleChanged.bind(this)}
|
2016-12-16 14:49:25 +01:00
|
|
|
onStyleSave={this.onStyleSave.bind(this)}
|
|
|
|
onStyleUpload={this.onStyleUpload.bind(this)}
|
|
|
|
onStyleDownload={this.onStyleDownload.bind(this)}
|
|
|
|
/>
|
|
|
|
<WorkspaceDrawer
|
|
|
|
onStyleChanged={this.onStyleChanged.bind(this)}
|
|
|
|
onReset={this.onReset.bind(this)}
|
|
|
|
workContext={this.state.workContext}
|
|
|
|
mapStyle={this.state.currentStyle}
|
|
|
|
accessToken={this.state.accessToken}
|
|
|
|
onAccessTokenChanged={this.onAccessTokenChanged.bind(this)}
|
|
|
|
/>
|
2016-12-16 17:13:05 +01:00
|
|
|
{renderer == 'ol3' && <OpenLayers3Map {...mapProps} />}
|
|
|
|
{renderer == 'mbgljs' && <MapboxGlMap {...mapProps} />}
|
2016-12-16 14:49:25 +01:00
|
|
|
</div>
|
|
|
|
}
|
2016-09-08 19:47:29 +02:00
|
|
|
}
|
2016-09-21 08:41:02 +02:00
|
|
|
|