Compare commits

...

7 Commits

Author SHA1 Message Date
orangemug
b966fae926 1.5.0 2018-09-10 13:18:21 +01:00
orangemug
f1ddf4e57e 1.5.0-beta3 2018-09-03 21:17:50 +01:00
Orange Mug
64e65dc7d3 Merge pull request #377 from orangemug/fix/glyphs-for-tilehosting
Updated regex to tilehosting.com
2018-09-03 21:15:01 +01:00
orangemug
1e07a88aed Updated regex to tilehosting.com, partial revert of #367 2018-09-03 21:02:38 +01:00
orangemug
6e49cc65a9 1.5.0-beta2 2018-09-03 20:37:16 +01:00
Orange Mug
06d579118a Merge pull request #367 from loicgasser/bugfix/default-token
Fix glyph access key for openmaptiles
2018-09-03 20:34:01 +01:00
Loïc Gasser
088127a9a5 Fix glyph access key for openmaptiles 2018-08-27 16:18:43 -04:00
3 changed files with 16 additions and 17 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "maputnik",
"version": "1.5.0-beta",
"version": "1.5.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "maputnik",
"version": "1.5.0-beta",
"version": "1.5.0",
"description": "A MapboxGL visual style editor",
"main": "''",
"scripts": {

View File

@@ -54,27 +54,27 @@ function indexOfLayer(layers, layerId) {
return null
}
function getAccessToken(key, mapStyle, opts) {
if(key === "thunderforest_transport" || key === "thunderforest_outdoors") {
key = "thunderforest";
function getAccessToken(sourceName, mapStyle, opts) {
if(sourceName === "thunderforest_transport" || sourceName === "thunderforest_outdoors") {
sourceName = "thunderforest"
}
const metadata = mapStyle.metadata || {}
let accessToken = metadata['maputnik:'+key+'_access_token'];
let accessToken = metadata[`maputnik:${sourceName}_access_token`]
if(opts.allowFallback && !accessToken) {
accessToken = tokens[key];
accessToken = tokens[sourceName]
}
return accessToken;
}
function replaceSourceAccessToken(mapStyle, key, opts={}) {
const source = mapStyle.sources[key]
function replaceSourceAccessToken(mapStyle, sourceName, opts={}) {
const source = mapStyle.sources[sourceName]
if(!source) return mapStyle
if(!source.hasOwnProperty("url")) return mapStyle
const accessToken = getAccessToken(key, mapStyle, opts)
const accessToken = getAccessToken(sourceName, mapStyle, opts)
if(!accessToken) {
// Early exit.
@@ -83,7 +83,7 @@ function replaceSourceAccessToken(mapStyle, key, opts={}) {
const changedSources = {
...mapStyle.sources,
[key]: {
[sourceName]: {
...source,
url: source.url.replace('{key}', accessToken)
}
@@ -92,21 +92,20 @@ function replaceSourceAccessToken(mapStyle, key, opts={}) {
...mapStyle,
sources: changedSources
}
return changedStyle
}
function replaceAccessTokens(mapStyle, opts={}) {
let changedStyle = mapStyle;
let changedStyle = mapStyle
Object.keys(mapStyle.sources).forEach((tokenKey) => {
changedStyle = replaceSourceAccessToken(changedStyle, tokenKey, opts);
Object.keys(mapStyle.sources).forEach((sourceName) => {
changedStyle = replaceSourceAccessToken(changedStyle, sourceName, opts);
})
if(mapStyle.glyphs && mapStyle.glyphs.match(/\.tileserver\.org/)) {
if (mapStyle.glyphs && mapStyle.glyphs.match(/\.tilehosting\.com/)) {
changedStyle = {
...changedStyle,
glyphs: mapStyle.glyphs ? mapStyle.glyphs.replace('{key}', getAccessToken("openmaptiles", mapStyle, opts)) : mapStyle.glyphs
glyphs: mapStyle.glyphs.replace('{key}', getAccessToken("openmaptiles", mapStyle, opts))
}
}