diff --git a/externs/olx.js b/externs/olx.js index 205fe6f13f..0345ca8e1e 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -23,21 +23,6 @@ olx.CollectionOptions; olx.CollectionOptions.prototype.unique; -/** - * @typedef {{html: string, - * tileRanges: (Object.>|undefined)}} - */ -olx.AttributionOptions; - - -/** - * HTML markup for this attribution. - * @type {string} - * @api - */ -olx.AttributionOptions.prototype.html; - - /** * @typedef {{tracking: (boolean|undefined), * trackingOptions: (GeolocationPositionOptions|undefined), diff --git a/src/ol/Attribution.js b/src/ol/Attribution.js deleted file mode 100644 index 9a4484589d..0000000000 --- a/src/ol/Attribution.js +++ /dev/null @@ -1,99 +0,0 @@ -/** - * @module ol/Attribution - */ -import _ol_TileRange_ from './TileRange.js'; -import _ol_math_ from './math.js'; -import _ol_tilegrid_ from './tilegrid.js'; - -/** - * @classdesc - * An attribution for a layer source. - * - * Example: - * - * source: new ol.source.OSM({ - * attributions: [ - * new ol.Attribution({ - * html: 'All maps © ' + - * 'OpenCycleMap' - * }), - * ol.source.OSM.ATTRIBUTION - * ], - * .. - * - * @constructor - * @deprecated This class is deprecated and will removed in the next major release. - * @param {olx.AttributionOptions} options Attribution options. - * @struct - * @api - */ -var _ol_Attribution_ = function(options) { - - /** - * @private - * @type {string} - */ - this.html_ = options.html; - - /** - * @private - * @type {Object.>} - */ - this.tileRanges_ = options.tileRanges ? options.tileRanges : null; - -}; - - -/** - * Get the attribution markup. - * @return {string} The attribution HTML. - * @api - */ -_ol_Attribution_.prototype.getHTML = function() { - return this.html_; -}; - - -/** - * @param {Object.} tileRanges Tile ranges. - * @param {!ol.tilegrid.TileGrid} tileGrid Tile grid. - * @param {!ol.proj.Projection} projection Projection. - * @return {boolean} Intersects any tile range. - */ -_ol_Attribution_.prototype.intersectsAnyTileRange = function(tileRanges, tileGrid, projection) { - if (!this.tileRanges_) { - return true; - } - var i, ii, tileRange, zKey; - for (zKey in tileRanges) { - if (!(zKey in this.tileRanges_)) { - continue; - } - tileRange = tileRanges[zKey]; - var testTileRange; - for (i = 0, ii = this.tileRanges_[zKey].length; i < ii; ++i) { - testTileRange = this.tileRanges_[zKey][i]; - if (testTileRange.intersects(tileRange)) { - return true; - } - var extentTileRange = tileGrid.getTileRangeForExtentAndZ( - _ol_tilegrid_.extentFromProjection(projection), parseInt(zKey, 10)); - var width = extentTileRange.getWidth(); - if (tileRange.minX < extentTileRange.minX || - tileRange.maxX > extentTileRange.maxX) { - if (testTileRange.intersects(new _ol_TileRange_( - _ol_math_.modulo(tileRange.minX, width), - _ol_math_.modulo(tileRange.maxX, width), - tileRange.minY, tileRange.maxY))) { - return true; - } - if (tileRange.getWidth() > width && - testTileRange.intersects(extentTileRange)) { - return true; - } - } - } - } - return false; -}; -export default _ol_Attribution_; diff --git a/src/ol/control/Attribution.js b/src/ol/control/Attribution.js index d18ba642a2..fbaacd36ed 100644 --- a/src/ol/control/Attribution.js +++ b/src/ol/control/Attribution.js @@ -174,7 +174,7 @@ _ol_control_Attribution_.prototype.getSourceAttributions_ = function(frameState) continue; } - var attributionGetter = source.getAttributions2(); + var attributionGetter = source.getAttributions(); if (!attributionGetter) { continue; } diff --git a/src/ol/source/Source.js b/src/ol/source/Source.js index 58c464c4fa..136339031d 100644 --- a/src/ol/source/Source.js +++ b/src/ol/source/Source.js @@ -2,7 +2,6 @@ * @module ol/source/Source */ import {inherits, nullFunction} from '../index.js'; -import _ol_Attribution_ from '../Attribution.js'; import _ol_Object_ from '../Object.js'; import _ol_proj_ from '../proj.js'; import _ol_source_State_ from '../source/State.js'; @@ -33,15 +32,9 @@ var _ol_source_Source_ = function(options) { /** * @private - * @type {Array.} + * @type {?ol.Attribution} */ - this.attributions_ = null; - - /** - * @private - * @type {?ol.Attribution2} - */ - this.attributions2_ = this.adaptAttributions_(options.attributions); + this.attributions_ = this.adaptAttributions_(options.attributions); /** * @private @@ -68,42 +61,14 @@ inherits(_ol_source_Source_, _ol_Object_); /** * Turns the attributions option into an attributions function. - * @suppress {deprecated} * @param {ol.AttributionLike|undefined} attributionLike The attribution option. - * @return {?ol.Attribution2} An attribution function (or null). + * @return {?ol.Attribution} An attribution function (or null). */ _ol_source_Source_.prototype.adaptAttributions_ = function(attributionLike) { if (!attributionLike) { return null; } - if (attributionLike instanceof _ol_Attribution_) { - - // TODO: remove attributions_ in next major release - this.attributions_ = [attributionLike]; - - return function(frameState) { - return [attributionLike.getHTML()]; - }; - } if (Array.isArray(attributionLike)) { - if (attributionLike[0] instanceof _ol_Attribution_) { - - // TODO: remove attributions_ in next major release - this.attributions_ = attributionLike; - - var attributions = attributionLike.map(function(attribution) { - return attribution.getHTML(); - }); - return function(frameState) { - return attributions; - }; - } - - // TODO: remove attributions_ in next major release - this.attributions_ = attributionLike.map(function(attribution) { - return new _ol_Attribution_({html: attribution}); - }); - return function(frameState) { return attributionLike; }; @@ -113,11 +78,6 @@ _ol_source_Source_.prototype.adaptAttributions_ = function(attributionLike) { return attributionLike; } - // TODO: remove attributions_ in next major release - this.attributions_ = [ - new _ol_Attribution_({html: attributionLike}) - ]; - return function(frameState) { return [attributionLike]; }; @@ -138,24 +98,14 @@ _ol_source_Source_.prototype.forEachFeatureAtCoordinate = nullFunction; /** - * Get the attributions of the source. - * @return {Array.} Attributions. - * @api + * Get the attribution function for the source. + * @return {?ol.Attribution} Attribution function. */ _ol_source_Source_.prototype.getAttributions = function() { return this.attributions_; }; -/** - * Get the attribution function for the source. - * @return {?ol.Attribution2} Attribution function. - */ -_ol_source_Source_.prototype.getAttributions2 = function() { - return this.attributions2_; -}; - - /** * Get the logo of the source. * @return {string|olx.LogoOptions|undefined} Logo. @@ -213,12 +163,12 @@ _ol_source_Source_.prototype.refresh = function() { /** * Set the attributions of the source. * @param {ol.AttributionLike|undefined} attributions Attributions. - * Can be passed as `string`, `Array`, `{@link ol.Attribution2}`, + * Can be passed as `string`, `Array`, `{@link ol.Attribution}`, * or `undefined`. * @api */ _ol_source_Source_.prototype.setAttributions = function(attributions) { - this.attributions2_ = this.adaptAttributions_(attributions); + this.attributions_ = this.adaptAttributions_(attributions); this.changed(); }; diff --git a/src/ol/source/TileJSON.js b/src/ol/source/TileJSON.js index c191736595..23728876ae 100644 --- a/src/ol/source/TileJSON.js +++ b/src/ol/source/TileJSON.js @@ -136,7 +136,7 @@ _ol_source_TileJSON_.prototype.handleTileJSONResponse = function(tileJSON) { this.tileUrlFunction = _ol_TileUrlFunction_.createFromTemplates(tileJSON.tiles, tileGrid); - if (tileJSON.attribution !== undefined && !this.getAttributions2()) { + if (tileJSON.attribution !== undefined && !this.getAttributions()) { var attributionExtent = extent !== undefined ? extent : epsg4326Projection.getExtent(); diff --git a/src/ol/typedefs.js b/src/ol/typedefs.js index 7163d6b873..60c7569c04 100644 --- a/src/ol/typedefs.js +++ b/src/ol/typedefs.js @@ -75,10 +75,9 @@ ol.AtlasManagerInfo; * It represents either * * a simple string (e.g. `'© Acme Inc.'`) * * an array of simple strings (e.g. `['© Acme Inc.', '© Bacme Inc.']`) - * * a function that returns a string or array of strings (`{@link ol.Attribution2}`) + * * a function that returns a string or array of strings (`{@link ol.Attribution}`) * - * Note that the `{@link ol.Attribution}` constructor is deprecated. - * @typedef {string|Array.|ol.Attribution2|ol.Attribution|Array.} + * @typedef {string|Array.|ol.Attribution} */ ol.AttributionLike; @@ -89,7 +88,7 @@ ol.AttributionLike; * * @typedef {function(olx.FrameState): (string|Array.)} */ -ol.Attribution2; +ol.Attribution; /** diff --git a/test/spec/ol/source/source.test.js b/test/spec/ol/source/source.test.js index 21d2085607..e05604888d 100644 --- a/test/spec/ol/source/source.test.js +++ b/test/spec/ol/source/source.test.js @@ -1,4 +1,3 @@ -import _ol_Attribution_ from '../../../../src/ol/Attribution.js'; import _ol_proj_ from '../../../../src/ol/proj.js'; import _ol_source_Source_ from '../../../../src/ol/source/Source.js'; @@ -17,7 +16,7 @@ describe('ol.source.Source', function() { describe('config option `attributions`', function() { it('accepts undefined', function() { var source = new _ol_source_Source_({}); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.be(null); }); @@ -25,7 +24,7 @@ describe('ol.source.Source', function() { var source = new _ol_source_Source_({ attributions: 'Humpty' }); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.not.be(null); expect(typeof attributions).to.be('function'); expect(attributions()).to.eql(['Humpty']); @@ -35,7 +34,7 @@ describe('ol.source.Source', function() { var source = new _ol_source_Source_({ attributions: ['Humpty', 'Dumpty'] }); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.not.be(null); expect(typeof attributions).to.be('function'); expect(attributions()).to.eql(['Humpty', 'Dumpty']); @@ -47,7 +46,7 @@ describe('ol.source.Source', function() { return 'Humpty'; } }); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.not.be(null); expect(typeof attributions).to.be('function'); expect(attributions()).to.be('Humpty'); @@ -59,7 +58,7 @@ describe('ol.source.Source', function() { return ['Humpty', 'Dumpty']; } }); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.not.be(null); expect(typeof attributions).to.be('function'); expect(attributions()).to.eql(['Humpty', 'Dumpty']); @@ -78,55 +77,6 @@ describe('ol.source.Source', 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; @@ -142,13 +92,13 @@ describe('ol.source.Source', function() { it('accepts undefined', function() { source.setAttributions(); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.be(null); }); it('accepts a single string', function() { source.setAttributions('Humpty'); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.not.be(null); expect(typeof attributions).to.be('function'); expect(attributions()).to.eql(['Humpty']); @@ -156,7 +106,7 @@ describe('ol.source.Source', function() { it('accepts an array of strings', function() { source.setAttributions(['Humpty', 'Dumpty']); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.not.be(null); expect(typeof attributions).to.be('function'); expect(attributions()).to.eql(['Humpty', 'Dumpty']); @@ -166,7 +116,7 @@ describe('ol.source.Source', function() { source.setAttributions(function() { return 'Humpty'; }); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.not.be(null); expect(typeof attributions).to.be('function'); expect(attributions()).to.eql('Humpty'); @@ -176,7 +126,7 @@ describe('ol.source.Source', function() { source.setAttributions(function() { return ['Humpty', 'Dumpty']; }); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.not.be(null); expect(typeof attributions).to.be('function'); expect(attributions()).to.eql(['Humpty', 'Dumpty']); diff --git a/test/spec/ol/source/tileutfgrid.test.js b/test/spec/ol/source/tileutfgrid.test.js index d99ac409c9..479609bdc8 100644 --- a/test/spec/ol/source/tileutfgrid.test.js +++ b/test/spec/ol/source/tileutfgrid.test.js @@ -163,13 +163,13 @@ describe('ol.source.TileUTFGrid', function() { it('sets up correct attribution', function() { var source = getTileUTFGrid(); - expect(source.getAttributions2()).to.be(null); + expect(source.getAttributions()).to.be(null); // call the handleTileJSONResponse method with our // locally available tileJson (from `before`) source.handleTileJSONResponse(tileJson); - var attributions = source.getAttributions2(); + var attributions = source.getAttributions(); expect(attributions).to.not.be(null); expect(typeof attributions).to.be('function'); });