Remove ol/Attribution
This commit is contained in:
@@ -23,21 +23,6 @@ olx.CollectionOptions;
|
||||
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),
|
||||
* trackingOptions: (GeolocationPositionOptions|undefined),
|
||||
|
||||
@@ -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 © ' +
|
||||
* '<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_;
|
||||
@@ -174,7 +174,7 @@ _ol_control_Attribution_.prototype.getSourceAttributions_ = function(frameState)
|
||||
continue;
|
||||
}
|
||||
|
||||
var attributionGetter = source.getAttributions2();
|
||||
var attributionGetter = source.getAttributions();
|
||||
if (!attributionGetter) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -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.<ol.Attribution>}
|
||||
* @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.<ol.Attribution>} 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<string>`, `{@link ol.Attribution2}`,
|
||||
* Can be passed as `string`, `Array<string>`, `{@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();
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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.<string>|ol.Attribution2|ol.Attribution|Array.<ol.Attribution>}
|
||||
* @typedef {string|Array.<string>|ol.Attribution}
|
||||
*/
|
||||
ol.AttributionLike;
|
||||
|
||||
@@ -89,7 +88,7 @@ ol.AttributionLike;
|
||||
*
|
||||
* @typedef {function(olx.FrameState): (string|Array.<string>)}
|
||||
*/
|
||||
ol.Attribution2;
|
||||
ol.Attribution;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user