Commit | Line | Data |
---|---|---|
c5ba5b04 JW |
1 | L.Control.Attribution = L.Class.extend({\r |
2 | onAdd: function(map) {\r | |
3 | this._container = L.DomUtil.create('div', 'leaflet-control-attribution');\r | |
4 | this._map = map;\r | |
5 | this._prefix = 'Powered by <a href="http://leaflet.cloudmade.com">Leaflet</a>';\r | |
6 | this._attributions = {};\r | |
7 | this._update();\r | |
8 | },\r | |
9 | \r | |
10 | getPosition: function() {\r | |
11 | return L.Control.Position.BOTTOM_RIGHT;\r | |
12 | },\r | |
13 | \r | |
14 | getContainer: function() {\r | |
15 | return this._container;\r | |
16 | },\r | |
17 | \r | |
18 | setPrefix: function(prefix) {\r | |
19 | this._prefix = prefix;\r | |
20 | },\r | |
21 | \r | |
22 | addAttribution: function(text) {\r | |
23 | if (!text) return;\r | |
24 | this._attributions[text] = true;\r | |
25 | this._update();\r | |
26 | },\r | |
27 | \r | |
28 | removeAttribution: function(text) {\r | |
29 | if (!text) return;\r | |
30 | delete this._attributions[text];\r | |
31 | this._update();\r | |
32 | },\r | |
33 | \r | |
34 | _update: function() {\r | |
35 | if (!this._map) return;\r | |
36 | \r | |
37 | var attribs = [];\r | |
38 | \r | |
39 | for (var i in this._attributions) {\r | |
40 | if (this._attributions.hasOwnProperty(i)) {\r | |
41 | attribs.push(i);\r | |
42 | }\r | |
43 | }\r | |
44 | \r | |
45 | var prefixAndAttribs = [];\r | |
46 | if (this._prefix) {\r | |
47 | prefixAndAttribs.push(this._prefix);\r | |
48 | }\r | |
49 | if (attribs.length) {\r | |
50 | prefixAndAttribs.push(attribs.join(', '));\r | |
51 | }\r | |
52 | \r | |
53 | this._container.innerHTML = prefixAndAttribs.join(' — ');\r | |
54 | }\r | |
55 | }); |