mirror of
https://github.com/maputnik/editor.git
synced 2026-08-25 22:47:39 +00:00
Refactor based on code review suggestion
This commit is contained in:
+13
-10
@@ -71,20 +71,13 @@ function replaceSourceAccessToken(mapStyle: StyleSpecification, sourceName: stri
|
|||||||
if(!("url" in source) || !source.url) return mapStyle
|
if(!("url" in source) || !source.url) return mapStyle
|
||||||
|
|
||||||
let authSourceName = sourceName
|
let authSourceName = sourceName
|
||||||
let setAccessToken = (url: string) => url.replace('{key}', accessToken)
|
|
||||||
if(sourceName === "thunderforest_transport" || sourceName === "thunderforest_outdoors") {
|
if(sourceName === "thunderforest_transport" || sourceName === "thunderforest_outdoors") {
|
||||||
authSourceName = "thunderforest"
|
authSourceName = "thunderforest"
|
||||||
}
|
}
|
||||||
else if (("url" in source) && source.url?.match(/\.stadiamaps\.com/)) {
|
else if (("url" in source) && source.url?.match(/\.stadiamaps\.com/)) {
|
||||||
// A few weird things here worth commenting on...
|
// The code currently usually assumes openmaptiles == MapTiler,
|
||||||
//
|
// so we need to check the source URL.
|
||||||
// 1. The code currently assumes openmaptiles == MapTiler,
|
|
||||||
// so we need to check the source URL.
|
|
||||||
// 2. Stadia Maps does not always require an API key,
|
|
||||||
// so there is no placeholder in our styles.
|
|
||||||
// We append it at the end during exporting if necessary.
|
|
||||||
authSourceName = "stadia"
|
authSourceName = "stadia"
|
||||||
setAccessToken = (url: string) => `${url}?api_key=${accessToken}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const accessToken = getAccessToken(authSourceName, mapStyle, opts)
|
const accessToken = getAccessToken(authSourceName, mapStyle, opts)
|
||||||
@@ -94,11 +87,21 @@ function replaceSourceAccessToken(mapStyle: StyleSpecification, sourceName: stri
|
|||||||
return mapStyle;
|
return mapStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let sourceUrl: string
|
||||||
|
if (authSourceName == "stadia") {
|
||||||
|
// Stadia Maps does not always require an API key,
|
||||||
|
// so there is no placeholder in our styles.
|
||||||
|
// We append it at the end of the URL when exporting if necessary.
|
||||||
|
sourceUrl = `${source.url}?api_key=${accessToken}`
|
||||||
|
} else {
|
||||||
|
sourceUrl = source.url.replace('{key}', accessToken)
|
||||||
|
}
|
||||||
|
|
||||||
const changedSources = {
|
const changedSources = {
|
||||||
...mapStyle.sources,
|
...mapStyle.sources,
|
||||||
[sourceName]: {
|
[sourceName]: {
|
||||||
...source,
|
...source,
|
||||||
url: setAccessToken(source.url)
|
url: sourceUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const changedStyle = {
|
const changedStyle = {
|
||||||
|
|||||||
Reference in New Issue
Block a user