Skip to content

Commit

Permalink
apply "is background valid" on "last used" instead of "requested" layer
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrasd committed Jul 15, 2022
1 parent ce67f53 commit eee346e
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions modules/renderer/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,43 +454,36 @@ export function rendererBackground(context) {
}

const hash = utilStringQs(window.location.hash);
const requested = hash.background || hash.layer;
const requestedBackground = hash.background || hash.layer;
const lastUsedBackground = prefs('background-last-used');
let extent = parseMapParams(hash.map);

return _loadPromise = ensureImageryIndex()
.then(imageryIndex => {
const validBackgrounds = background.sources(extent);
const validBackgrounds = background.sources(extent).filter(d => d.id !== 'none' && d.id !== 'custom');
const first = validBackgrounds.length && validBackgrounds[0];
const isRequestedValid = !!validBackgrounds.find(d => d.id && d.id === requested);
const isLastUsedValid = !!validBackgrounds.find(d => d.id && d.id === lastUsedBackground);

let best;
if (!isRequestedValid || (!requested && extent)) {
if (!requestedBackground && extent) {
best = validBackgrounds.find(s => s.best());
}

// Decide which background layer to display
if (requested && requested.indexOf('custom:') === 0) {
const template = requested.replace(/^custom:/, '');
if (requestedBackground && requestedBackground.indexOf('custom:') === 0) {
const template = requestedBackground.replace(/^custom:/, '');
const custom = background.findSource('custom');
background.baseLayerSource(custom.template(template));
prefs('background-custom-template', template);
} else {
const defaultSource = (
background.baseLayerSource(
background.findSource(requestedBackground) ||
best ||
isLastUsedValid && background.findSource(lastUsedBackground) ||
background.findSource('Bing') ||
first ||
background.findSource('none')
);

if (!isRequestedValid) {
background.baseLayerSource(best || defaultSource);
} else {
background.baseLayerSource(
background.findSource(requested) ||
best ||
background.findSource(prefs('background-last-used')) ||
defaultSource
);
}
}

const locator = imageryIndex.backgrounds.find(d => d.overlay && d.default);
Expand Down

0 comments on commit eee346e

Please sign in to comment.