Add links to tile provider authentication docs (#914)

This probably confused some people in the past, since vector tiles won't
even display an access denied image ;)

Before (no information on access keys and where to get them):

<img width="411" alt="image"
src="https://github.com/user-attachments/assets/8820fb20-bda4-460c-9cc9-8fec5daa480d">

After (add links to providers in info callout + add a field for Stadia
Maps API keys):

<img width="395" alt="image"
src="https://github.com/user-attachments/assets/91ee732c-b3f5-45f8-81a6-8d896a93f644">

---------

Co-authored-by: Harel M <harel.mazor@gmail.com>
Co-authored-by: Joscha <34318751+josxha@users.noreply.github.com>
Co-authored-by: Hugues Tavernier <hugues.tavernier@protonmail.com>
Co-authored-by: Keitaroh Kobayashi <keita@kbys.me>
This commit is contained in:
Ian Wagner
2024-09-25 16:22:39 +09:00
committed by GitHub
parent 0f1000c5b0
commit 25cf61a825
12 changed files with 102 additions and 24 deletions
+13 -3
View File
@@ -4,15 +4,25 @@ const spec = (t: TFunction) => ({
maputnik: {
maptiler_access_token: {
label: t("MapTiler Access Token"),
doc: t("Public access token for MapTiler Cloud.")
doc: t("Public access token for MapTiler Cloud."),
docUrl: "https://docs.maptiler.com/cloud/api/authentication-key/",
docUrlLinkText: t("Learn More")
},
thunderforest_access_token: {
label: t("Thunderforest Access Token"),
doc: t("Public access token for Thunderforest services.")
doc: t("Public access token for Thunderforest services."),
docUrl: "https://www.thunderforest.com/docs/apikeys/",
docUrlLinkText: t("Learn More")
},
stadia_access_token: {
label: t("Stadia Maps API Key"),
doc: t("API key for Stadia Maps."),
docUrl: "https://docs.stadiamaps.com/authentication/",
docUrlLinkText: t("Learn More")
},
style_renderer: {
label: t("Style Renderer"),
doc: t("Choose the default Maputnik renderer for this style."),
doc: t("Choose the default Maputnik renderer for this style.")
},
}
})
+24 -6
View File
@@ -55,10 +55,6 @@ function indexOfLayer(layers: LayerSpecification[], layerId: string) {
}
function getAccessToken(sourceName: string, mapStyle: StyleSpecification, opts: {allowFallback?: boolean}) {
if(sourceName === "thunderforest_transport" || sourceName === "thunderforest_outdoors") {
sourceName = "thunderforest"
}
const metadata = mapStyle.metadata || {} as any;
let accessToken = metadata[`maputnik:${sourceName}_access_token`]
@@ -74,18 +70,38 @@ function replaceSourceAccessToken(mapStyle: StyleSpecification, sourceName: stri
if(!source) return mapStyle
if(!("url" in source) || !source.url) return mapStyle
const accessToken = getAccessToken(sourceName, mapStyle, opts)
let authSourceName = sourceName
if(sourceName === "thunderforest_transport" || sourceName === "thunderforest_outdoors") {
authSourceName = "thunderforest"
}
else if (("url" in source) && source.url?.match(/\.stadiamaps\.com/)) {
// The code currently usually assumes openmaptiles == MapTiler,
// so we need to check the source URL.
authSourceName = "stadia"
}
const accessToken = getAccessToken(authSourceName, mapStyle, opts)
if(!accessToken) {
// Early exit.
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 = {
...mapStyle.sources,
[sourceName]: {
...source,
url: source.url.replace('{key}', accessToken)
url: sourceUrl
}
}
const changedStyle = {
@@ -120,6 +136,8 @@ function stripAccessTokens(mapStyle: StyleSpecification) {
...mapStyle.metadata as any
};
delete changedMetadata['maputnik:openmaptiles_access_token'];
delete changedMetadata['maputnik:thunderforest_access_token'];
delete changedMetadata['maputnik:stadia_access_token'];
return {
...mapStyle,
metadata: changedMetadata