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