diff --git a/src/components/App.tsx b/src/components/App.tsx index 2e0586bf..fcee5f93 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -364,24 +364,6 @@ export default class App extends React.Component { } } - - // For the style object, find the urls that has "{key}" and insert the correct API keys - // Without this, going from e.g. MapTiler to OpenLayers and back will lose the maptlier key. - - if (changedStyle.glyphs && typeof changedStyle.glyphs === 'string') { - changedStyle.glyphs = setFetchAccessToken(changedStyle.glyphs, changedStyle); - } - - if (changedStyle.sprite && typeof changedStyle.sprite === 'string') { - changedStyle.sprite = setFetchAccessToken(changedStyle.sprite, changedStyle); - } - - for (const [_sourceId, source] of Object.entries(changedStyle.sources)) { - if (source && 'url' in source && typeof source.url === 'string') { - source.url = setFetchAccessToken(source.url, changedStyle); - } - } - this.onStyleChanged(changedStyle) } @@ -393,11 +375,27 @@ export default class App extends React.Component { ...opts, }; - if (opts.initialLoad) { - this.getInitialStateFromUrl(newStyle); + // For the style object, find the urls that has "{key}" and insert the correct API keys + // Without this, going from e.g. MapTiler to OpenLayers and back will lose the maptlier key. + + if (newStyle.glyphs && typeof newStyle.glyphs === 'string') { + newStyle.glyphs = setFetchAccessToken(newStyle.glyphs, newStyle); + } + + if (newStyle.sprite && typeof newStyle.sprite === 'string') { + newStyle.sprite = setFetchAccessToken(newStyle.sprite, newStyle); + } + + for (const [_sourceId, source] of Object.entries(newStyle.sources)) { + if (source && 'url' in source && typeof source.url === 'string') { + source.url = setFetchAccessToken(source.url, newStyle); + } } + if (opts.initialLoad) { + this.getInitialStateFromUrl(newStyle); + } const errors: ValidationError[] = validateStyleMin(newStyle) || [];