Add possibility to disable collapsible attributions from Source

This commit is contained in:
Bobo Häggström
2018-10-11 14:11:56 +02:00
parent da41515944
commit 2f4d31c8f4
7 changed files with 33 additions and 4 deletions

View File

@@ -186,6 +186,11 @@ class Attribution extends Control {
continue; continue;
} }
const collapsible = source.getAttributionsCollapsible();
if (collapsible !== undefined && !collapsible) {
this.setCollapsible(collapsible);
}
if (Array.isArray(attributions)) { if (Array.isArray(attributions)) {
for (let j = 0, jj = attributions.length; j < jj; ++j) { for (let j = 0, jj = attributions.length; j < jj; ++j) {
if (!(attributions[j] in lookup)) { if (!(attributions[j] in lookup)) {

View File

@@ -76,7 +76,8 @@ class OSM extends XYZ {
reprojectionErrorThreshold: options.reprojectionErrorThreshold, reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileLoadFunction: options.tileLoadFunction, tileLoadFunction: options.tileLoadFunction,
url: url, url: url,
wrapX: options.wrapX wrapX: options.wrapX,
attributionsCollapsible: false
}); });
} }

View File

@@ -31,6 +31,7 @@ import SourceState from './State.js';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {AttributionLike} [attributions] * @property {AttributionLike} [attributions]
* @property {boolean} [attributionsCollapsible] Whether attributions should be collapsible.
* @property {import("../proj.js").ProjectionLike} projection * @property {import("../proj.js").ProjectionLike} projection
* @property {SourceState} [state] * @property {SourceState} [state]
* @property {boolean} [wrapX] * @property {boolean} [wrapX]
@@ -66,6 +67,13 @@ class Source extends BaseObject {
*/ */
this.attributions_ = this.adaptAttributions_(options.attributions); this.attributions_ = this.adaptAttributions_(options.attributions);
/**
* @private
* @type {boolean}
*/
this.attributionsCollapsible_ = options.attributionsCollapsible !== undefined ?
options.attributionsCollapsible : true;
/** /**
* This source is currently loading data. Sources that defer loading to the * This source is currently loading data. Sources that defer loading to the
* map's tile queue never set this to `true`. * map's tile queue never set this to `true`.
@@ -120,6 +128,13 @@ class Source extends BaseObject {
return this.attributions_; return this.attributions_;
} }
/**
* @return {boolean} Should the attributions be collapsible or not.
*/
getAttributionsCollapsible() {
return this.attributionsCollapsible_;
}
/** /**
* Get the projection of the source. * Get the projection of the source.
* @return {import("../proj/Projection.js").default} Projection. * @return {import("../proj/Projection.js").default} Projection.

View File

@@ -14,6 +14,7 @@ import {wrapX, getForProjection as getTileGridForProjection} from '../tilegrid.j
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] * @property {import("./Source.js").AttributionLike} [attributions]
* @property {boolean} [attributionsCollapsible] Whether attributions should be collapsible.
* @property {number} [cacheSize] * @property {number} [cacheSize]
* @property {boolean} [opaque] * @property {boolean} [opaque]
* @property {number} [tilePixelRatio] * @property {number} [tilePixelRatio]
@@ -40,6 +41,7 @@ class TileSource extends Source {
super({ super({
attributions: options.attributions, attributions: options.attributions,
attributionsCollapsible: options.attributionsCollapsible,
projection: options.projection, projection: options.projection,
state: options.state, state: options.state,
wrapX: options.wrapX wrapX: options.wrapX

View File

@@ -17,6 +17,7 @@ import {getForProjection as getTileGridForProjection} from '../tilegrid.js';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {boolean} [attributionsCollapsible] Whether attributions should be collapsible.
* @property {number} [cacheSize=2048] Cache size. * @property {number} [cacheSize=2048] Cache size.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that
* you must provide a `crossOrigin` value if you are using the WebGL renderer or if you want to * you must provide a `crossOrigin` value if you are using the WebGL renderer or if you want to
@@ -81,7 +82,8 @@ class TileImage extends UrlTile {
url: options.url, url: options.url,
urls: options.urls, urls: options.urls,
wrapX: options.wrapX, wrapX: options.wrapX,
transition: options.transition transition: options.transition,
attributionsCollapsible: options.attributionsCollapsible
}); });
/** /**

View File

@@ -11,6 +11,7 @@ import {getKeyZXY} from '../tilecoord.js';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] * @property {import("./Source.js").AttributionLike} [attributions]
* @property {boolean} [attributionsCollapsible] Whether attributions should be collapsible.
* @property {number} [cacheSize] * @property {number} [cacheSize]
* @property {boolean} [opaque] * @property {boolean} [opaque]
* @property {import("../proj.js").ProjectionLike} [projection] * @property {import("../proj.js").ProjectionLike} [projection]
@@ -47,7 +48,8 @@ class UrlTile extends TileSource {
tileGrid: options.tileGrid, tileGrid: options.tileGrid,
tilePixelRatio: options.tilePixelRatio, tilePixelRatio: options.tilePixelRatio,
wrapX: options.wrapX, wrapX: options.wrapX,
transition: options.transition transition: options.transition,
attributionsCollapsible: options.attributionsCollapsible
}); });
/** /**

View File

@@ -8,6 +8,7 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions. * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {boolean} [attributionsCollapsible] Whether attributions should be collapsible.
* @property {number} [cacheSize=2048] Cache size. * @property {number} [cacheSize=2048] Cache size.
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that * @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that
* you must provide a `crossOrigin` value if you are using the WebGL renderer or if you want to * you must provide a `crossOrigin` value if you are using the WebGL renderer or if you want to
@@ -93,7 +94,8 @@ class XYZ extends TileImage {
url: options.url, url: options.url,
urls: options.urls, urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true, wrapX: options.wrapX !== undefined ? options.wrapX : true,
transition: options.transition transition: options.transition,
attributionsCollapsible: options.attributionsCollapsible
}); });
} }