mirror of
https://github.com/maputnik/editor.git
synced 2025-12-07 06:40:00 +00:00
Compare commits
7 Commits
v1.5.0-bet
...
v1.5.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b966fae926 | ||
|
|
f1ddf4e57e | ||
|
|
64e65dc7d3 | ||
|
|
1e07a88aed | ||
|
|
6e49cc65a9 | ||
|
|
06d579118a | ||
|
|
088127a9a5 |
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "maputnik",
|
"name": "maputnik",
|
||||||
"version": "1.5.0-beta",
|
"version": "1.5.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "maputnik",
|
"name": "maputnik",
|
||||||
"version": "1.5.0-beta",
|
"version": "1.5.0",
|
||||||
"description": "A MapboxGL visual style editor",
|
"description": "A MapboxGL visual style editor",
|
||||||
"main": "''",
|
"main": "''",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -54,27 +54,27 @@ function indexOfLayer(layers, layerId) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAccessToken(key, mapStyle, opts) {
|
function getAccessToken(sourceName, mapStyle, opts) {
|
||||||
if(key === "thunderforest_transport" || key === "thunderforest_outdoors") {
|
if(sourceName === "thunderforest_transport" || sourceName === "thunderforest_outdoors") {
|
||||||
key = "thunderforest";
|
sourceName = "thunderforest"
|
||||||
}
|
}
|
||||||
|
|
||||||
const metadata = mapStyle.metadata || {}
|
const metadata = mapStyle.metadata || {}
|
||||||
let accessToken = metadata['maputnik:'+key+'_access_token'];
|
let accessToken = metadata[`maputnik:${sourceName}_access_token`]
|
||||||
|
|
||||||
if(opts.allowFallback && !accessToken) {
|
if(opts.allowFallback && !accessToken) {
|
||||||
accessToken = tokens[key];
|
accessToken = tokens[sourceName]
|
||||||
}
|
}
|
||||||
|
|
||||||
return accessToken;
|
return accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceSourceAccessToken(mapStyle, key, opts={}) {
|
function replaceSourceAccessToken(mapStyle, sourceName, opts={}) {
|
||||||
const source = mapStyle.sources[key]
|
const source = mapStyle.sources[sourceName]
|
||||||
if(!source) return mapStyle
|
if(!source) return mapStyle
|
||||||
if(!source.hasOwnProperty("url")) return mapStyle
|
if(!source.hasOwnProperty("url")) return mapStyle
|
||||||
|
|
||||||
const accessToken = getAccessToken(key, mapStyle, opts)
|
const accessToken = getAccessToken(sourceName, mapStyle, opts)
|
||||||
|
|
||||||
if(!accessToken) {
|
if(!accessToken) {
|
||||||
// Early exit.
|
// Early exit.
|
||||||
@@ -83,7 +83,7 @@ function replaceSourceAccessToken(mapStyle, key, opts={}) {
|
|||||||
|
|
||||||
const changedSources = {
|
const changedSources = {
|
||||||
...mapStyle.sources,
|
...mapStyle.sources,
|
||||||
[key]: {
|
[sourceName]: {
|
||||||
...source,
|
...source,
|
||||||
url: source.url.replace('{key}', accessToken)
|
url: source.url.replace('{key}', accessToken)
|
||||||
}
|
}
|
||||||
@@ -92,21 +92,20 @@ function replaceSourceAccessToken(mapStyle, key, opts={}) {
|
|||||||
...mapStyle,
|
...mapStyle,
|
||||||
sources: changedSources
|
sources: changedSources
|
||||||
}
|
}
|
||||||
|
|
||||||
return changedStyle
|
return changedStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceAccessTokens(mapStyle, opts={}) {
|
function replaceAccessTokens(mapStyle, opts={}) {
|
||||||
let changedStyle = mapStyle;
|
let changedStyle = mapStyle
|
||||||
|
|
||||||
Object.keys(mapStyle.sources).forEach((tokenKey) => {
|
Object.keys(mapStyle.sources).forEach((sourceName) => {
|
||||||
changedStyle = replaceSourceAccessToken(changedStyle, tokenKey, opts);
|
changedStyle = replaceSourceAccessToken(changedStyle, sourceName, opts);
|
||||||
})
|
})
|
||||||
|
|
||||||
if(mapStyle.glyphs && mapStyle.glyphs.match(/\.tileserver\.org/)) {
|
if (mapStyle.glyphs && mapStyle.glyphs.match(/\.tilehosting\.com/)) {
|
||||||
changedStyle = {
|
changedStyle = {
|
||||||
...changedStyle,
|
...changedStyle,
|
||||||
glyphs: mapStyle.glyphs ? mapStyle.glyphs.replace('{key}', getAccessToken("openmaptiles", mapStyle, opts)) : mapStyle.glyphs
|
glyphs: mapStyle.glyphs.replace('{key}', getAccessToken("openmaptiles", mapStyle, opts))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user