Remove ol/Attribution

This commit is contained in:
Tim Schaub
2017-12-12 19:27:12 -07:00
parent ac6b3fb908
commit 7e3d44e35a
8 changed files with 24 additions and 239 deletions

View File

@@ -23,21 +23,6 @@ olx.CollectionOptions;
olx.CollectionOptions.prototype.unique; olx.CollectionOptions.prototype.unique;
/**
* @typedef {{html: string,
* tileRanges: (Object.<string, Array.<ol.TileRange>>|undefined)}}
*/
olx.AttributionOptions;
/**
* HTML markup for this attribution.
* @type {string}
* @api
*/
olx.AttributionOptions.prototype.html;
/** /**
* @typedef {{tracking: (boolean|undefined), * @typedef {{tracking: (boolean|undefined),
* trackingOptions: (GeolocationPositionOptions|undefined), * trackingOptions: (GeolocationPositionOptions|undefined),

View File

@@ -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 &copy; ' +
* '<a href="https://www.opencyclemap.org/">OpenCycleMap</a>'
* }),
* 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.<string, Array.<ol.TileRange>>}
*/
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.<string, ol.TileRange>} 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_;

View File

@@ -174,7 +174,7 @@ _ol_control_Attribution_.prototype.getSourceAttributions_ = function(frameState)
continue; continue;
} }
var attributionGetter = source.getAttributions2(); var attributionGetter = source.getAttributions();
if (!attributionGetter) { if (!attributionGetter) {
continue; continue;
} }

View File

@@ -2,7 +2,6 @@
* @module ol/source/Source * @module ol/source/Source
*/ */
import {inherits, nullFunction} from '../index.js'; import {inherits, nullFunction} from '../index.js';
import _ol_Attribution_ from '../Attribution.js';
import _ol_Object_ from '../Object.js'; import _ol_Object_ from '../Object.js';
import _ol_proj_ from '../proj.js'; import _ol_proj_ from '../proj.js';
import _ol_source_State_ from '../source/State.js'; import _ol_source_State_ from '../source/State.js';
@@ -33,15 +32,9 @@ var _ol_source_Source_ = function(options) {
/** /**
* @private * @private
* @type {Array.<ol.Attribution>} * @type {?ol.Attribution}
*/ */
this.attributions_ = null; this.attributions_ = this.adaptAttributions_(options.attributions);
/**
* @private
* @type {?ol.Attribution2}
*/
this.attributions2_ = this.adaptAttributions_(options.attributions);
/** /**
* @private * @private
@@ -68,42 +61,14 @@ inherits(_ol_source_Source_, _ol_Object_);
/** /**
* Turns the attributions option into an attributions function. * Turns the attributions option into an attributions function.
* @suppress {deprecated}
* @param {ol.AttributionLike|undefined} attributionLike The attribution option. * @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) { _ol_source_Source_.prototype.adaptAttributions_ = function(attributionLike) {
if (!attributionLike) { if (!attributionLike) {
return null; 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 (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 function(frameState) {
return attributionLike; return attributionLike;
}; };
@@ -113,11 +78,6 @@ _ol_source_Source_.prototype.adaptAttributions_ = function(attributionLike) {
return attributionLike; return attributionLike;
} }
// TODO: remove attributions_ in next major release
this.attributions_ = [
new _ol_Attribution_({html: attributionLike})
];
return function(frameState) { return function(frameState) {
return [attributionLike]; return [attributionLike];
}; };
@@ -138,24 +98,14 @@ _ol_source_Source_.prototype.forEachFeatureAtCoordinate = nullFunction;
/** /**
* Get the attributions of the source. * Get the attribution function for the source.
* @return {Array.<ol.Attribution>} Attributions. * @return {?ol.Attribution} Attribution function.
* @api
*/ */
_ol_source_Source_.prototype.getAttributions = function() { _ol_source_Source_.prototype.getAttributions = function() {
return this.attributions_; 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. * Get the logo of the source.
* @return {string|olx.LogoOptions|undefined} Logo. * @return {string|olx.LogoOptions|undefined} Logo.
@@ -213,12 +163,12 @@ _ol_source_Source_.prototype.refresh = function() {
/** /**
* Set the attributions of the source. * Set the attributions of the source.
* @param {ol.AttributionLike|undefined} attributions Attributions. * @param {ol.AttributionLike|undefined} attributions Attributions.
* Can be passed as `string`, `Array<string>`, `{@link ol.Attribution2}`, * Can be passed as `string`, `Array<string>`, `{@link ol.Attribution}`,
* or `undefined`. * or `undefined`.
* @api * @api
*/ */
_ol_source_Source_.prototype.setAttributions = function(attributions) { _ol_source_Source_.prototype.setAttributions = function(attributions) {
this.attributions2_ = this.adaptAttributions_(attributions); this.attributions_ = this.adaptAttributions_(attributions);
this.changed(); this.changed();
}; };

View File

@@ -136,7 +136,7 @@ _ol_source_TileJSON_.prototype.handleTileJSONResponse = function(tileJSON) {
this.tileUrlFunction = this.tileUrlFunction =
_ol_TileUrlFunction_.createFromTemplates(tileJSON.tiles, tileGrid); _ol_TileUrlFunction_.createFromTemplates(tileJSON.tiles, tileGrid);
if (tileJSON.attribution !== undefined && !this.getAttributions2()) { if (tileJSON.attribution !== undefined && !this.getAttributions()) {
var attributionExtent = extent !== undefined ? var attributionExtent = extent !== undefined ?
extent : epsg4326Projection.getExtent(); extent : epsg4326Projection.getExtent();

View File

@@ -75,10 +75,9 @@ ol.AtlasManagerInfo;
* It represents either * It represents either
* * a simple string (e.g. `'© Acme Inc.'`) * * a simple string (e.g. `'© Acme Inc.'`)
* * an array of simple strings (e.g. `['© Acme Inc.', '© Bacme 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.<string>|ol.Attribution}
* @typedef {string|Array.<string>|ol.Attribution2|ol.Attribution|Array.<ol.Attribution>}
*/ */
ol.AttributionLike; ol.AttributionLike;
@@ -89,7 +88,7 @@ ol.AttributionLike;
* *
* @typedef {function(olx.FrameState): (string|Array.<string>)} * @typedef {function(olx.FrameState): (string|Array.<string>)}
*/ */
ol.Attribution2; ol.Attribution;
/** /**

View File

@@ -1,4 +1,3 @@
import _ol_Attribution_ from '../../../../src/ol/Attribution.js';
import _ol_proj_ from '../../../../src/ol/proj.js'; import _ol_proj_ from '../../../../src/ol/proj.js';
import _ol_source_Source_ from '../../../../src/ol/source/Source.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() { describe('config option `attributions`', function() {
it('accepts undefined', function() { it('accepts undefined', function() {
var source = new _ol_source_Source_({}); var source = new _ol_source_Source_({});
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.be(null); expect(attributions).to.be(null);
}); });
@@ -25,7 +24,7 @@ describe('ol.source.Source', function() {
var source = new _ol_source_Source_({ var source = new _ol_source_Source_({
attributions: 'Humpty' attributions: 'Humpty'
}); });
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.not.be(null); expect(attributions).to.not.be(null);
expect(typeof attributions).to.be('function'); expect(typeof attributions).to.be('function');
expect(attributions()).to.eql(['Humpty']); expect(attributions()).to.eql(['Humpty']);
@@ -35,7 +34,7 @@ describe('ol.source.Source', function() {
var source = new _ol_source_Source_({ var source = new _ol_source_Source_({
attributions: ['Humpty', 'Dumpty'] attributions: ['Humpty', 'Dumpty']
}); });
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.not.be(null); expect(attributions).to.not.be(null);
expect(typeof attributions).to.be('function'); expect(typeof attributions).to.be('function');
expect(attributions()).to.eql(['Humpty', 'Dumpty']); expect(attributions()).to.eql(['Humpty', 'Dumpty']);
@@ -47,7 +46,7 @@ describe('ol.source.Source', function() {
return 'Humpty'; return 'Humpty';
} }
}); });
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.not.be(null); expect(attributions).to.not.be(null);
expect(typeof attributions).to.be('function'); expect(typeof attributions).to.be('function');
expect(attributions()).to.be('Humpty'); expect(attributions()).to.be('Humpty');
@@ -59,7 +58,7 @@ describe('ol.source.Source', function() {
return ['Humpty', 'Dumpty']; return ['Humpty', 'Dumpty'];
} }
}); });
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.not.be(null); expect(attributions).to.not.be(null);
expect(typeof attributions).to.be('function'); expect(typeof attributions).to.be('function');
expect(attributions()).to.eql(['Humpty', 'Dumpty']); 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() { describe('#setAttributions()', function() {
var source = null; var source = null;
@@ -142,13 +92,13 @@ describe('ol.source.Source', function() {
it('accepts undefined', function() { it('accepts undefined', function() {
source.setAttributions(); source.setAttributions();
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.be(null); expect(attributions).to.be(null);
}); });
it('accepts a single string', function() { it('accepts a single string', function() {
source.setAttributions('Humpty'); source.setAttributions('Humpty');
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.not.be(null); expect(attributions).to.not.be(null);
expect(typeof attributions).to.be('function'); expect(typeof attributions).to.be('function');
expect(attributions()).to.eql(['Humpty']); expect(attributions()).to.eql(['Humpty']);
@@ -156,7 +106,7 @@ describe('ol.source.Source', function() {
it('accepts an array of strings', function() { it('accepts an array of strings', function() {
source.setAttributions(['Humpty', 'Dumpty']); source.setAttributions(['Humpty', 'Dumpty']);
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.not.be(null); expect(attributions).to.not.be(null);
expect(typeof attributions).to.be('function'); expect(typeof attributions).to.be('function');
expect(attributions()).to.eql(['Humpty', 'Dumpty']); expect(attributions()).to.eql(['Humpty', 'Dumpty']);
@@ -166,7 +116,7 @@ describe('ol.source.Source', function() {
source.setAttributions(function() { source.setAttributions(function() {
return 'Humpty'; return 'Humpty';
}); });
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.not.be(null); expect(attributions).to.not.be(null);
expect(typeof attributions).to.be('function'); expect(typeof attributions).to.be('function');
expect(attributions()).to.eql('Humpty'); expect(attributions()).to.eql('Humpty');
@@ -176,7 +126,7 @@ describe('ol.source.Source', function() {
source.setAttributions(function() { source.setAttributions(function() {
return ['Humpty', 'Dumpty']; return ['Humpty', 'Dumpty'];
}); });
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.not.be(null); expect(attributions).to.not.be(null);
expect(typeof attributions).to.be('function'); expect(typeof attributions).to.be('function');
expect(attributions()).to.eql(['Humpty', 'Dumpty']); expect(attributions()).to.eql(['Humpty', 'Dumpty']);

View File

@@ -163,13 +163,13 @@ describe('ol.source.TileUTFGrid', function() {
it('sets up correct attribution', function() { it('sets up correct attribution', function() {
var source = getTileUTFGrid(); var source = getTileUTFGrid();
expect(source.getAttributions2()).to.be(null); expect(source.getAttributions()).to.be(null);
// call the handleTileJSONResponse method with our // call the handleTileJSONResponse method with our
// locally available tileJson (from `before`) // locally available tileJson (from `before`)
source.handleTileJSONResponse(tileJson); source.handleTileJSONResponse(tileJson);
var attributions = source.getAttributions2(); var attributions = source.getAttributions();
expect(attributions).to.not.be(null); expect(attributions).to.not.be(null);
expect(typeof attributions).to.be('function'); expect(typeof attributions).to.be('function');
}); });