Merge pull request #476 from pathmapper/fix_issue_404

Use access token for fetchSources
This commit is contained in:
Orange Mug 2019-01-04 14:34:26 +00:00 committed by GitHub
commit 98ded98583
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View file

@ -49,6 +49,25 @@ function normalizeSourceURL (url, apiToken="") {
}
}
function setFetchAccessToken(url, mapStyle) {
const matchesTilehosting = url.match(/\.tilehosting\.com/);
const matchesThunderforest = url.match(/\.thunderforest\.com/);
if (matchesTilehosting) {
const accessToken = style.getAccessToken("openmaptiles", mapStyle, {allowFallback: true})
if (accessToken) {
return url.replace('{key}', accessToken)
}
}
else if (matchesThunderforest) {
const accessToken = style.getAccessToken("thunderforest", mapStyle, {allowFallback: true})
if (accessToken) {
return url.replace('{key}', accessToken)
}
}
else {
return url;
}
}
function updateRootSpec(spec, fieldName, newValues) {
return {
@ -398,6 +417,12 @@ export default class App extends React.Component {
console.warn("Failed to normalizeSourceURL: ", err);
}
try {
url = setFetchAccessToken(url, this.state.mapStyle)
} catch(err) {
console.warn("Failed to setFetchAccessToken: ", err);
}
fetch(url, {
mode: 'cors',
})

View file

@ -119,5 +119,6 @@ export default {
emptyStyle,
indexOfLayer,
generateId,
getAccessToken,
replaceAccessTokens,
}