Reworked attribution handling
This commit is contained in:
1 parent
a5a0f5b98b
commit
2dd8fdb5b7
32 files changed
+346
-391
No files matched your search
@@ -22,12 +22,10 @@ describe('ol.renderer.Layer', function() {
|
||||
var extent = [];
|
||||
var resolution = 1;
|
||||
var pixelRatio = 1;
|
||||
var attributions = [];
|
||||
var src = '';
|
||||
var crossOrigin = '';
|
||||
imageLoadFunction = sinon.spy();
|
||||
image = new ol.Image(extent, resolution, pixelRatio, attributions,
|
||||
src, crossOrigin, imageLoadFunction);
|
||||
image = new ol.Image(extent, resolution, pixelRatio, src, crossOrigin, imageLoadFunction);
|
||||
});
|
||||
|
||||
describe('load IDLE image', function() {
|
||||
|
||||
@@ -12,7 +12,7 @@ describe('ol.reproj.Image', function() {
|
||||
ol.proj.get('EPSG:3857'), ol.proj.get('EPSG:4326'),
|
||||
[-180, -85, 180, 85], 10, pixelRatio,
|
||||
function(extent, resolution, pixelRatio) {
|
||||
return new ol.Image(extent, resolution, pixelRatio, [],
|
||||
return new ol.Image(extent, resolution, pixelRatio,
|
||||
'data:image/gif;base64,' +
|
||||
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=', null,
|
||||
function(image, src) {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.Source');
|
||||
@@ -19,68 +17,52 @@ describe('ol.source.Source', function() {
|
||||
describe('config option `attributions`', function() {
|
||||
it('accepts undefined', function() {
|
||||
var source = new ol.source.Source({});
|
||||
var attributions = source.getAttributions();
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.be(null);
|
||||
});
|
||||
|
||||
it('accepts a single string', function() {
|
||||
var source = new ol.source.Source({
|
||||
attributions: 'Humpty'
|
||||
});
|
||||
var attributions = source.getAttributions();
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(1);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0].getHTML()).to.be('Humpty');
|
||||
expect(typeof attributions).to.be('function');
|
||||
expect(attributions()).to.eql(['Humpty']);
|
||||
});
|
||||
|
||||
it('accepts an array of strings', function() {
|
||||
var source = new ol.source.Source({
|
||||
attributions: ['Humpty', 'Dumpty']
|
||||
});
|
||||
var attributions = source.getAttributions();
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(2);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0].getHTML()).to.be('Humpty');
|
||||
expect(attributions[1]).to.be.an(ol.Attribution);
|
||||
expect(attributions[1].getHTML()).to.be('Dumpty');
|
||||
expect(typeof attributions).to.be('function');
|
||||
expect(attributions()).to.eql(['Humpty', 'Dumpty']);
|
||||
});
|
||||
it('accepts a single ol.Attribution', function() {
|
||||
var passedAttribution = new ol.Attribution({html: 'Humpty'});
|
||||
|
||||
it('accepts a function that returns a string', function() {
|
||||
var source = new ol.source.Source({
|
||||
attributions: passedAttribution
|
||||
attributions: function() {
|
||||
return 'Humpty';
|
||||
}
|
||||
});
|
||||
var attributions = source.getAttributions();
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(1);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0]).to.be(passedAttribution);
|
||||
expect(typeof attributions).to.be('function');
|
||||
expect(attributions()).to.be('Humpty');
|
||||
});
|
||||
it('accepts an array of ol.Attribution', function() {
|
||||
var firstAttribution = new ol.Attribution({html: 'Humpty'});
|
||||
var secondAttribution = new ol.Attribution({html: 'Dumpty'});
|
||||
|
||||
it('accepts a function that returns an array of strings', function() {
|
||||
var source = new ol.source.Source({
|
||||
attributions: [firstAttribution, secondAttribution]
|
||||
attributions: function() {
|
||||
return ['Humpty', 'Dumpty'];
|
||||
}
|
||||
});
|
||||
var attributions = source.getAttributions();
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(2);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0]).to.be(firstAttribution);
|
||||
expect(attributions[1]).to.be.an(ol.Attribution);
|
||||
expect(attributions[1]).to.be(secondAttribution);
|
||||
});
|
||||
it('accepts an array with a string and an ol.Attribution', function() {
|
||||
var attribution = new ol.Attribution({html: 'Dumpty'});
|
||||
var source = new ol.source.Source({
|
||||
attributions: ['Humpty', attribution]
|
||||
});
|
||||
var attributions = source.getAttributions();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(2);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0].getHTML()).to.be('Humpty');
|
||||
expect(attributions[1]).to.be.an(ol.Attribution);
|
||||
expect(attributions[1]).to.be(attribution);
|
||||
expect(typeof attributions).to.be('function');
|
||||
expect(attributions()).to.eql(['Humpty', 'Dumpty']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -96,7 +78,56 @@ describe('ol.source.Source', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setAttributions`', function() {
|
||||
describe('#getAttributions()', function() {
|
||||
it('maintains backwards compatibility for string option', function() {
|
||||
var source = new ol.source.Source({
|
||||
attributions: 'foo'
|
||||
});
|
||||
var attributions = source.getAttributions();
|
||||
expect(attributions.length).to.be(1);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0].getHTML()).to.be('foo');
|
||||
});
|
||||
|
||||
it('maintains backwards compatibility for array of strings option', function() {
|
||||
var source = new ol.source.Source({
|
||||
attributions: ['foo', 'bar']
|
||||
});
|
||||
var attributions = source.getAttributions();
|
||||
expect(attributions.length).to.be(2);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0].getHTML()).to.be('foo');
|
||||
expect(attributions[1]).to.be.an(ol.Attribution);
|
||||
expect(attributions[1].getHTML()).to.be('bar');
|
||||
});
|
||||
|
||||
it('maintains backwards compatibility for ol.Attribution option', function() {
|
||||
var source = new ol.source.Source({
|
||||
attributions: new ol.Attribution({html: 'foo'})
|
||||
});
|
||||
var attributions = source.getAttributions();
|
||||
expect(attributions.length).to.be(1);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0].getHTML()).to.be('foo');
|
||||
});
|
||||
|
||||
it('maintains backwards compatibility for array of strings option', function() {
|
||||
var source = new ol.source.Source({
|
||||
attributions: [
|
||||
new ol.Attribution({html: 'foo'}),
|
||||
new ol.Attribution({html: 'bar'})
|
||||
]
|
||||
});
|
||||
var attributions = source.getAttributions();
|
||||
expect(attributions.length).to.be(2);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0].getHTML()).to.be('foo');
|
||||
expect(attributions[1]).to.be.an(ol.Attribution);
|
||||
expect(attributions[1].getHTML()).to.be('bar');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setAttributions()', function() {
|
||||
var source = null;
|
||||
|
||||
beforeEach(function() {
|
||||
@@ -104,64 +135,51 @@ describe('ol.source.Source', function() {
|
||||
attributions: 'before'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
source = null;
|
||||
});
|
||||
|
||||
it('accepts undefined', function() {
|
||||
source.setAttributions();
|
||||
var attributions = source.getAttributions();
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.be(null);
|
||||
});
|
||||
|
||||
it('accepts a single string', function() {
|
||||
source.setAttributions('Humpty');
|
||||
var attributions = source.getAttributions();
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(1);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0].getHTML()).to.be('Humpty');
|
||||
expect(typeof attributions).to.be('function');
|
||||
expect(attributions()).to.eql(['Humpty']);
|
||||
});
|
||||
|
||||
it('accepts an array of strings', function() {
|
||||
source.setAttributions(['Humpty', 'Dumpty']);
|
||||
var attributions = source.getAttributions();
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(2);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0].getHTML()).to.be('Humpty');
|
||||
expect(attributions[1]).to.be.an(ol.Attribution);
|
||||
expect(attributions[1].getHTML()).to.be('Dumpty');
|
||||
expect(typeof attributions).to.be('function');
|
||||
expect(attributions()).to.eql(['Humpty', 'Dumpty']);
|
||||
});
|
||||
it('accepts a single ol.Attribution', function() {
|
||||
var passedAttribution = new ol.Attribution({html: 'Humpty'});
|
||||
source.setAttributions(passedAttribution);
|
||||
var attributions = source.getAttributions();
|
||||
|
||||
it('accepts a function that returns a string', function() {
|
||||
source.setAttributions(function() {
|
||||
return 'Humpty';
|
||||
});
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(1);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0]).to.be(passedAttribution);
|
||||
expect(typeof attributions).to.be('function');
|
||||
expect(attributions()).to.eql('Humpty');
|
||||
});
|
||||
it('accepts an array of ol.Attribution', function() {
|
||||
var firstAttribution = new ol.Attribution({html: 'Humpty'});
|
||||
var secondAttribution = new ol.Attribution({html: 'Dumpty'});
|
||||
source.setAttributions([firstAttribution, secondAttribution]);
|
||||
var attributions = source.getAttributions();
|
||||
|
||||
it('accepts a function that returns an array of strings', function() {
|
||||
source.setAttributions(function() {
|
||||
return ['Humpty', 'Dumpty'];
|
||||
});
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(2);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0]).to.be(firstAttribution);
|
||||
expect(attributions[1]).to.be.an(ol.Attribution);
|
||||
expect(attributions[1]).to.be(secondAttribution);
|
||||
});
|
||||
it('accepts an array with a string and an ol.Attribution', function() {
|
||||
var attribution = new ol.Attribution({html: 'Dumpty'});
|
||||
source.setAttributions(['Humpty', attribution]);
|
||||
var attributions = source.getAttributions();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(2);
|
||||
expect(attributions[0]).to.be.an(ol.Attribution);
|
||||
expect(attributions[0].getHTML()).to.be('Humpty');
|
||||
expect(attributions[1]).to.be.an(ol.Attribution);
|
||||
expect(attributions[1]).to.be(attribution);
|
||||
expect(typeof attributions).to.be('function');
|
||||
expect(attributions()).to.eql(['Humpty', 'Dumpty']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -165,21 +165,15 @@ describe('ol.source.TileUTFGrid', function() {
|
||||
|
||||
it('sets up correct attribution', function() {
|
||||
var source = getTileUTFGrid();
|
||||
expect(source.getAttributions()).to.be(null);
|
||||
expect(source.getAttributions2()).to.be(null);
|
||||
|
||||
// call the handleTileJSONResponse method with our
|
||||
// locally available tileJson (from `before`)
|
||||
source.handleTileJSONResponse(tileJson);
|
||||
|
||||
var attributions = source.getAttributions();
|
||||
var attributions = source.getAttributions2();
|
||||
expect(attributions).to.not.be(null);
|
||||
expect(attributions).to.have.length(1);
|
||||
expect(attributions[0].getHTML()).to.be(tileJson.attribution);
|
||||
var tileRanges = attributions[0].tileRanges_;
|
||||
for (var z = tileJson.minzoom; z <= tileJson.maxzoom; z++) {
|
||||
var key = z.toString();
|
||||
expect(key in tileRanges).to.be(true);
|
||||
}
|
||||
expect(typeof attributions).to.be('function');
|
||||
});
|
||||
|
||||
it('sets correct state', function() {
|
||||
|
||||
Reference in new issue
Block a user