Skip to content

Commit

Permalink
move to onStyleChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
birkskyum committed Jan 22, 2025
1 parent 5f12c52 commit ffce5cf
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,41 +363,39 @@ export default class App extends React.Component<any, AppState> {
}
}

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
Expand Down

0 comments on commit ffce5cf

Please sign in to comment.