2016-12-20 11:44:22 +01:00
|
|
|
import React from 'react'
|
|
|
|
import FileReaderInput from 'react-file-reader-input'
|
2016-09-08 19:47:29 +02:00
|
|
|
|
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-12-20 11:44:22 +01:00
|
|
|
import SettingsModal from './modals/SettingsModal'
|
|
|
|
import TilesetsModal from './modals/TilesetsModal'
|
|
|
|
|
|
|
|
import style from '../libs/style'
|
|
|
|
import colors from '../config/colors';
|
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-12-21 14:46:51 +01:00
|
|
|
const ToolbarAction = props => <a onClick={props.onClick}
|
|
|
|
style={{ display: "inline-block", ...props.style }}>
|
|
|
|
{props.children}
|
|
|
|
</a>
|
|
|
|
|
2016-12-20 11:44:22 +01:00
|
|
|
export default class Toolbar extends React.Component {
|
2016-12-04 17:03:36 +01:00
|
|
|
static propTypes = {
|
2016-12-20 16:08:49 +01:00
|
|
|
mapStyle: React.PropTypes.object.isRequired,
|
2016-12-16 16:52:16 +01:00
|
|
|
onStyleChanged: React.PropTypes.func.isRequired,
|
2016-12-04 17:03:36 +01:00
|
|
|
// 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,
|
2016-12-16 16:52:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
openSettingsModal: false,
|
2016-12-16 17:35:09 +01:00
|
|
|
openTilesetsModal: false,
|
2016-12-16 16:52:16 +01:00
|
|
|
}
|
2016-12-04 17:03:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onUpload(_, files) {
|
|
|
|
const [e, file] = files[0];
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.readAsText(file, "UTF-8");
|
|
|
|
reader.onload = e => {
|
2016-12-20 16:08:49 +01:00
|
|
|
let mapStyle = JSON.parse(e.target.result)
|
2016-12-04 17:03:36 +01:00
|
|
|
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() {
|
2016-12-20 16:08:49 +01:00
|
|
|
if(this.props.mapStyle.layers.length > 0) {
|
2016-12-04 17:03:36 +01:00
|
|
|
return <InlineBlock>
|
2016-12-21 14:46:51 +01:00
|
|
|
<ToolbarAction onClick={this.props.onStyleSave} big={true}>
|
2016-12-04 17:03:36 +01:00
|
|
|
<MdSave />
|
|
|
|
Save
|
2016-12-21 14:46:51 +01:00
|
|
|
</ToolbarAction>
|
2016-12-04 17:03:36 +01:00
|
|
|
</InlineBlock>
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
2016-09-09 00:10:54 +02:00
|
|
|
|
2016-12-04 17:03:36 +01:00
|
|
|
downloadButton() {
|
2016-12-20 20:50:19 +01:00
|
|
|
return <InlineBlock>
|
2016-12-21 14:46:51 +01:00
|
|
|
<ToolbarAction onClick={this.props.onStyleDownload} big={true}>
|
2016-12-20 20:50:19 +01:00
|
|
|
<MdFileDownload />
|
|
|
|
Download
|
2016-12-21 14:46:51 +01:00
|
|
|
</ToolbarAction>
|
2016-12-20 20:50:19 +01:00
|
|
|
</InlineBlock>
|
2016-12-04 17:03:36 +01:00
|
|
|
}
|
2016-09-10 14:56:59 +02:00
|
|
|
|
2016-12-16 16:52:16 +01:00
|
|
|
toggleSettings() {
|
|
|
|
this.setState({openSettingsModal: !this.state.openSettingsModal})
|
|
|
|
}
|
2016-09-09 16:58:48 +02:00
|
|
|
|
2016-12-16 17:35:09 +01:00
|
|
|
toggleTilesets() {
|
|
|
|
this.setState({openTilesetsModal: !this.state.openTilesetsModal})
|
|
|
|
}
|
|
|
|
|
2016-12-16 16:52:16 +01:00
|
|
|
render() {
|
2016-12-04 17:03:36 +01:00
|
|
|
return <div style={{
|
|
|
|
position: "fixed",
|
2016-12-20 20:36:02 +01:00
|
|
|
height: 40,
|
2016-12-04 17:03:36 +01:00
|
|
|
width: '100%',
|
|
|
|
zIndex: 100,
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
2016-12-20 11:44:22 +01:00
|
|
|
backgroundColor: colors.black
|
2016-12-04 17:03:36 +01:00
|
|
|
}}>
|
2016-12-16 16:52:16 +01:00
|
|
|
<SettingsModal
|
|
|
|
mapStyle={this.props.mapStyle}
|
|
|
|
onStyleChanged={this.props.onStyleChanged}
|
|
|
|
open={this.state.openSettingsModal}
|
|
|
|
toggle={() => this.toggleSettings.bind(this)}
|
|
|
|
/>
|
2016-12-16 17:35:09 +01:00
|
|
|
<TilesetsModal
|
|
|
|
mapStyle={this.props.mapStyle}
|
|
|
|
onStyleChanged={this.props.onStyleChanged}
|
|
|
|
open={this.state.openTilesetsModal}
|
|
|
|
toggle={() => this.toggleSettings.bind(this)}
|
|
|
|
/>
|
2016-12-04 17:03:36 +01:00
|
|
|
<InlineBlock>
|
2016-12-21 14:46:51 +01:00
|
|
|
<ToolbarAction style={{
|
2016-12-20 20:36:02 +01:00
|
|
|
width: 180,
|
|
|
|
textAlign: 'left',
|
|
|
|
backgroundColor: colors.black
|
|
|
|
}}>
|
|
|
|
<img src="https://github.com/maputnik/editor/raw/master/media/maputnik.png" alt="Maputnik" style={{width: 30, height: 30, paddingRight: 5, verticalAlign: 'middle'}}/>
|
|
|
|
<span style={{fontSize: 20, verticalAlign: 'middle' }}>Maputnik</span>
|
2016-12-21 14:46:51 +01:00
|
|
|
</ToolbarAction>
|
2016-12-04 17:03:36 +01:00
|
|
|
</InlineBlock>
|
|
|
|
<InlineBlock>
|
|
|
|
<FileReaderInput onChange={this.onUpload.bind(this)}>
|
2016-12-21 14:46:51 +01:00
|
|
|
<ToolbarAction>
|
2016-12-04 17:03:36 +01:00
|
|
|
<MdOpenInBrowser />
|
|
|
|
Open
|
2016-12-21 14:46:51 +01:00
|
|
|
</ToolbarAction>
|
2016-12-04 17:03:36 +01:00
|
|
|
</FileReaderInput>
|
|
|
|
</InlineBlock>
|
|
|
|
{this.downloadButton()}
|
|
|
|
{this.saveButton()}
|
|
|
|
<InlineBlock>
|
2016-12-21 14:46:51 +01:00
|
|
|
<ToolbarAction onClick={this.toggleTilesets.bind(this)}>
|
2016-12-04 17:03:36 +01:00
|
|
|
<MdLayers />
|
|
|
|
Tilesets
|
2016-12-21 14:46:51 +01:00
|
|
|
</ToolbarAction>
|
2016-12-04 17:03:36 +01:00
|
|
|
</InlineBlock>
|
|
|
|
<InlineBlock>
|
2016-12-21 14:46:51 +01:00
|
|
|
<ToolbarAction onClick={this.toggleSettings.bind(this)}>
|
2016-12-16 16:57:21 +01:00
|
|
|
<MdSettings />
|
|
|
|
Style Settings
|
2016-12-21 14:46:51 +01:00
|
|
|
</ToolbarAction>
|
2016-12-04 17:03:36 +01:00
|
|
|
</InlineBlock>
|
|
|
|
<InlineBlock>
|
2016-12-21 14:46:51 +01:00
|
|
|
<ToolbarAction onClick={this.toggleSettings.bind(this)}>
|
2016-12-04 17:03:36 +01:00
|
|
|
<MdFindInPage />
|
|
|
|
Inspect
|
2016-12-21 14:46:51 +01:00
|
|
|
</ToolbarAction>
|
2016-12-04 17:03:36 +01:00
|
|
|
</InlineBlock>
|
|
|
|
<InlineBlock>
|
2016-12-21 14:46:51 +01:00
|
|
|
<ToolbarAction onClick={this.props.onOpenAbout}>
|
2016-12-04 17:03:36 +01:00
|
|
|
<MdHelpOutline />
|
|
|
|
Help
|
2016-12-21 14:46:51 +01:00
|
|
|
</ToolbarAction>
|
2016-12-04 17:03:36 +01:00
|
|
|
</InlineBlock>
|
|
|
|
</div>
|
|
|
|
}
|
2016-09-08 19:47:29 +02:00
|
|
|
}
|