2017-01-12 18:27:44 +01:00
|
|
|
import React from 'react'
|
2017-11-06 16:32:04 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2017-01-13 15:55:49 +01:00
|
|
|
import { saveAs } from 'file-saver'
|
2017-01-12 18:27:44 +01:00
|
|
|
|
2018-05-17 11:44:54 +02:00
|
|
|
import * as styleSpec from '@mapbox/mapbox-gl-style-spec/style-spec'
|
2017-01-12 18:27:44 +01:00
|
|
|
import InputBlock from '../inputs/InputBlock'
|
|
|
|
import StringInput from '../inputs/StringInput'
|
2017-01-16 15:07:41 +01:00
|
|
|
import CheckboxInput from '../inputs/CheckboxInput'
|
2017-01-12 18:27:44 +01:00
|
|
|
import Button from '../Button'
|
|
|
|
import Modal from './Modal'
|
|
|
|
import MdFileDownload from 'react-icons/lib/md/file-download'
|
2017-10-16 02:59:06 +02:00
|
|
|
import TiClipboard from 'react-icons/lib/ti/clipboard'
|
2018-07-27 17:25:53 +02:00
|
|
|
import style from '../../libs/style'
|
2017-01-12 18:27:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-13 15:55:49 +01:00
|
|
|
function stripAccessTokens(mapStyle) {
|
|
|
|
const changedMetadata = { ...mapStyle.metadata }
|
|
|
|
delete changedMetadata['maputnik:mapbox_access_token']
|
|
|
|
delete changedMetadata['maputnik:openmaptiles_access_token']
|
|
|
|
return {
|
|
|
|
...mapStyle,
|
|
|
|
metadata: changedMetadata
|
|
|
|
}
|
|
|
|
}
|
2017-01-12 18:27:44 +01:00
|
|
|
|
|
|
|
class ExportModal extends React.Component {
|
|
|
|
static propTypes = {
|
2017-11-06 16:32:04 +01:00
|
|
|
mapStyle: PropTypes.object.isRequired,
|
|
|
|
onStyleChanged: PropTypes.func.isRequired,
|
|
|
|
isOpen: PropTypes.bool.isRequired,
|
|
|
|
onOpenToggle: PropTypes.func.isRequired,
|
2017-01-12 18:27:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
2017-01-13 15:55:49 +01:00
|
|
|
downloadStyle() {
|
2018-07-27 17:25:53 +02:00
|
|
|
const tokenStyle = styleSpec.format(stripAccessTokens(style.replaceAccessTokens(this.props.mapStyle)));
|
2018-07-15 23:51:57 +02:00
|
|
|
|
|
|
|
const blob = new Blob([tokenStyle], {type: "application/json;charset=utf-8"});
|
2017-01-13 15:55:49 +01:00
|
|
|
saveAs(blob, this.props.mapStyle.id + ".json");
|
2017-01-12 18:27:44 +01:00
|
|
|
}
|
|
|
|
|
2018-07-15 23:51:57 +02:00
|
|
|
changeMetadataProperty(property, value) {
|
|
|
|
const changedStyle = {
|
|
|
|
...this.props.mapStyle,
|
|
|
|
metadata: {
|
|
|
|
...this.props.mapStyle.metadata,
|
|
|
|
[property]: value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.props.onStyleChanged(changedStyle)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-12 18:27:44 +01:00
|
|
|
render() {
|
|
|
|
return <Modal
|
2018-01-05 18:45:55 +01:00
|
|
|
data-wd-key="export-modal"
|
2017-01-12 18:27:44 +01:00
|
|
|
isOpen={this.props.isOpen}
|
|
|
|
onOpenToggle={this.props.onOpenToggle}
|
|
|
|
title={'Export Style'}
|
|
|
|
>
|
|
|
|
|
|
|
|
<div className="maputnik-modal-section">
|
|
|
|
<h4>Download Style</h4>
|
|
|
|
<p>
|
|
|
|
Download a JSON style to your computer.
|
|
|
|
</p>
|
2018-07-15 23:51:57 +02:00
|
|
|
|
|
|
|
<p>
|
2018-09-14 08:16:45 +02:00
|
|
|
<InputBlock label={"MapTiler Access Token: "}>
|
2018-07-15 23:51:57 +02:00
|
|
|
<StringInput
|
|
|
|
value={(this.props.mapStyle.metadata || {})['maputnik:openmaptiles_access_token']}
|
|
|
|
onChange={this.changeMetadataProperty.bind(this, "maputnik:openmaptiles_access_token")}
|
|
|
|
/>
|
|
|
|
</InputBlock>
|
|
|
|
<InputBlock label={"Mapbox Access Token: "}>
|
|
|
|
<StringInput
|
|
|
|
value={(this.props.mapStyle.metadata || {})['maputnik:mapbox_access_token']}
|
|
|
|
onChange={this.changeMetadataProperty.bind(this, "maputnik:mapbox_access_token")}
|
|
|
|
/>
|
|
|
|
</InputBlock>
|
2018-07-27 17:25:53 +02:00
|
|
|
<InputBlock label={"Thunderforest Access Token: "}>
|
|
|
|
<StringInput
|
|
|
|
value={(this.props.mapStyle.metadata || {})['maputnik:thunderforest_access_token']}
|
|
|
|
onChange={this.changeMetadataProperty.bind(this, "maputnik:thunderforest_access_token")}
|
|
|
|
/>
|
|
|
|
</InputBlock>
|
2018-07-15 23:51:57 +02:00
|
|
|
</p>
|
|
|
|
|
2017-01-13 15:55:49 +01:00
|
|
|
<Button onClick={this.downloadStyle.bind(this)}>
|
2017-01-12 18:27:44 +01:00
|
|
|
<MdFileDownload />
|
|
|
|
Download
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</Modal>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ExportModal
|