Merge pull request #8804 from notnotse/issue/8621-disable-collapsible-attributions-for-osm

Add possibility to disable collapsible attributions from Source
This commit is contained in:
Andreas Hocevar
2018-10-14 12:16:36 +02:00
committed by GitHub
36 changed files with 105 additions and 178 deletions

View File

@@ -16,9 +16,9 @@ import {visibleAtResolution} from '../layer/Layer.js';
* @property {HTMLElement|string} [target] Specify a target if you
* want the control to be rendered outside of the map's
* viewport.
* @property {boolean} [collapsible=true] Specify if attributions can
* be collapsed. If you use an OSM source, should be set to `false` — see
* {@link https://www.openstreetmap.org/copyright OSM Copyright} —
* @property {boolean} [collapsible] Specify if attributions can
* be collapsed. If not specified, sources control this behavior with their
* `attributionsCollapsible` setting.
* @property {boolean} [collapsed=true] Specify if attributions should
* be collapsed at startup.
* @property {string} [tipLabel='Attributions'] Text label to use for the button tip.
@@ -70,6 +70,12 @@ class Attribution extends Control {
*/
this.collapsed_ = options.collapsed !== undefined ? options.collapsed : true;
/**
* @private
* @type {boolean}
*/
this.overrideCollapsible_ = options.collapsible !== undefined;
/**
* @private
* @type {boolean}
@@ -145,12 +151,12 @@ class Attribution extends Control {
}
/**
* Get a list of visible attributions.
* Collect a list of visible attributions and set the collapsible state.
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
* @return {Array<string>} Attributions.
* @private
*/
getSourceAttributions_(frameState) {
collectSourceAttributions_(frameState) {
/**
* Used to determine if an attribution already exists.
* @type {!Object<string, boolean>}
@@ -186,6 +192,10 @@ class Attribution extends Control {
continue;
}
if (!this.overrideCollapsible_ && source.getAttributionsCollapsible() === false) {
this.setCollapsible(false);
}
if (Array.isArray(attributions)) {
for (let j = 0, jj = attributions.length; j < jj; ++j) {
if (!(attributions[j] in lookup)) {
@@ -216,7 +226,7 @@ class Attribution extends Control {
return;
}
const attributions = this.getSourceAttributions_(frameState);
const attributions = this.collectSourceAttributions_(frameState);
const visible = attributions.length > 0;
if (this.renderedVisible_ != visible) {

View File

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

View File

@@ -31,6 +31,7 @@ import SourceState from './State.js';
/**
* @typedef {Object} Options
* @property {AttributionLike} [attributions]
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {import("../proj.js").ProjectionLike} projection
* @property {SourceState} [state='ready']
* @property {boolean} [wrapX=false]
@@ -66,6 +67,13 @@ class Source extends BaseObject {
*/
this.attributions_ = 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
* map's tile queue never set this to `true`.
@@ -96,6 +104,13 @@ class Source extends BaseObject {
return this.attributions_;
}
/**
* @return {boolean} Aattributions are collapsible.
*/
getAttributionsCollapsible() {
return this.attributionsCollapsible_;
}
/**
* Get the projection of the source.
* @return {import("../proj/Projection.js").default} Projection.

View File

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

View File

@@ -17,6 +17,7 @@ import {getForProjection as getTileGridForProjection} from '../tilegrid.js';
/**
* @typedef {Object} Options
* @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {number} [cacheSize=2048] Cache size.
* @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
@@ -81,7 +82,8 @@ class TileImage extends UrlTile {
url: options.url,
urls: options.urls,
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
* @property {import("./Source.js").AttributionLike} [attributions]
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {number} [cacheSize]
* @property {boolean} [opaque]
* @property {import("../proj.js").ProjectionLike} [projection]
@@ -47,7 +48,8 @@ class UrlTile extends TileSource {
tileGrid: options.tileGrid,
tilePixelRatio: options.tilePixelRatio,
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
* @property {import("./Source.js").AttributionLike} [attributions] Attributions.
* @property {boolean} [attributionsCollapsible=true] Attributions are collapsible.
* @property {number} [cacheSize=2048] Cache size.
* @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
@@ -93,7 +94,8 @@ class XYZ extends TileImage {
url: options.url,
urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true,
transition: options.transition
transition: options.transition,
attributionsCollapsible: options.attributionsCollapsible
});
}