From ffce5cfd62dc993a6bc7be9bc3f600f138a1d03a Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Wed, 22 Jan 2025 11:21:57 +0100 Subject: [PATCH] move to onStyleChanged --- src/components/App.tsx | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 84859de2..a0682fab 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -363,41 +363,39 @@ export default class App extends React.Component { } } + this.onStyleChanged(changedStyle) + } + + onStyleChanged = (newStyle: StyleSpecification & {id: string}, opts: OnStyleChangedOpts={}) => { + opts = { + save: true, + addRevision: true, + initialLoad: false, + ...opts, + }; // 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 (newStyle.glyphs && typeof newStyle.glyphs === 'string') { + newStyle.glyphs = setFetchAccessToken(newStyle.glyphs, newStyle); } - if (changedStyle.sprite && typeof changedStyle.sprite === 'string') { - changedStyle.sprite = setFetchAccessToken(changedStyle.sprite, changedStyle); + if (newStyle.sprite && typeof newStyle.sprite === 'string') { + newStyle.sprite = setFetchAccessToken(newStyle.sprite, newStyle); } - for (const [_sourceId, source] of Object.entries(changedStyle.sources)) { + for (const [_sourceId, source] of Object.entries(newStyle.sources)) { if (source && 'url' in source && typeof source.url === 'string') { - source.url = setFetchAccessToken(source.url, changedStyle); + source.url = setFetchAccessToken(source.url, newStyle); } } - this.onStyleChanged(changedStyle) - } - - onStyleChanged = (newStyle: StyleSpecification & {id: string}, opts: OnStyleChangedOpts={}) => { - opts = { - save: true, - addRevision: true, - initialLoad: false, - ...opts, - }; if (opts.initialLoad) { this.getInitialStateFromUrl(newStyle); } - - const errors: ValidationError[] = validateStyleMin(newStyle) || []; // The validate function doesn't give us errors for duplicate error with