Code coverage report for src/control/Control.Attribution.js

Statements: 93.62% (44 / 47)      Branches: 83.33% (20 / 24)      Functions: 90.91% (10 / 11)      Lines: 95.45% (42 / 44)     

All files » src/control/ » Control.Attribution.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116        1             60   60       58 58   58       58   58                     1 1 1       15   9 8   9   9   9       5   4 2 2     4       70   70   70 16 14       70   70 70   70 11     70       14 6         2           1       1 50 50       1 1    
/*
 * L.Control.Attribution is used for displaying attribution on the map (added by default).
 */
 
L.Control.Attribution = L.Control.extend({
	options: {
		position: 'bottomright',
		prefix: '<a href="http://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>'
	},
 
	initialize: function (options) {
		L.setOptions(this, options);
 
		this._attributions = {};
	},
 
	onAdd: function (map) {
		this._container = L.DomUtil.create('div', 'leaflet-control-attribution');
		L.DomEvent.disableClickPropagation(this._container);
 
		map
		    .on('layeradd', this._onLayerAdd, this)
		    .on('layerremove', this._onLayerRemove, this);
 
		this._update();
 
		return this._container;
	},
 
	onRemove: function (map) {
		map
		    .off('layeradd', this._onLayerAdd)
		    .off('layerremove', this._onLayerRemove);
 
	},
 
	setPrefix: function (prefix) {
		this.options.prefix = prefix;
		this._update();
		return this;
	},
 
	addAttribution: function (text) {
		if (!text) { return; }
 
		if (!this._attributions[text]) {
			this._attributions[text] = 0;
		}
		this._attributions[text]++;
 
		this._update();
 
		return this;
	},
 
	removeAttribution: function (text) {
		if (!text) { return; }
 
		if (this._attributions[text]) {
			this._attributions[text]--;
			this._update();
		}
 
		return this;
	},
 
	_update: function () {
		Iif (!this._map) { return; }
 
		var attribs = [];
 
		for (var i in this._attributions) {
			if (this._attributions.hasOwnProperty(i) && this._attributions[i]) {
				attribs.push(i);
			}
		}
 
		var prefixAndAttribs = [];
 
		Eif (this.options.prefix) {
			prefixAndAttribs.push(this.options.prefix);
		}
		if (attribs.length) {
			prefixAndAttribs.push(attribs.join(', '));
		}
 
		this._container.innerHTML = prefixAndAttribs.join(' | ');
	},
 
	_onLayerAdd: function (e) {
		if (e.layer.getAttribution) {
			this.addAttribution(e.layer.getAttribution());
		}
	},
 
	_onLayerRemove: function (e) {
		Iif (e.layer.getAttribution) {
			this.removeAttribution(e.layer.getAttribution());
		}
	}
});
 
L.Map.mergeOptions({
	attributionControl: true
});
 
L.Map.addInitHook(function () {
	Eif (this.options.attributionControl) {
		this.attributionControl = (new L.Control.Attribution()).addTo(this);
	}
});
 
L.control.attribution = function (options) {
	return new L.Control.Attribution(options);
};