summaryrefslogtreecommitdiffstats
path: root/debian/missing-sources/leaflet.js/control/Control.Attribution.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:45:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:45:13 +0000
commit3c99fde45db83b531c41c350ed4d0ac2a3c40c62 (patch)
treead5257daf9e41556ed73875ab56b69162dffdac1 /debian/missing-sources/leaflet.js/control/Control.Attribution.js
parentAdding upstream version 1.1.0. (diff)
downloadicingaweb2-module-map-debian.tar.xz
icingaweb2-module-map-debian.zip
Adding debian version 1.1.0-3.debian/1.1.0-3debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--debian/missing-sources/leaflet.js/control/Control.Attribution.js129
1 files changed, 129 insertions, 0 deletions
diff --git a/debian/missing-sources/leaflet.js/control/Control.Attribution.js b/debian/missing-sources/leaflet.js/control/Control.Attribution.js
new file mode 100644
index 0000000..49cd478
--- /dev/null
+++ b/debian/missing-sources/leaflet.js/control/Control.Attribution.js
@@ -0,0 +1,129 @@
+
+import {Control} from './Control';
+import {Map} from '../map/Map';
+import * as Util from '../core/Util';
+import * as DomEvent from '../dom/DomEvent';
+import * as DomUtil from '../dom/DomUtil';
+
+/*
+ * @class Control.Attribution
+ * @aka L.Control.Attribution
+ * @inherits Control
+ *
+ * The attribution control allows you to display attribution data in a small text box on a map. It is put on the map by default unless you set its [`attributionControl` option](#map-attributioncontrol) to `false`, and it fetches attribution texts from layers with the [`getAttribution` method](#layer-getattribution) automatically. Extends Control.
+ */
+
+export var Attribution = Control.extend({
+ // @section
+ // @aka Control.Attribution options
+ options: {
+ position: 'bottomright',
+
+ // @option prefix: String = 'Leaflet'
+ // The HTML text shown before the attributions. Pass `false` to disable.
+ prefix: '<a href="http://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>'
+ },
+
+ initialize: function (options) {
+ Util.setOptions(this, options);
+
+ this._attributions = {};
+ },
+
+ onAdd: function (map) {
+ map.attributionControl = this;
+ this._container = DomUtil.create('div', 'leaflet-control-attribution');
+ DomEvent.disableClickPropagation(this._container);
+
+ // TODO ugly, refactor
+ for (var i in map._layers) {
+ if (map._layers[i].getAttribution) {
+ this.addAttribution(map._layers[i].getAttribution());
+ }
+ }
+
+ this._update();
+
+ return this._container;
+ },
+
+ // @method setPrefix(prefix: String): this
+ // Sets the text before the attributions.
+ setPrefix: function (prefix) {
+ this.options.prefix = prefix;
+ this._update();
+ return this;
+ },
+
+ // @method addAttribution(text: String): this
+ // Adds an attribution text (e.g. `'Vector data &copy; Mapbox'`).
+ addAttribution: function (text) {
+ if (!text) { return this; }
+
+ if (!this._attributions[text]) {
+ this._attributions[text] = 0;
+ }
+ this._attributions[text]++;
+
+ this._update();
+
+ return this;
+ },
+
+ // @method removeAttribution(text: String): this
+ // Removes an attribution text.
+ removeAttribution: function (text) {
+ if (!text) { return this; }
+
+ if (this._attributions[text]) {
+ this._attributions[text]--;
+ this._update();
+ }
+
+ return this;
+ },
+
+ _update: function () {
+ if (!this._map) { return; }
+
+ var attribs = [];
+
+ for (var i in this._attributions) {
+ if (this._attributions[i]) {
+ attribs.push(i);
+ }
+ }
+
+ var prefixAndAttribs = [];
+
+ if (this.options.prefix) {
+ prefixAndAttribs.push(this.options.prefix);
+ }
+ if (attribs.length) {
+ prefixAndAttribs.push(attribs.join(', '));
+ }
+
+ this._container.innerHTML = prefixAndAttribs.join(' | ');
+ }
+});
+
+// @namespace Map
+// @section Control options
+// @option attributionControl: Boolean = true
+// Whether a [attribution control](#control-attribution) is added to the map by default.
+Map.mergeOptions({
+ attributionControl: true
+});
+
+Map.addInitHook(function () {
+ if (this.options.attributionControl) {
+ new Attribution().addTo(this);
+ }
+});
+
+// @namespace Control.Attribution
+// @factory L.control.attribution(options: Control.Attribution options)
+// Creates an attribution control.
+export var attribution = function (options) {
+ return new Attribution(options);
+};