Hide background sources from the list if they're blocked (close #7905)

This commit is contained in:
Quincy Morgan
2020-09-03 12:30:59 -04:00
parent 15078bd39c
commit a72a2bb860
5 changed files with 30 additions and 21 deletions

View File

@@ -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`

View File

@@ -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;

View File

@@ -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;
},

View File

@@ -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;

View File

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