Don't list non-global imagery sources at low zooms (close #7062)

Always show the currently selected background in the list (close #7061)
This commit is contained in:
Quincy Morgan
2019-11-22 12:14:20 -05:00
parent 0ce99bc8fd
commit b5a5dfc34a
2 changed files with 15 additions and 3 deletions

View File

@@ -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];
});
};

View File

@@ -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')