diff --git a/data/update_imagery.js b/data/update_imagery.js index 761b93fa3..225f9c153 100644 --- a/data/update_imagery.js +++ b/data/update_imagery.js @@ -54,7 +54,7 @@ sources.concat(whitelist).forEach(function(source) { var supportedProjection = source.available_projections && supportedWMSProjections.find(function(supportedProjection) { return source.available_projections.some(function(projection) { - return supportedProjection === projection; + return supportedProjection === projection; }) }); if (source.type === 'wms' && supportedProjection === undefined) return; @@ -67,7 +67,7 @@ sources.concat(whitelist).forEach(function(source) { }; if (source.type === 'wms') { - im.projection = supportedProjection; + im.projection = supportedProjection; } var startDate, endDate, isValid; diff --git a/modules/renderer/background_source.js b/modules/renderer/background_source.js index df5de7df1..74d75cd3a 100644 --- a/modules/renderer/background_source.js +++ b/modules/renderer/background_source.js @@ -33,9 +33,15 @@ function vintageRange(vintage) { } function getEPSG3857XY(x, y, z) { + //polyfill for IE11, PhantomJS + var sinh = Math.sinh || function(x) { + var y = Math.exp(x); + return (y - 1 / y) / 2; + }; + var zoomSize = Math.pow(2, z); var lon = x / zoomSize * Math.PI * 2 - Math.PI; - var lat = Math.atan(Math.sinh(Math.PI * (1 - 2 * y / zoomSize))); + var lat = Math.atan(sinh(Math.PI * (1 - 2 * y / zoomSize))); var mercCoords = d3_geoMercatorRaw(lon, lat); return { x: 20037508.34 / Math.PI * mercCoords[0], diff --git a/test/spec/renderer/background_source.js b/test/spec/renderer/background_source.js index 21f64ad92..2828bdf0c 100644 --- a/test/spec/renderer/background_source.js +++ b/test/spec/renderer/background_source.js @@ -1,48 +1,71 @@ -describe('iD.BackgroundSource', function() { +describe('iD.rendererBackgroundSource', function() { it('does not error with blank template', function() { - var source = iD.BackgroundSource({ template: '' }); + var source = iD.rendererBackgroundSource({ template: '' }); expect(source.url([0,1,2])).to.equal(''); }); - it('generates a tile-generating source', function() { - var source = iD.BackgroundSource({ template: '{z}/{x}/{y}' }); + it('supports tms replacement tokens', function() { + var source = iD.rendererBackgroundSource({ + type: 'tms', + template: '{z}/{x}/{y}' + }); expect(source.url([0,1,2])).to.equal('2/0/1'); }); + it('supports wms replacement tokens', function() { + var source = iD.rendererBackgroundSource({ + type: 'wms', + projection: 'EPSG:3857', + template: 'SRS={proj}&FORMAT=image/jpeg&WIDTH={width}&HEIGHT={height}&BBOX={bbox}' + }); + + var result = iD.utilStringQs(source.url([0,1,2])); + expect(result.SRS).to.equal('EPSG:3857'); + expect(result.FORMAT).to.equal('image/jpeg'); + expect(result.WIDTH).to.equal('256'); + expect(result.HEIGHT).to.equal('256'); + + var bbox = result.BBOX.split(','); + expect(+bbox[0]).to.be.closeTo(-20037508.34, 1e-3); + expect(+bbox[1]).to.be.closeTo(0, 1e-3); + expect(+bbox[2]).to.be.closeTo(-10018754.17, 1e-3); + expect(+bbox[3]).to.be.closeTo(10018754.17, 1e-3); + }); + it('supports subdomains', function() { - var source = iD.BackgroundSource({ template: '{switch:a,b}/{z}/{x}/{y}'}); + var source = iD.rendererBackgroundSource({ template: '{switch:a,b}/{z}/{x}/{y}'}); expect(source.url([0,1,2])).to.equal('b/2/0/1'); }); it('distributes requests between subdomains', function() { - var source = iD.BackgroundSource({ template: '{switch:a,b}/{z}/{x}/{y}' }); + var source = iD.rendererBackgroundSource({ template: '{switch:a,b}/{z}/{x}/{y}' }); expect(source.url([0,1,1])).to.equal('b/1/0/1'); expect(source.url([0,2,1])).to.equal('a/1/0/2'); }); it('correctly displays an overlay with no overzoom specified', function() { - var source = iD.BackgroundSource({ scaleExtent: [6,16] }); + var source = iD.rendererBackgroundSource({ scaleExtent: [6,16] }); expect(source.validZoom(10)).to.be.true; expect(source.validZoom(3)).to.be.false; expect(source.validZoom(17)).to.be.true; }); it('correctly displays an overlay with an invalid overzoom', function() { - var source = iD.BackgroundSource({ scaleExtent: [6,16], overzoom: 'gibberish'}); + var source = iD.rendererBackgroundSource({ scaleExtent: [6,16], overzoom: 'gibberish'}); expect(source.validZoom(10)).to.be.true; expect(source.validZoom(3)).to.be.false; expect(source.validZoom(17)).to.be.true; }); it('correctly displays an overlay with overzoom:true', function() { - var source = iD.BackgroundSource({ scaleExtent: [6,16], overzoom: true}); + var source = iD.rendererBackgroundSource({ scaleExtent: [6,16], overzoom: true}); expect(source.validZoom(10)).to.be.true; expect(source.validZoom(3)).to.be.false; expect(source.validZoom(17)).to.be.true; }); it('correctly displays an overlay with overzoom:false', function() { - var source = iD.BackgroundSource({ scaleExtent: [6,16], overzoom: false}); + var source = iD.rendererBackgroundSource({ scaleExtent: [6,16], overzoom: false}); expect(source.validZoom(10)).to.be.true; expect(source.validZoom(3)).to.be.false; expect(source.validZoom(17)).to.be.false;