From 89b354ddbaf896b408d65c0a95c61ae6316882b4 Mon Sep 17 00:00:00 2001 From: Olaf Veerman Date: Wed, 25 Mar 2015 14:17:39 +0000 Subject: [PATCH] Allow overzoom to be set on overlays The default behaviour is to overzoom overlays past their max scaleExtent. When 'overzoom':false is defined in imagery.json, the layer will disappear on the max scaleExtent. --- data/imagery.json | 1 + data/update_imagery.js | 4 ++++ js/id/renderer/background_source.js | 3 ++- test/spec/renderer/background_source.js | 28 +++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/data/imagery.json b/data/imagery.json index ef28d4fb8..2586fc185 100644 --- a/data/imagery.json +++ b/data/imagery.json @@ -10515,6 +10515,7 @@ 0, 16 ], + "overzoom": false, "terms_url": "http://www.mapbox.com/about/maps/", "terms_text": "Terms & Feedback", "default": true, diff --git a/data/update_imagery.js b/data/update_imagery.js index 1dbc2b79e..f0377eaa3 100644 --- a/data/update_imagery.js +++ b/data/update_imagery.js @@ -83,6 +83,10 @@ sources.forEach(function(source) { ]]; } + if (source.name == 'Locator Overlay') { + im.overzoom = false; + } + var attribution = source.attribution || {}; if (attribution.url) { im.terms_url = attribution.url; diff --git a/js/id/renderer/background_source.js b/js/id/renderer/background_source.js index 444082dc1..653a723a2 100644 --- a/js/id/renderer/background_source.js +++ b/js/id/renderer/background_source.js @@ -4,6 +4,7 @@ iD.BackgroundSource = function(data) { name = source.name; source.scaleExtent = data.scaleExtent || [0, 20]; + source.overzoom = data.overzoom !== false; source.offset = function(_) { if (!arguments.length) return offset; @@ -58,7 +59,7 @@ iD.BackgroundSource = function(data) { source.validZoom = function(z) { return source.scaleExtent[0] <= z && - (!source.isLocatorOverlay() || source.scaleExtent[1] > z); + (source.overzoom || source.scaleExtent[1] > z); }; source.isLocatorOverlay = function() { diff --git a/test/spec/renderer/background_source.js b/test/spec/renderer/background_source.js index b77ecab91..21f64ad92 100644 --- a/test/spec/renderer/background_source.js +++ b/test/spec/renderer/background_source.js @@ -19,4 +19,32 @@ describe('iD.BackgroundSource', function() { 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] }); + 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'}); + 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}); + 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}); + expect(source.validZoom(10)).to.be.true; + expect(source.validZoom(3)).to.be.false; + expect(source.validZoom(17)).to.be.false; + }); });