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-15 09:13:23 +02:00
|
|
|
import Button from 'rebass/dist/Button'
|
|
|
|
import Text from 'rebass/dist/Text'
|
|
|
|
import Menu from 'rebass/dist/Menu'
|
|
|
|
import NavItem from 'rebass/dist/NavItem'
|
|
|
|
import Tooltip from 'rebass/dist/Tooltip'
|
|
|
|
import Container from 'rebass/dist/Container'
|
|
|
|
import Block from 'rebass/dist/Block'
|
|
|
|
import Fixed from 'rebass/dist/Fixed'
|
2016-09-10 14:47:06 +02:00
|
|
|
|
|
|
|
import MdFileDownload from 'react-icons/lib/md/file-download'
|
|
|
|
import MdFileUpload from 'react-icons/lib/md/file-upload'
|
2016-12-04 17:03:36 +01:00
|
|
|
import MdOpenInBrowser from 'react-icons/lib/md/open-in-browser'
|
2016-09-10 14:47:06 +02:00
|
|
|
import MdSettings from 'react-icons/lib/md/settings'
|
2016-09-19 20:49:16 +02:00
|
|
|
import MdInfo from 'react-icons/lib/md/info'
|
2016-09-10 14:47:06 +02:00
|
|
|
import MdLayers from 'react-icons/lib/md/layers'
|
|
|
|
import MdSave from 'react-icons/lib/md/save'
|
2016-12-04 17:03:36 +01:00
|
|
|
import MdStyle from 'react-icons/lib/md/style'
|
2016-09-10 22:08:26 +02:00
|
|
|
import MdMap from 'react-icons/lib/md/map'
|
2016-12-04 17:03:36 +01:00
|
|
|
import MdInsertEmoticon from 'react-icons/lib/md/insert-emoticon'
|
|
|
|
import MdFontDownload from 'react-icons/lib/md/font-download'
|
|
|
|
import MdHelpOutline from 'react-icons/lib/md/help-outline'
|
|
|
|
import MdFindInPage from 'react-icons/lib/md/find-in-page'
|
2016-09-10 22:08:26 +02:00
|
|
|
|
2016-09-14 20:22:32 +02:00
|
|
|
import style from './style.js'
|
2016-09-10 16:11:43 +02:00
|
|
|
import { fullHeight } from './theme.js'
|
2016-09-09 00:10:54 +02:00
|
|
|
import theme from './theme.js';
|
2016-09-08 19:47:29 +02:00
|
|
|
|
2016-12-04 17:03:36 +01:00
|
|
|
const InlineBlock = props => <div style={{display: "inline-block", ...props.style}}>
|
|
|
|
{props.children}
|
|
|
|
</div>
|
|
|
|
|
2016-09-08 19:47:29 +02:00
|
|
|
export class Toolbar extends React.Component {
|
2016-12-04 17:03:36 +01:00
|
|
|
static propTypes = {
|
|
|
|
// A new style has been uploaded
|
|
|
|
onStyleUpload: React.PropTypes.func.isRequired,
|
|
|
|
// Current style is requested for download
|
|
|
|
onStyleDownload: React.PropTypes.func.isRequired,
|
|
|
|
// Style is explicitely saved to local cache
|
|
|
|
onStyleSave: React.PropTypes.func,
|
|
|
|
// Open settings drawer
|
|
|
|
onOpenSettings: React.PropTypes.func,
|
|
|
|
// Open about page
|
|
|
|
onOpenAbout: React.PropTypes.func,
|
|
|
|
// Open sources drawer
|
|
|
|
onOpenSources: React.PropTypes.func,
|
|
|
|
// Whether a style is available for download or saving
|
|
|
|
// A style with no layers should not be available
|
|
|
|
styleAvailable: React.PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
onUpload(_, files) {
|
|
|
|
const [e, file] = files[0];
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.readAsText(file, "UTF-8");
|
|
|
|
reader.onload = e => {
|
|
|
|
let mapStyle = style.fromJSON(JSON.parse(e.target.result))
|
|
|
|
mapStyle = style.ensureMetadataExists(mapStyle)
|
|
|
|
this.props.onStyleUpload(mapStyle);
|
|
|
|
}
|
|
|
|
reader.onerror = e => console.log(e.target);
|
|
|
|
}
|
2016-09-09 16:58:48 +02:00
|
|
|
|
2016-12-04 17:03:36 +01:00
|
|
|
saveButton() {
|
|
|
|
if(this.props.styleAvailable) {
|
|
|
|
return <InlineBlock>
|
|
|
|
<Button onClick={this.props.onStyleSave} big={true}>
|
|
|
|
<MdSave />
|
|
|
|
Save
|
|
|
|
</Button>
|
|
|
|
</InlineBlock>
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
2016-09-09 00:10:54 +02:00
|
|
|
|
2016-12-04 17:03:36 +01:00
|
|
|
downloadButton() {
|
|
|
|
if(this.props.styleAvailable) {
|
|
|
|
return <InlineBlock>
|
|
|
|
<Button onClick={this.props.onStyleDownload} big={true}>
|
|
|
|
<MdFileDownload />
|
|
|
|
Download
|
|
|
|
</Button>
|
|
|
|
</InlineBlock>
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
2016-09-10 14:56:59 +02:00
|
|
|
|
2016-12-04 17:03:36 +01:00
|
|
|
render() {
|
2016-09-09 16:58:48 +02:00
|
|
|
|
2016-12-04 17:03:36 +01:00
|
|
|
return <div style={{
|
|
|
|
position: "fixed",
|
|
|
|
height: 50,
|
|
|
|
width: '100%',
|
|
|
|
zIndex: 100,
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
backgroundColor: theme.colors.black
|
|
|
|
}}>
|
|
|
|
<InlineBlock>
|
|
|
|
<Button style={{width: 300, textAlign: 'left'}}>
|
|
|
|
<img src="https://github.com/maputnik/editor/raw/master/media/maputnik.png" alt="Maputnik" style={{width: 40, height: 40, paddingRight: 5, verticalAlign: 'middle'}}/>
|
|
|
|
<span style={{fontSize: 20 }}>Maputnik</span>
|
|
|
|
</Button>
|
|
|
|
</InlineBlock>
|
|
|
|
<InlineBlock>
|
|
|
|
<FileReaderInput onChange={this.onUpload.bind(this)}>
|
|
|
|
<Button big={true} theme={this.props.styleAvailable ? "default" : "success"}>
|
|
|
|
<MdOpenInBrowser />
|
|
|
|
Open
|
|
|
|
</Button>
|
|
|
|
</FileReaderInput>
|
|
|
|
</InlineBlock>
|
|
|
|
{this.downloadButton()}
|
|
|
|
{this.saveButton()}
|
|
|
|
<InlineBlock>
|
|
|
|
<Button big={true} onClick={this.props.onOpenSettings}>
|
|
|
|
<MdLayers />
|
|
|
|
Tilesets
|
|
|
|
</Button>
|
|
|
|
</InlineBlock>
|
|
|
|
<InlineBlock>
|
|
|
|
<Button big={true} onClick={this.props.onOpenSettings}>
|
|
|
|
<MdFontDownload />
|
|
|
|
Fonts
|
|
|
|
</Button>
|
|
|
|
</InlineBlock>
|
|
|
|
<InlineBlock>
|
|
|
|
<Button big={true} onClick={this.props.onOpenSettings}>
|
|
|
|
<MdInsertEmoticon/>
|
|
|
|
Icons
|
|
|
|
</Button>
|
|
|
|
</InlineBlock>
|
|
|
|
<InlineBlock>
|
|
|
|
<Button big={true} onClick={this.props.onOpenSettings}>
|
|
|
|
<MdFindInPage />
|
|
|
|
Inspect
|
|
|
|
</Button>
|
|
|
|
</InlineBlock>
|
|
|
|
<InlineBlock>
|
|
|
|
<Button big={true} onClick={this.props.onOpenAbout}>
|
|
|
|
<MdHelpOutline />
|
|
|
|
Help
|
|
|
|
</Button>
|
|
|
|
</InlineBlock>
|
|
|
|
</div>
|
|
|
|
}
|
2016-09-08 19:47:29 +02:00
|
|
|
}
|