Skip to content

Commit ffce5cf

Browse files
committed
move to onStyleChanged
1 parent 5f12c52 commit ffce5cf

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/components/App.tsx

+16-18
Original file line numberDiff line numberDiff line change
@@ -363,41 +363,39 @@ export default class App extends React.Component<any, AppState> {
363363
}
364364
}
365365

366+
this.onStyleChanged(changedStyle)
367+
}
368+
369+
onStyleChanged = (newStyle: StyleSpecification & {id: string}, opts: OnStyleChangedOpts={}) => {
370+
opts = {
371+
save: true,
372+
addRevision: true,
373+
initialLoad: false,
374+
...opts,
375+
};
366376

367377
// For the style object, find the urls that has "{key}" and insert the correct API keys
368378
// Without this, going from e.g. MapTiler to OpenLayers and back will lose the maptlier key.
369379

370-
if (changedStyle.glyphs && typeof changedStyle.glyphs === 'string') {
371-
changedStyle.glyphs = setFetchAccessToken(changedStyle.glyphs, changedStyle);
380+
if (newStyle.glyphs && typeof newStyle.glyphs === 'string') {
381+
newStyle.glyphs = setFetchAccessToken(newStyle.glyphs, newStyle);
372382
}
373383

374-
if (changedStyle.sprite && typeof changedStyle.sprite === 'string') {
375-
changedStyle.sprite = setFetchAccessToken(changedStyle.sprite, changedStyle);
384+
if (newStyle.sprite && typeof newStyle.sprite === 'string') {
385+
newStyle.sprite = setFetchAccessToken(newStyle.sprite, newStyle);
376386
}
377387

378-
for (const [_sourceId, source] of Object.entries(changedStyle.sources)) {
388+
for (const [_sourceId, source] of Object.entries(newStyle.sources)) {
379389
if (source && 'url' in source && typeof source.url === 'string') {
380-
source.url = setFetchAccessToken(source.url, changedStyle);
390+
source.url = setFetchAccessToken(source.url, newStyle);
381391
}
382392
}
383393

384-
this.onStyleChanged(changedStyle)
385-
}
386-
387-
onStyleChanged = (newStyle: StyleSpecification & {id: string}, opts: OnStyleChangedOpts={}) => {
388-
opts = {
389-
save: true,
390-
addRevision: true,
391-
initialLoad: false,
392-
...opts,
393-
};
394394

395395
if (opts.initialLoad) {
396396
this.getInitialStateFromUrl(newStyle);
397397
}
398398

399-
400-
401399
const errors: ValidationError[] = validateStyleMin(newStyle) || [];
402400

403401
// The validate function doesn't give us errors for duplicate error with

0 commit comments

Comments
 (0)