mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-15 23:31:18 +01:00
Do not expose fallback tokens during export. Fixes #230
This commit is contained in:
parent
a94c53534c
commit
b66a4afd28
2 changed files with 13 additions and 3 deletions
|
@ -247,7 +247,7 @@ export default class App extends React.Component {
|
||||||
|
|
||||||
mapRenderer() {
|
mapRenderer() {
|
||||||
const mapProps = {
|
const mapProps = {
|
||||||
mapStyle: style.replaceAccessToken(this.state.mapStyle),
|
mapStyle: style.replaceAccessToken(this.state.mapStyle, {allowFallback: true}),
|
||||||
onDataChange: (e) => {
|
onDataChange: (e) => {
|
||||||
this.layerWatcher.analyzeMap(e.map)
|
this.layerWatcher.analyzeMap(e.map)
|
||||||
this.fetchSources();
|
this.fetchSources();
|
||||||
|
|
|
@ -54,13 +54,23 @@ function indexOfLayer(layers, layerId) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceAccessToken(mapStyle) {
|
function replaceAccessToken(mapStyle, opts={}) {
|
||||||
const omtSource = mapStyle.sources.openmaptiles
|
const omtSource = mapStyle.sources.openmaptiles
|
||||||
if(!omtSource) return mapStyle
|
if(!omtSource) return mapStyle
|
||||||
if(!omtSource.hasOwnProperty("url")) return mapStyle
|
if(!omtSource.hasOwnProperty("url")) return mapStyle
|
||||||
|
|
||||||
const metadata = mapStyle.metadata || {}
|
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 = {
|
const changedSources = {
|
||||||
...mapStyle.sources,
|
...mapStyle.sources,
|
||||||
openmaptiles: {
|
openmaptiles: {
|
||||||
|
|
Loading…
Reference in a new issue