move to onStyleChanged

This commit is contained in:
Birk Skyum
2025-01-22 11:21:57 +01:00
parent c5fa544d68
commit 0b194f8ba4

View File

@@ -364,24 +364,6 @@ export default class App extends React.Component<any, AppState> {
}
}
// 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<any, AppState> {
...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) || [];