From a72a2bb8604ee8e7e6405eaa3c9aec0e3d75aedc Mon Sep 17 00:00:00 2001 From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com> Date: Thu, 3 Sep 2020 12:30:59 -0400 Subject: [PATCH] Hide background sources from the list if they're blocked (close #7905) --- data/presets/README.md | 4 ++-- modules/renderer/background.js | 19 ++++++++++++++----- modules/services/osm.js | 12 ++++++------ modules/svg/data.js | 8 ++++---- test/spec/services/osm.js | 8 ++++---- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/data/presets/README.md b/data/presets/README.md index ee2e9cd30..8ca30aae6 100644 --- a/data/presets/README.md +++ b/data/presets/README.md @@ -197,7 +197,7 @@ By default, presets are available everywhere. ##### `notCountryCodes` -An array of two-letter, lowercase [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes. Similar to `countryCodes` except a blacklist instead of a whitelist. +An array of two-letter, lowercase [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes. Similar to `countryCodes` except a blocklist. ##### `replacement` @@ -423,7 +423,7 @@ By default, fields are available everywhere. ##### `notCountryCodes` -An array of two-letter, lowercase [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes. Similar to `countryCodes` except a blacklist instead of a whitelist. +An array of two-letter, lowercase [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes. Similar to `countryCodes` except a blocklist. ##### `urlFormat` diff --git a/modules/renderer/background.js b/modules/renderer/background.js index bfffd7b43..a4ff533d7 100644 --- a/modules/renderer/background.js +++ b/modules/renderer/background.js @@ -281,9 +281,18 @@ export function rendererBackground(context) { const currSource = baseLayer.source(); + const osm = context.connection(); + const blocklists = osm && osm.imageryBlocklists(); + const isBlocked = blocklists && function(source) { + return blocklists.some(function(blocklist) { + return new RegExp(blocklist).test(source.template()); + }); + }; + return _imageryIndex.backgrounds.filter(source => { - if (!source.polygon) return true; // always include imagery with worldwide coverage if (includeCurrent && currSource === source) return true; // optionally include the current imagery + if (isBlocked && isBlocked(source)) return false; // even bundled sources may be blocked - #7905 + if (!source.polygon) return true; // always include imagery with worldwide coverage if (zoom && zoom < 6) return false; // optionally exclude local imagery at low zooms return visible[source.id]; // include imagery visible in given extent }); @@ -300,19 +309,19 @@ export function rendererBackground(context) { background.baseLayerSource = function(d) { if (!arguments.length) return baseLayer.source(); - // test source against OSM imagery blacklists.. + // test source against OSM imagery blocklists.. const osm = context.connection(); if (!osm) return background; - const blacklists = osm.imageryBlacklists(); + const blocklists = osm.imageryBlocklists(); const template = d.template(); let fail = false; let tested = 0; let regex; - for (let i = 0; i < blacklists.length; i++) { + for (let i = 0; i < blocklists.length; i++) { try { - regex = new RegExp(blacklists[i]); + regex = new RegExp(blocklists[i]); fail = regex.test(template); tested++; if (fail) break; diff --git a/modules/services/osm.js b/modules/services/osm.js index 1b78df3ce..8fa670cbd 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -23,8 +23,8 @@ var oauth = osmAuth({ loading: authLoading, done: authDone }); - -var _blacklists = ['.*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*']; +// hardcode default block of Google Maps +var _imageryBlocklists = ['.*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*']; var _tileCache = { toLoad: {}, loaded: {}, inflight: {}, seen: {}, rtree: new RBush() }; var _noteCache = { toLoad: {}, loaded: {}, inflight: {}, inflightPost: {}, note: {}, closed: {}, rtree: new RBush() }; var _userCache = { toLoad: {}, user: {} }; @@ -919,7 +919,7 @@ export default { return callback(err, null); } - // update blacklists + // update blocklists var elements = xml.getElementsByTagName('blacklist'); var regexes = []; for (var i = 0; i < elements.length; i++) { @@ -929,7 +929,7 @@ export default { } } if (regexes.length) { - _blacklists = regexes; + _imageryBlocklists = regexes; } if (_rateLimitError) { @@ -1321,8 +1321,8 @@ export default { }, - imageryBlacklists: function() { - return _blacklists; + imageryBlocklists: function() { + return _imageryBlocklists; }, diff --git a/modules/svg/data.js b/modules/svg/data.js index 94abf00d5..f16f8c803 100644 --- a/modules/svg/data.js +++ b/modules/svg/data.js @@ -379,17 +379,17 @@ export function svgData(projection, context, dispatch) { drawData.template = function(val, src) { if (!arguments.length) return _template; - // test source against OSM imagery blacklists.. + // test source against OSM imagery blocklists.. var osm = context.connection(); if (osm) { - var blacklists = osm.imageryBlacklists(); + var blocklists = osm.imageryBlocklists(); var fail = false; var tested = 0; var regex; - for (var i = 0; i < blacklists.length; i++) { + for (var i = 0; i < blocklists.length; i++) { try { - regex = new RegExp(blacklists[i]); + regex = new RegExp(blocklists[i]); fail = regex.test(val); tested++; if (fail) break; diff --git a/test/spec/services/osm.js b/test/spec/services/osm.js index dd995942a..8e73b66e2 100644 --- a/test/spec/services/osm.js +++ b/test/spec/services/osm.js @@ -728,11 +728,11 @@ describe('iD.serviceOsm', function () { }); }); - describe('#imageryBlacklists', function() { - it('updates imagery blacklists', function(done) { + describe('#imageryBlocklists', function() { + it('updates imagery blocklists', function(done) { connection.status(function() { - var blacklists = connection.imageryBlacklists(); - expect(blacklists).to.deep.equal(['\.foo\.com','\.bar\.org']); + var blocklists = connection.imageryBlocklists(); + expect(blocklists).to.deep.equal(['\.foo\.com','\.bar\.org']); done(); });