From b66a4afd28f4125d9baecc34cf6296b76e872d13 Mon Sep 17 00:00:00 2001 From: orangemug Date: Fri, 2 Feb 2018 15:33:15 +0000 Subject: [PATCH] Do not expose fallback tokens during export. Fixes #230 --- src/components/App.jsx | 2 +- src/libs/style.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index 4eca4c3..bd5ffec 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -247,7 +247,7 @@ export default class App extends React.Component { mapRenderer() { const mapProps = { - mapStyle: style.replaceAccessToken(this.state.mapStyle), + mapStyle: style.replaceAccessToken(this.state.mapStyle, {allowFallback: true}), onDataChange: (e) => { this.layerWatcher.analyzeMap(e.map) this.fetchSources(); diff --git a/src/libs/style.js b/src/libs/style.js index 4441912..0e78652 100644 --- a/src/libs/style.js +++ b/src/libs/style.js @@ -54,13 +54,23 @@ function indexOfLayer(layers, layerId) { return null } -function replaceAccessToken(mapStyle) { +function replaceAccessToken(mapStyle, opts={}) { const omtSource = mapStyle.sources.openmaptiles if(!omtSource) return mapStyle if(!omtSource.hasOwnProperty("url")) return mapStyle const metadata = mapStyle.metadata || {} - const accessToken = metadata['maputnik:openmaptiles_access_token'] || tokens.openmaptiles + let accessToken = metadata['maputnik:openmaptiles_access_token']; + + if(opts.allowFallback && !accessToken) { + accessToken = tokens.openmaptiles; + } + + if(!accessToken) { + // Early exit. + return mapStyle; + } + const changedSources = { ...mapStyle.sources, openmaptiles: {