From 1313e4b21ec008a3a2eaa83d6e5d30712acb0465 Mon Sep 17 00:00:00 2001 From: Renan Date: Fri, 15 Apr 2022 00:38:33 -0300 Subject: [PATCH 1/3] Fix iD using invalid user selected imagery --- CHANGELOG.md | 8 ++++++++ modules/renderer/background.js | 24 +++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aa9a2165..066e0c957 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ _Breaking developer changes, which may affect downstream projects or sites that # Unreleased #### :newspaper: News +<<<<<<< HEAD #### :tada: New Features * Consider lifecycle prefixes when deciding whether features should be rendered as a line or an area ([#8881], thanks [@k-yle]) #### :white_check_mark: Validation @@ -102,6 +103,9 @@ _Breaking developer changes, which may affect downstream projects or sites that ##### 2022-Jun-03 #### :newspaper: News +======= + +>>>>>>> Fix iD using invalid user selected imagery * Drop legacy support for Internet Explorer 11 ([#8811]) * Use OAuth2 for authentication with OSM API ([#9134], thanks [@bhousel] and [@dakotabenjamin]) #### :white_check_mark: Validation @@ -111,8 +115,12 @@ _Breaking developer changes, which may affect downstream projects or sites that * Fix KeepRight warnings showing up as "Unknown" issues ([#8925]) * Fix W keyboard shortcut not working on MacOS in certain system languages / keyboard layouts (e.g. Spanish) ([#8905]) * Render closed ways tagged as `public_transport=platform`, `waterway=dam` or `highway=elevator` as areas ([#8985]) +<<<<<<< HEAD * Fix a bug which caused validations to not take effect in certain situations ([#9021], thanks [@mbrzakovic]) * Properly escape currently logged-in user's user name ([#9097], thanks [@jleedev]) +======= +* Fix iD using invalid user selected imagery ([#8732]) +>>>>>>> Fix iD using invalid user selected imagery #### :rocket: Presets * Optimize order of values in dropdowns of `access` fields ([#8945]) * Use value of `vehicle` tag as placeholder value of `access` fields for `motor_vehicle` and `bicycle` diff --git a/modules/renderer/background.js b/modules/renderer/background.js index b293c6e5f..09b267b8a 100644 --- a/modules/renderer/background.js +++ b/modules/renderer/background.js @@ -459,11 +459,13 @@ export function rendererBackground(context) { return _loadPromise = ensureImageryIndex() .then(imageryIndex => { - const first = imageryIndex.backgrounds.length && imageryIndex.backgrounds[0]; + const validBackgrounds = background.sources(extent); + const first = validBackgrounds.length && validBackgrounds[0]; + const isRequestedValid = !!validBackgrounds.find(d => d.id && d.id === requested); let best; - if (!requested && extent) { - best = background.sources(extent).find(s => s.best()); + if (!isRequestedValid || (!requested && extent)) { + best = validBackgrounds.find(s => s.best()); } // Decide which background layer to display @@ -473,14 +475,22 @@ export function rendererBackground(context) { background.baseLayerSource(custom.template(template)); prefs('background-custom-template', template); } else { - background.baseLayerSource( - background.findSource(requested) || - best || - background.findSource(prefs('background-last-used')) || + const defaultSource = ( 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); From ce67f5390be5dad2ffa5d97e53082f45acf69e5d Mon Sep 17 00:00:00 2001 From: Renan Cleyson Date: Fri, 15 Apr 2022 16:52:04 -0300 Subject: [PATCH 2/3] Fixes CHANGELOG.md --- CHANGELOG.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 066e0c957..0158c8487 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,6 @@ _Breaking developer changes, which may affect downstream projects or sites that # Unreleased #### :newspaper: News -<<<<<<< HEAD #### :tada: New Features * Consider lifecycle prefixes when deciding whether features should be rendered as a line or an area ([#8881], thanks [@k-yle]) #### :white_check_mark: Validation @@ -57,6 +56,7 @@ _Breaking developer changes, which may affect downstream projects or sites that * Fix localizable labels in multiCombo fields ("chips") being rendered multiple times ([#9169]) * Fix missing styling when rendering of proposed footway/cycleway/path bridges ([#9172], thanks [@k-yle]) * Fix some boundary lines (and preset) not hidden by the map features filter ([#9171], thanks [@k-yle]) +* Fix iD using invalid user selected imagery ([#8732], thanks [@renancleyson-dev]) #### :rocket: Presets * Disable taginfo suggestions for the `via` field ([#9140], thanks [@k-yle]) * Treat `surface=chipseal` as a paved surface ([#9139], thanks [@k-yle]) @@ -69,6 +69,7 @@ _Breaking developer changes, which may affect downstream projects or sites that [#8419]: https://github.com/openstreetmap/iD/issues/8419 +[#8732]: https://github.com/openstreetmap/iD/issues/8732 [#8881]: https://github.com/openstreetmap/iD/issues/8881 [#8975]: https://github.com/openstreetmap/iD/pull/8975 [#9018]: https://github.com/openstreetmap/iD/issues/9018 @@ -88,6 +89,7 @@ _Breaking developer changes, which may affect downstream projects or sites that [@JackNUMBER]: https://github.com/JackNUMBER [@aaditya0000]: https://github.com/aaditya0000 [@paulklie]: https://github.com/paulklie +[@renancleyson-dev]: https://github.com/renancleyson-dev # 2.21.1 @@ -103,9 +105,6 @@ _Breaking developer changes, which may affect downstream projects or sites that ##### 2022-Jun-03 #### :newspaper: News -======= - ->>>>>>> Fix iD using invalid user selected imagery * Drop legacy support for Internet Explorer 11 ([#8811]) * Use OAuth2 for authentication with OSM API ([#9134], thanks [@bhousel] and [@dakotabenjamin]) #### :white_check_mark: Validation @@ -115,12 +114,8 @@ _Breaking developer changes, which may affect downstream projects or sites that * Fix KeepRight warnings showing up as "Unknown" issues ([#8925]) * Fix W keyboard shortcut not working on MacOS in certain system languages / keyboard layouts (e.g. Spanish) ([#8905]) * Render closed ways tagged as `public_transport=platform`, `waterway=dam` or `highway=elevator` as areas ([#8985]) -<<<<<<< HEAD * Fix a bug which caused validations to not take effect in certain situations ([#9021], thanks [@mbrzakovic]) * Properly escape currently logged-in user's user name ([#9097], thanks [@jleedev]) -======= -* Fix iD using invalid user selected imagery ([#8732]) ->>>>>>> Fix iD using invalid user selected imagery #### :rocket: Presets * Optimize order of values in dropdowns of `access` fields ([#8945]) * Use value of `vehicle` tag as placeholder value of `access` fields for `motor_vehicle` and `bicycle` From eee346e7dc2b78eebedc5f7c89421371205380cc Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Fri, 15 Jul 2022 18:51:05 +0200 Subject: [PATCH 3/3] apply "is background valid" on "last used" instead of "requested" layer --- modules/renderer/background.js | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/modules/renderer/background.js b/modules/renderer/background.js index 09b267b8a..2b754c7bf 100644 --- a/modules/renderer/background.js +++ b/modules/renderer/background.js @@ -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);