2016-12-20 11:44:22 +01:00
|
|
|
import React from 'react'
|
2017-11-06 16:32:04 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2017-01-11 09:35:48 +01:00
|
|
|
import classnames from 'classnames'
|
2019-05-18 19:19:23 +02:00
|
|
|
import {detect} from 'detect-browser';
|
2016-09-08 19:47:29 +02:00
|
|
|
|
2018-10-06 17:06:21 +02:00
|
|
|
import {MdFileDownload, MdOpenInBrowser, MdSettings, MdLayers, MdHelpOutline, MdFindInPage, MdAssignmentTurnedIn} from 'react-icons/md'
|
2016-09-10 22:08:26 +02:00
|
|
|
|
2018-06-18 21:28:24 +02:00
|
|
|
|
2017-10-11 12:17:02 +02:00
|
|
|
import logoImage from 'maputnik-design/logos/logo-color.svg'
|
2018-01-31 22:04:49 +01:00
|
|
|
import pkgJson from '../../package.json'
|
2016-12-20 11:44:22 +01:00
|
|
|
|
2016-09-08 19:47:29 +02:00
|
|
|
|
2019-05-18 19:19:23 +02:00
|
|
|
// This is required because of <https://stackoverflow.com/a/49846426>, there isn't another way to detect support that I'm aware of.
|
|
|
|
const browser = detect();
|
|
|
|
const colorAccessibilityFiltersEnabled = ['chrome', 'firefox'].indexOf(browser.name) > -1;
|
|
|
|
|
|
|
|
|
2017-11-08 09:47:36 +01:00
|
|
|
class IconText extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <span className="maputnik-icon-text">{this.props.children}</span>
|
|
|
|
}
|
2017-01-11 09:35:48 +01:00
|
|
|
}
|
2016-12-04 17:03:36 +01:00
|
|
|
|
2017-11-08 09:47:36 +01:00
|
|
|
class ToolbarLink extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
children: PropTypes.node,
|
2017-11-08 09:51:24 +01:00
|
|
|
href: PropTypes.string,
|
2018-06-03 11:00:50 +02:00
|
|
|
onToggleModal: PropTypes.func,
|
2017-11-08 09:47:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <a
|
|
|
|
className={classnames('maputnik-toolbar-link', this.props.className)}
|
|
|
|
href={this.props.href}
|
2017-11-08 10:01:35 +01:00
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
2017-11-08 09:47:36 +01:00
|
|
|
>
|
|
|
|
{this.props.children}
|
|
|
|
</a>
|
|
|
|
}
|
2017-01-11 09:35:48 +01:00
|
|
|
}
|
2016-12-21 14:46:51 +01:00
|
|
|
|
2018-06-25 19:52:48 +02:00
|
|
|
class ToolbarLinkHighlighted extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
children: PropTypes.node,
|
|
|
|
href: PropTypes.string,
|
|
|
|
onToggleModal: PropTypes.func
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <a
|
2018-07-08 14:42:49 +02:00
|
|
|
className={classnames('maputnik-toolbar-link', "maputnik-toolbar-link--highlighted", this.props.className)}
|
2018-06-25 19:52:48 +02:00
|
|
|
href={this.props.href}
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
<span className="maputnik-toolbar-link-wrapper">
|
|
|
|
{this.props.children}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-06 14:54:02 +02:00
|
|
|
class ToolbarSelect extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
wdKey: PropTypes.string
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <div
|
|
|
|
className='maputnik-toolbar-select'
|
|
|
|
data-wd-key={this.props.wdKey}
|
|
|
|
>
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-08 09:47:36 +01:00
|
|
|
class ToolbarAction extends React.Component {
|
|
|
|
static propTypes = {
|
2017-11-08 09:51:24 +01:00
|
|
|
children: PropTypes.node,
|
2018-04-10 16:15:29 +02:00
|
|
|
onClick: PropTypes.func,
|
|
|
|
wdKey: PropTypes.string
|
2017-11-08 09:47:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-05-10 17:50:37 +02:00
|
|
|
return <button
|
2017-11-08 09:47:36 +01:00
|
|
|
className='maputnik-toolbar-action'
|
2018-01-05 18:45:55 +01:00
|
|
|
data-wd-key={this.props.wdKey}
|
2017-11-08 09:47:36 +01:00
|
|
|
onClick={this.props.onClick}
|
|
|
|
>
|
|
|
|
{this.props.children}
|
2018-05-10 17:50:37 +02:00
|
|
|
</button>
|
2017-11-08 09:47:36 +01:00
|
|
|
}
|
2016-12-22 14:18:07 +01:00
|
|
|
}
|
2016-12-22 11:27:53 +01:00
|
|
|
|
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 = {
|
2017-11-06 16:32:04 +01:00
|
|
|
mapStyle: PropTypes.object.isRequired,
|
|
|
|
inspectModeEnabled: PropTypes.bool.isRequired,
|
|
|
|
onStyleChanged: PropTypes.func.isRequired,
|
2016-12-04 17:03:36 +01:00
|
|
|
// A new style has been uploaded
|
2017-11-06 16:32:04 +01:00
|
|
|
onStyleOpen: PropTypes.func.isRequired,
|
2016-12-29 14:44:46 +01:00
|
|
|
// A dict of source id's and the available source layers
|
2017-11-06 16:32:04 +01:00
|
|
|
sources: PropTypes.object.isRequired,
|
2018-06-03 11:18:55 +02:00
|
|
|
children: PropTypes.node,
|
|
|
|
onToggleModal: PropTypes.func,
|
2018-09-23 15:50:29 +02:00
|
|
|
onSetMapState: PropTypes.func,
|
|
|
|
mapState: PropTypes.string,
|
2019-05-29 19:59:26 +02:00
|
|
|
renderer: PropTypes.string,
|
2016-12-16 16:52:16 +01:00
|
|
|
}
|
|
|
|
|
2018-08-23 03:09:37 +02:00
|
|
|
state = {
|
|
|
|
isOpen: {
|
|
|
|
settings: false,
|
|
|
|
sources: false,
|
|
|
|
open: false,
|
|
|
|
add: false,
|
|
|
|
export: false,
|
2016-12-16 16:52:16 +01:00
|
|
|
}
|
2016-12-04 17:03:36 +01:00
|
|
|
}
|
|
|
|
|
2018-06-18 21:28:24 +02:00
|
|
|
handleSelection(val) {
|
|
|
|
this.props.onSetMapState(val);
|
|
|
|
}
|
|
|
|
|
2016-12-22 16:54:22 +01:00
|
|
|
render() {
|
2018-06-18 21:28:24 +02:00
|
|
|
const views = [
|
|
|
|
{
|
|
|
|
id: "map",
|
|
|
|
title: "Map",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "inspect",
|
|
|
|
title: "Inspect",
|
2019-05-29 18:37:55 +02:00
|
|
|
disabled: this.props.renderer !== 'mbgljs',
|
2018-06-18 21:28:24 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "filter-deuteranopia",
|
2018-09-23 15:39:02 +02:00
|
|
|
title: "Map (deuteranopia)",
|
2019-05-18 19:19:23 +02:00
|
|
|
disabled: !colorAccessibilityFiltersEnabled,
|
2018-06-18 21:28:24 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "filter-protanopia",
|
2018-09-23 15:39:02 +02:00
|
|
|
title: "Map (protanopia)",
|
2019-05-18 19:19:23 +02:00
|
|
|
disabled: !colorAccessibilityFiltersEnabled,
|
2018-06-18 21:28:24 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "filter-tritanopia",
|
2018-09-23 15:39:02 +02:00
|
|
|
title: "Map (tritanopia)",
|
2019-05-18 19:19:23 +02:00
|
|
|
disabled: !colorAccessibilityFiltersEnabled,
|
2018-06-18 21:28:24 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "filter-achromatopsia",
|
2018-09-23 15:39:02 +02:00
|
|
|
title: "Map (achromatopsia)",
|
2019-05-18 19:19:23 +02:00
|
|
|
disabled: !colorAccessibilityFiltersEnabled,
|
2018-06-18 21:28:24 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-09-23 15:39:02 +02:00
|
|
|
const currentView = views.find((view) => {
|
|
|
|
return view.id === this.props.mapState;
|
|
|
|
});
|
|
|
|
|
2017-01-10 21:28:30 +01:00
|
|
|
return <div className='maputnik-toolbar'>
|
2017-11-06 11:23:13 +01:00
|
|
|
<div className="maputnik-toolbar__inner">
|
2018-06-03 17:37:46 +02:00
|
|
|
<div
|
|
|
|
className="maputnik-toolbar-logo-container"
|
2017-11-06 11:23:13 +01:00
|
|
|
>
|
2018-06-03 17:37:46 +02:00
|
|
|
<a className="maputnik-toolbar-skip" href="#skip-menu">
|
2018-05-28 12:29:49 +02:00
|
|
|
Skip navigation
|
2018-05-28 11:50:19 +02:00
|
|
|
</a>
|
2018-06-03 17:37:46 +02:00
|
|
|
<a
|
|
|
|
href="https://github.com/maputnik/editor"
|
2018-06-03 17:59:41 +02:00
|
|
|
rel="noopener noreferrer"
|
2018-06-03 17:37:46 +02:00
|
|
|
target="_blank"
|
|
|
|
className="maputnik-toolbar-logo"
|
|
|
|
>
|
2020-02-17 16:39:54 +01:00
|
|
|
<span dangerouslySetInnerHTML={{__html: logoImage}} />
|
2018-10-04 16:42:39 +02:00
|
|
|
<h1>
|
|
|
|
<span className="maputnik-toolbar-name">{pkgJson.name}</span>
|
2018-06-03 17:37:46 +02:00
|
|
|
<span className="maputnik-toolbar-version">v{pkgJson.version}</span>
|
|
|
|
</h1>
|
|
|
|
</a>
|
|
|
|
</div>
|
2017-11-06 11:23:13 +01:00
|
|
|
<div className="maputnik-toolbar__actions">
|
2018-05-29 18:06:00 +02:00
|
|
|
<ToolbarAction wdKey="nav:open" onClick={this.props.onToggleModal.bind(this, 'open')}>
|
2018-10-06 17:06:21 +02:00
|
|
|
<MdOpenInBrowser />
|
2017-11-06 11:23:13 +01:00
|
|
|
<IconText>Open</IconText>
|
|
|
|
</ToolbarAction>
|
2018-05-29 18:06:00 +02:00
|
|
|
<ToolbarAction wdKey="nav:export" onClick={this.props.onToggleModal.bind(this, 'export')}>
|
2017-11-06 11:23:13 +01:00
|
|
|
<MdFileDownload />
|
|
|
|
<IconText>Export</IconText>
|
|
|
|
</ToolbarAction>
|
2018-05-29 18:06:00 +02:00
|
|
|
<ToolbarAction wdKey="nav:sources" onClick={this.props.onToggleModal.bind(this, 'sources')}>
|
2018-10-06 17:06:21 +02:00
|
|
|
<MdLayers />
|
2018-06-03 10:17:53 +02:00
|
|
|
<IconText>Data Sources</IconText>
|
2017-11-06 11:23:13 +01:00
|
|
|
</ToolbarAction>
|
2018-05-29 18:06:00 +02:00
|
|
|
<ToolbarAction wdKey="nav:settings" onClick={this.props.onToggleModal.bind(this, 'settings')}>
|
2018-10-06 17:06:21 +02:00
|
|
|
<MdSettings />
|
2017-11-06 11:23:13 +01:00
|
|
|
<IconText>Style Settings</IconText>
|
|
|
|
</ToolbarAction>
|
2018-06-18 21:28:24 +02:00
|
|
|
|
2018-10-06 14:54:02 +02:00
|
|
|
<ToolbarSelect wdKey="nav:inspect">
|
2018-10-06 17:06:21 +02:00
|
|
|
<MdFindInPage />
|
2018-10-06 14:54:02 +02:00
|
|
|
<IconText>View </IconText>
|
2019-01-06 06:20:03 +01:00
|
|
|
<select onChange={(e) => this.handleSelection(e.target.value)} value={currentView.id}>
|
2018-10-06 14:54:02 +02:00
|
|
|
{views.map((item) => {
|
|
|
|
return (
|
2019-05-18 19:19:23 +02:00
|
|
|
<option key={item.id} value={item.id} disabled={item.disabled}>
|
2018-10-06 14:54:02 +02:00
|
|
|
{item.title}
|
|
|
|
</option>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</select>
|
|
|
|
</ToolbarSelect>
|
2018-06-18 21:28:24 +02:00
|
|
|
|
2017-11-06 11:23:13 +01:00
|
|
|
<ToolbarLink href={"https://github.com/maputnik/editor/wiki"}>
|
2018-10-06 17:06:21 +02:00
|
|
|
<MdHelpOutline />
|
2017-11-06 11:23:13 +01:00
|
|
|
<IconText>Help</IconText>
|
|
|
|
</ToolbarLink>
|
2018-06-25 19:52:48 +02:00
|
|
|
<ToolbarLinkHighlighted href={"https://gregorywolanski.typeform.com/to/cPgaSY"}>
|
2018-10-06 17:06:21 +02:00
|
|
|
<MdAssignmentTurnedIn />
|
2018-06-25 19:52:48 +02:00
|
|
|
<IconText>Take the Maputnik Survey</IconText>
|
|
|
|
</ToolbarLinkHighlighted>
|
2017-11-06 11:23:13 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2016-12-04 17:03:36 +01:00
|
|
|
</div>
|
|
|
|
}
|
2016-09-08 19:47:29 +02:00
|
|
|
}
|