2016-09-08 19:47:29 +02:00
|
|
|
import React from 'react';
|
2016-09-09 00:10:54 +02:00
|
|
|
import FileReaderInput from 'react-file-reader-input';
|
2016-09-08 19:47:29 +02:00
|
|
|
|
2016-09-09 00:10:54 +02:00
|
|
|
import { Button, Text } from 'rebass';
|
2016-09-08 19:47:29 +02:00
|
|
|
import { Menu, NavItem, Tooltip, Container, Block, Fixed } from 'rebass'
|
2016-09-09 16:58:48 +02:00
|
|
|
import { MdFileDownload, MdFileUpload, MdSettings, MdPalette, MdLayers, MdSave, MdFolderOpen} from 'react-icons/lib/md';
|
2016-09-09 00:10:54 +02:00
|
|
|
|
|
|
|
import theme from './theme.js';
|
2016-09-08 19:47:29 +02:00
|
|
|
|
|
|
|
export class Toolbar extends React.Component {
|
2016-09-09 16:58:48 +02:00
|
|
|
static propTypes = {
|
|
|
|
onStyleUpload: React.PropTypes.func.isRequired,
|
2016-09-09 17:09:13 +02:00
|
|
|
onStyleDownload: React.PropTypes.func.isRequired,
|
|
|
|
onOpenSettings: React.PropTypes.func,
|
|
|
|
onOpenLayers: React.PropTypes.func,
|
2016-09-09 16:58:48 +02:00
|
|
|
}
|
|
|
|
|
2016-09-08 20:35:21 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2016-09-09 00:10:54 +02:00
|
|
|
this.onUpload = this.onUpload.bind(this);
|
2016-09-09 16:58:48 +02:00
|
|
|
this.state = {
|
|
|
|
styleUploaded: false
|
|
|
|
}
|
2016-09-08 20:35:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onUpload(_, files) {
|
|
|
|
const [e, file] = files[0];
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.readAsText(file, "UTF-8");
|
|
|
|
reader.onload = e => {
|
|
|
|
const style = JSON.parse(e.target.result);
|
2016-09-09 00:10:54 +02:00
|
|
|
this.props.onStyleUpload(style);
|
2016-09-09 16:58:48 +02:00
|
|
|
this.setState({
|
|
|
|
styleUploaded: true
|
|
|
|
})
|
2016-09-08 20:35:21 +02:00
|
|
|
}
|
|
|
|
reader.onerror = e => console.log(e.target);
|
|
|
|
}
|
2016-09-09 00:10:54 +02:00
|
|
|
|
2016-09-08 19:47:29 +02:00
|
|
|
render() {
|
2016-09-09 16:58:48 +02:00
|
|
|
let downloadButton = null
|
|
|
|
if(this.state.styleUploaded) {
|
|
|
|
downloadButton = <Block>
|
|
|
|
<Button onClick={this.props.onStyleDownload} big={true}>
|
|
|
|
<Tooltip inverted rounded title="Download style">
|
|
|
|
<MdFileDownload />
|
|
|
|
</Tooltip>
|
|
|
|
</Button>
|
|
|
|
</Block>
|
|
|
|
}
|
|
|
|
|
2016-09-08 19:47:29 +02:00
|
|
|
return <Container style={{
|
|
|
|
zIndex: 100,
|
|
|
|
position: "fixed",
|
|
|
|
height: "100%",
|
|
|
|
left: "0",
|
|
|
|
top: "0",
|
|
|
|
bottom: "0",
|
|
|
|
backgroundColor: theme.colors.black }
|
|
|
|
}>
|
|
|
|
<Block>
|
2016-09-08 20:35:21 +02:00
|
|
|
<FileReaderInput onChange={this.onUpload}>
|
2016-09-09 16:58:48 +02:00
|
|
|
<Button big={true} theme={this.state.styleUploaded ? "default" : "success"}>
|
|
|
|
<Tooltip inverted rounded title="Upload style">
|
|
|
|
<MdFileUpload />
|
2016-09-08 20:35:21 +02:00
|
|
|
</Tooltip>
|
|
|
|
</Button>
|
|
|
|
</FileReaderInput>
|
2016-09-08 19:47:29 +02:00
|
|
|
</Block>
|
2016-09-09 16:58:48 +02:00
|
|
|
{downloadButton}
|
2016-09-08 19:47:29 +02:00
|
|
|
<Block>
|
2016-09-09 17:09:13 +02:00
|
|
|
<Button big={true} onClick={this.props.onOpenLayers}>
|
2016-09-08 19:47:29 +02:00
|
|
|
<Tooltip inverted rounded title="Layers">
|
|
|
|
<MdLayers />
|
2016-09-09 17:09:13 +02:00
|
|
|
</Tooltip>
|
|
|
|
</Button>
|
|
|
|
</Block>
|
|
|
|
<Block>
|
|
|
|
<Button big={true} onClick={this.props.onOpenSettings}>
|
|
|
|
<Tooltip inverted rounded title="Settings">
|
|
|
|
<MdSettings />
|
2016-09-08 19:47:29 +02:00
|
|
|
</Tooltip>
|
|
|
|
</Button>
|
|
|
|
</Block>
|
|
|
|
</Container>
|
|
|
|
}
|
|
|
|
}
|