mirror of
https://github.com/maputnik/editor.git
synced 2026-06-14 19:27:25 +00:00
Added initial thunderforest source integration
This commit is contained in:
+34
-12
@@ -54,18 +54,24 @@ function indexOfLayer(layers, layerId) {
|
||||
return null
|
||||
}
|
||||
|
||||
function replaceAccessToken(mapStyle, opts={}) {
|
||||
const omtSource = mapStyle.sources.openmaptiles
|
||||
if(!omtSource) return mapStyle
|
||||
if(!omtSource.hasOwnProperty("url")) return mapStyle
|
||||
|
||||
function getAccessToken(key, mapStyle, opts) {
|
||||
const metadata = mapStyle.metadata || {}
|
||||
let accessToken = metadata['maputnik:openmaptiles_access_token'];
|
||||
let accessToken = metadata['maputnik:'+key+'_access_token'];
|
||||
|
||||
if(opts.allowFallback && !accessToken) {
|
||||
accessToken = tokens.openmaptiles;
|
||||
accessToken = tokens[key];
|
||||
}
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
function replaceSourceAccessToken(mapStyle, key, opts={}) {
|
||||
const source = mapStyle.sources[key]
|
||||
if(!source) return mapStyle
|
||||
if(!source.hasOwnProperty("url")) return mapStyle
|
||||
|
||||
const accessToken = getAccessToken(key, mapStyle, opts)
|
||||
|
||||
if(!accessToken) {
|
||||
// Early exit.
|
||||
return mapStyle;
|
||||
@@ -73,24 +79,40 @@ function replaceAccessToken(mapStyle, opts={}) {
|
||||
|
||||
const changedSources = {
|
||||
...mapStyle.sources,
|
||||
openmaptiles: {
|
||||
...omtSource,
|
||||
url: omtSource.url.replace('{key}', accessToken)
|
||||
[key]: {
|
||||
...source,
|
||||
url: source.url.replace('{key}', accessToken)
|
||||
}
|
||||
}
|
||||
const changedStyle = {
|
||||
...mapStyle,
|
||||
glyphs: mapStyle.glyphs ? mapStyle.glyphs.replace('{key}', accessToken) : mapStyle.glyphs,
|
||||
sources: changedSources
|
||||
}
|
||||
|
||||
return changedStyle
|
||||
}
|
||||
|
||||
function replaceAccessTokens(mapStyle, opts={}) {
|
||||
let changedStyle = mapStyle;
|
||||
|
||||
Object.keys(tokens).forEach((tokenKey) => {
|
||||
changedStyle = replaceSourceAccessToken(changedStyle, tokenKey, opts);
|
||||
})
|
||||
|
||||
if(mapStyle.glyphs && mapStyle.glyphs.match(/\.tileserver\.org/)) {
|
||||
changedStyle = {
|
||||
...changedStyle,
|
||||
glyphs: mapStyle.glyphs ? mapStyle.glyphs.replace('{key}', getAccessToken("openmaptiles", mapStyle, opts)) : mapStyle.glyphs
|
||||
}
|
||||
}
|
||||
|
||||
return changedStyle
|
||||
}
|
||||
|
||||
export default {
|
||||
ensureStyleValidity,
|
||||
emptyStyle,
|
||||
indexOfLayer,
|
||||
generateId,
|
||||
replaceAccessToken,
|
||||
replaceAccessTokens,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user