Make new behavior overridable; update docs and examples

This commit is contained in:
ahocevar
2018-10-14 12:10:40 +02:00
parent af4e5ca7cf
commit 2768884044
30 changed files with 43 additions and 167 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,9 +192,8 @@ class Attribution extends Control {
continue;
}
const collapsible = source.getAttributionsCollapsible();
if (collapsible !== undefined && !collapsible) {
this.setCollapsible(collapsible);
if (!this.overrideCollapsible_ && source.getAttributionsCollapsible() === false) {
this.setCollapsible(false);
}
if (Array.isArray(attributions)) {
@@ -221,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) {