From b5a5dfc34a2befef0cc2f09fce12d833c4bba901 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Fri, 22 Nov 2019 12:14:20 -0500 Subject: [PATCH] Don't list non-global imagery sources at low zooms (close #7062) Always show the currently selected background in the list (close #7061) --- modules/renderer/background.js | 16 ++++++++++++++-- modules/ui/background.js | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/renderer/background.js b/modules/renderer/background.js index 0bbaf5a25..ce7416e7b 100644 --- a/modules/renderer/background.js +++ b/modules/renderer/background.js @@ -212,15 +212,27 @@ export function rendererBackground(context) { }; - background.sources = function(extent) { + background.sources = function(extent, zoom, alwaysIncludeSelected) { if (!data.imagery || !data.imagery.query) return []; // called before init()? var matchIDs = {}; var matchImagery = data.imagery.query.bbox(extent.rectangle(), true) || []; matchImagery.forEach(function(d) { matchIDs[d.id] = true; }); + var currentSource = baseLayer.source(); + return _backgroundSources.filter(function(source) { - return matchIDs[source.id] || !source.polygon; // no polygon = worldwide + // optionally always include the selected source + if (alwaysIncludeSelected && currentSource === source) return true; + + // always show sources with worldwide coverage + if (!source.polygon) return true; + + // optionally don't include non-worldwide sources at low zooms + if (zoom && zoom < 6) return false; + + // don't include sources outside the extent + return matchIDs[source.id]; }); }; diff --git a/modules/ui/background.js b/modules/ui/background.js index e8ada1956..6a15fb0ff 100644 --- a/modules/ui/background.js +++ b/modules/ui/background.js @@ -121,7 +121,7 @@ export function uiBackground(context) { function drawListItems(layerList, type, change, filter) { var sources = context.background() - .sources(context.map().extent()) + .sources(context.map().extent(), context.map().zoom(), true) .filter(filter); var layerLinks = layerList.selectAll('li')