mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 01:05:25 +01:00
Merge pull request #606 from orangemug/fix/issue-591
Added style formatting into the api store
This commit is contained in:
commit
c3670701e5
3 changed files with 26 additions and 12 deletions
|
@ -15,16 +15,6 @@ import fieldSpecAdditional from '../../libs/field-spec-additional'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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: PropTypes.object.isRequired,
|
mapStyle: PropTypes.object.isRequired,
|
||||||
|
@ -38,7 +28,11 @@ class ExportModal extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadStyle() {
|
downloadStyle() {
|
||||||
const tokenStyle = format(stripAccessTokens(style.replaceAccessTokens(this.props.mapStyle)));
|
const tokenStyle = format(
|
||||||
|
style.stripAccessTokens(
|
||||||
|
style.replaceAccessTokens(this.props.mapStyle)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
const blob = new Blob([tokenStyle], {type: "application/json;charset=utf-8"});
|
const blob = new Blob([tokenStyle], {type: "application/json;charset=utf-8"});
|
||||||
let exportName;
|
let exportName;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import style from './style.js'
|
import style from './style.js'
|
||||||
|
import {format} from '@mapbox/mapbox-gl-style-spec'
|
||||||
import ReconnectingWebSocket from 'reconnecting-websocket'
|
import ReconnectingWebSocket from 'reconnecting-websocket'
|
||||||
|
|
||||||
export class ApiStyleStore {
|
export class ApiStyleStore {
|
||||||
|
@ -64,6 +65,12 @@ export class ApiStyleStore {
|
||||||
|
|
||||||
// Save current style replacing previous version
|
// Save current style replacing previous version
|
||||||
save(mapStyle) {
|
save(mapStyle) {
|
||||||
|
const styleJSON = format(
|
||||||
|
style.stripAccessTokens(
|
||||||
|
style.replaceAccessTokens(newStyle)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
const id = mapStyle.id
|
const id = mapStyle.id
|
||||||
fetch(this.localUrl + '/styles/' + id, {
|
fetch(this.localUrl + '/styles/' + id, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
@ -71,7 +78,7 @@ export class ApiStyleStore {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(mapStyle)
|
body: styleJSON
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
if(error) console.error(error)
|
if(error) console.error(error)
|
||||||
|
|
|
@ -114,6 +114,18 @@ function replaceAccessTokens(mapStyle, opts={}) {
|
||||||
return changedStyle
|
return changedStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stripAccessTokens(mapStyle) {
|
||||||
|
const changedMetadata = {
|
||||||
|
...mapStyle.metadata
|
||||||
|
};
|
||||||
|
delete changedMetadata['maputnik:mapbox_access_token'];
|
||||||
|
delete changedMetadata['maputnik:openmaptiles_access_token'];
|
||||||
|
return {
|
||||||
|
...mapStyle,
|
||||||
|
metadata: changedMetadata
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
ensureStyleValidity,
|
ensureStyleValidity,
|
||||||
emptyStyle,
|
emptyStyle,
|
||||||
|
@ -121,4 +133,5 @@ export default {
|
||||||
generateId,
|
generateId,
|
||||||
getAccessToken,
|
getAccessToken,
|
||||||
replaceAccessTokens,
|
replaceAccessTokens,
|
||||||
|
stripAccessTokens,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue