mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-29 11:30:27 +01:00
Fix style download and strip metadata
This commit is contained in:
parent
fc8665ed93
commit
82a11e4b98
3 changed files with 14 additions and 25 deletions
|
@ -1,5 +1,4 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { saveAs } from 'file-saver'
|
|
||||||
import Mousetrap from 'mousetrap'
|
import Mousetrap from 'mousetrap'
|
||||||
|
|
||||||
import MapboxGlMap from './map/MapboxGlMap'
|
import MapboxGlMap from './map/MapboxGlMap'
|
||||||
|
@ -90,12 +89,6 @@ export default class App extends React.Component {
|
||||||
loadDefaultStyle(mapStyle => this.onStyleOpen(mapStyle))
|
loadDefaultStyle(mapStyle => this.onStyleOpen(mapStyle))
|
||||||
}
|
}
|
||||||
|
|
||||||
onStyleDownload() {
|
|
||||||
const mapStyle = this.state.mapStyle
|
|
||||||
const blob = new Blob([formatStyle(mapStyle)], {type: "application/json;charset=utf-8"});
|
|
||||||
saveAs(blob, mapStyle.id + ".json");
|
|
||||||
}
|
|
||||||
|
|
||||||
saveStyle(snapshotStyle) {
|
saveStyle(snapshotStyle) {
|
||||||
this.styleStore.save(snapshotStyle)
|
this.styleStore.save(snapshotStyle)
|
||||||
}
|
}
|
||||||
|
@ -228,7 +221,6 @@ export default class App extends React.Component {
|
||||||
sources={this.state.sources}
|
sources={this.state.sources}
|
||||||
onStyleChanged={this.onStyleChanged.bind(this)}
|
onStyleChanged={this.onStyleChanged.bind(this)}
|
||||||
onStyleOpen={this.onStyleChanged.bind(this)}
|
onStyleOpen={this.onStyleChanged.bind(this)}
|
||||||
onStyleDownload={this.onStyleDownload.bind(this)}
|
|
||||||
onInspectModeToggle={this.changeInspectMode.bind(this)}
|
onInspectModeToggle={this.changeInspectMode.bind(this)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,6 @@ export default class Toolbar extends React.Component {
|
||||||
onStyleChanged: React.PropTypes.func.isRequired,
|
onStyleChanged: React.PropTypes.func.isRequired,
|
||||||
// A new style has been uploaded
|
// A new style has been uploaded
|
||||||
onStyleOpen: React.PropTypes.func.isRequired,
|
onStyleOpen: React.PropTypes.func.isRequired,
|
||||||
// Current style is requested for download
|
|
||||||
onStyleDownload: React.PropTypes.func.isRequired,
|
|
||||||
// A dict of source id's and the available source layers
|
// A dict of source id's and the available source layers
|
||||||
sources: React.PropTypes.object.isRequired,
|
sources: React.PropTypes.object.isRequired,
|
||||||
onInspectModeToggle: React.PropTypes.func.isRequired
|
onInspectModeToggle: React.PropTypes.func.isRequired
|
||||||
|
@ -74,13 +72,6 @@ export default class Toolbar extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadButton() {
|
|
||||||
return <ToolbarAction onClick={this.props.onStyleDownload}>
|
|
||||||
<MdFileDownload />
|
|
||||||
<IconText>Download</IconText>
|
|
||||||
</ToolbarAction>
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleModal(modalName) {
|
toggleModal(modalName) {
|
||||||
this.setState({
|
this.setState({
|
||||||
isOpen: {
|
isOpen: {
|
||||||
|
@ -100,7 +91,6 @@ export default class Toolbar extends React.Component {
|
||||||
/>
|
/>
|
||||||
<ExportModal
|
<ExportModal
|
||||||
mapStyle={this.props.mapStyle}
|
mapStyle={this.props.mapStyle}
|
||||||
onStyleDownload={this.props.onStyleDownload}
|
|
||||||
isOpen={this.state.isOpen.export}
|
isOpen={this.state.isOpen.export}
|
||||||
onOpenToggle={this.toggleModal.bind(this, 'export')}
|
onOpenToggle={this.toggleModal.bind(this, 'export')}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { saveAs } from 'file-saver'
|
||||||
|
|
||||||
import GlSpec from 'mapbox-gl-style-spec/reference/latest.js'
|
import GlSpec from 'mapbox-gl-style-spec/reference/latest.js'
|
||||||
import InputBlock from '../inputs/InputBlock'
|
import InputBlock from '../inputs/InputBlock'
|
||||||
|
@ -103,24 +104,30 @@ class Gist extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stripAccessTokens(mapStyle) {
|
||||||
|
const changedMetadata = { ...mapStyle.metadata }
|
||||||
|
delete changedMetadata['maputnik:mapbox_access_token']
|
||||||
|
delete changedMetadata['maputnik:openmaptiles_access_token']
|
||||||
|
return {
|
||||||
|
...mapStyle,
|
||||||
|
metadata: changedMetadata
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ExportModal extends React.Component {
|
class ExportModal extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
mapStyle: React.PropTypes.object.isRequired,
|
mapStyle: React.PropTypes.object.isRequired,
|
||||||
isOpen: React.PropTypes.bool.isRequired,
|
isOpen: React.PropTypes.bool.isRequired,
|
||||||
onOpenToggle: React.PropTypes.func.isRequired,
|
onOpenToggle: React.PropTypes.func.isRequired,
|
||||||
// Current style is requested for download
|
|
||||||
onStyleDownload: React.PropTypes.func.isRequired,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
onStyleDownload() {
|
downloadStyle() {
|
||||||
const blob = new Blob([formatStyle(mapStyle)], {type: "application/json;charset=utf-8"});
|
const blob = new Blob([formatStyle(stripAccessTokens(this.props.mapStyle))], {type: "application/json;charset=utf-8"});
|
||||||
saveAs(blob, mapStyle.id + ".json");
|
saveAs(blob, this.props.mapStyle.id + ".json");
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -135,7 +142,7 @@ class ExportModal extends React.Component {
|
||||||
<p>
|
<p>
|
||||||
Download a JSON style to your computer.
|
Download a JSON style to your computer.
|
||||||
</p>
|
</p>
|
||||||
<Button onClick={this.props.onStyleDownload}>
|
<Button onClick={this.downloadStyle.bind(this)}>
|
||||||
<MdFileDownload />
|
<MdFileDownload />
|
||||||
Download
|
Download
|
||||||
</Button>
|
</Button>
|
||||||
|
|
Loading…
Reference in a new issue