diff --git a/modules/core/context.js b/modules/core/context.js index a6b9249be..e2f49a15f 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -381,7 +381,6 @@ export function coreContext() { ui = uiInit(context); connection = services.osm; - background = rendererBackground(context); features = rendererFeatures(context); presets = presetIndex(); @@ -396,16 +395,16 @@ export function coreContext() { context.zoomOutFurther = map.zoomOutFurther; context.redrawEnable = map.redrawEnable; - background.init(); - presets.init(); - areaKeys = presets.areaKeys(); - _.each(services, function(service) { if (service && typeof service.init === 'function') { service.init(context); } }); + background.init(); + presets.init(); + areaKeys = presets.areaKeys(); + return utilRebind(context, dispatch, 'on'); } diff --git a/modules/renderer/background.js b/modules/renderer/background.js index 50f58a0f4..46284acad 100644 --- a/modules/renderer/background.js +++ b/modules/renderer/background.js @@ -12,8 +12,6 @@ export function rendererBackground(context) { var dispatch = d3.dispatch('change'), baseLayer = rendererTileLayer(context).projection(context.projection), overlayLayers = [], - defaultBlacklist = '.*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*', - blacklists = [defaultBlacklist], backgroundSources; @@ -130,10 +128,8 @@ export function rendererBackground(context) { background.baseLayerSource = function(d) { if (!arguments.length) return baseLayer.source(); - // // test source against OSM imagery blacklists.. - // context.connection().imageryBlacklists(function(err, val) { - // if (!err) blacklists = val; - // }); + // test source against OSM imagery blacklists.. + var blacklists = context.connection().imageryBlacklists(); var fail = false, tested = 0, @@ -152,7 +148,7 @@ export function rendererBackground(context) { // ensure at least one test was run. if (!tested) { - regex = new RegExp(defaultBlacklist); + regex = new RegExp('.*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*'); fail = regex.test(d.template); } diff --git a/modules/services/osm.js b/modules/services/osm.js index aaa2162ad..defbf6ec1 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -13,6 +13,7 @@ var dispatch = d3.dispatch('authLoading', 'authDone', 'change', 'loading', 'load useHttps = window.location.protocol === 'https:', protocol = useHttps ? 'https:' : 'http:', urlroot = protocol + '//www.openstreetmap.org', + blacklists = ['.*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*'], inflight = {}, loadedTiles = {}, tileZoom = 16, @@ -25,7 +26,6 @@ var dispatch = d3.dispatch('authLoading', 'authDone', 'change', 'loading', 'load }), rateLimitError, userDetails, - capabilities, off; @@ -162,7 +162,6 @@ export default { reset: function() { userDetails = undefined; rateLimitError = undefined; - capabilities = undefined; _.forEach(inflight, abortRequest); loadedTiles = {}; inflight = {}; @@ -431,15 +430,26 @@ export default { }, - // `status` will always request the `api/capabilities` resource.. status: function(callback) { function done(xml) { - capabilities = xml; + // update blacklists + var elements = xml.getElementsByTagName('blacklist'), + regexes = []; + for (var i = 0; i < elements.length; i++) { + var regex = elements[i].getAttribute('regex'); // needs unencode? + if (regex) { + regexes.push(regex); + } + } + if (regexes.length) { + blacklists = regexes; + } + if (rateLimitError) { callback(rateLimitError, 'rateLimited'); } else { - var apiStatus = capabilities.getElementsByTagName('status'), + var apiStatus = xml.getElementsByTagName('status'), val = apiStatus[0].getAttribute('api'); callback(undefined, val); @@ -452,30 +462,8 @@ export default { }, - // `imageryBlacklists` will reuse the previous `api/capabilities` result, if available.. - imageryBlacklists: function(callback) { - function done(xml) { - capabilities = xml; - - var elements = capabilities.getElementsByTagName('blacklist'), - blacklists = []; - for (var i = 0; i < elements.length; i++) { - var regex = elements[i].getAttribute('regex'); // needs unencode? - if (regex) { - blacklists.push(regex); - } - } - - callback(undefined, blacklists); - } - - if (capabilities) { - done(capabilities); - } else { - d3.xml(urlroot + '/api/capabilities').get() - .on('load', done) - .on('error', callback); - } + imageryBlacklists: function() { + return blacklists; }, diff --git a/modules/ui/background.js b/modules/ui/background.js index e03309588..f3389a616 100644 --- a/modules/ui/background.js +++ b/modules/ui/background.js @@ -109,14 +109,11 @@ export function uiBackground(context) { function editCustom() { d3.event.preventDefault(); var template = window.prompt(t('background.custom_prompt'), customTemplate); - if (!template || - template.indexOf('google.com') !== -1 || - template.indexOf('googleapis.com') !== -1 || - template.indexOf('google.ru') !== -1) { + if (template) { + setCustom(template); + } else { selectLayer(); - return; } - setCustom(template); } diff --git a/test/spec/services/osm.js b/test/spec/services/osm.js index bd5d75fb9..b75c23378 100644 --- a/test/spec/services/osm.js +++ b/test/spec/services/osm.js @@ -458,13 +458,15 @@ describe('iD.serviceOsm', function () { '' + '' + '' + - '' + + '' + + '' + + '' + + '' + ''; beforeEach(function() { server = sinon.fakeServer.create(); - // connection.reset(); }); afterEach(function() { @@ -485,9 +487,10 @@ describe('iD.serviceOsm', function () { }); describe('#imageryBlacklists', function() { - it('gets imagery blacklists', function(done) { - connection.imageryBlacklists(function(err, val) { - expect(val).to.eql(['.*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*']); + it('updates imagery blacklists', function(done) { + connection.status(function() { + var blacklists = connection.imageryBlacklists(); + expect(blacklists).to.deep.equal(['\.foo\.com','\.bar\.org']); done(); });