-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaflet-control-credits-src.js
63 lines (55 loc) · 2.63 KB
/
leaflet-control-credits-src.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
// a simple control to display a logo and credits in the corner of the map, with some neat interactive behavior
// in Leaflet tradition, a shortcut method is also provided, so you may use either version:
// new L.CreditsControl(options)
// L.controlCredits(options)
L.controlCredits = function (options) {
return new L.CreditsControl(options);
}
L.CreditsControl = L.Control.extend({
options: {
position: 'bottomright'
},
initialize: function(options) {
if (! options.text) throw "L.CreditsControl missing required option: text";
if (! options.image) throw "L.CreditsControl missing required option: image";
if (! options.link) throw "L.CreditsControl missing required option: link";
L.setOptions(this,options);
},
onAdd: function (map) {
this._map = map;
// create our container, and set the background image
var container = L.DomUtil.create('div', 'leaflet-credits-control', container);
container.style.backgroundImage = 'url(' + this.options.image + ')';
if (this.options.width) container.style.paddingRight = this.options.width + 'px';
if (this.options.height) container.style.height = this.options.height + 'px';
// generate the hyperlink to the left-hand side
var link = L.DomUtil.create('a', '', container);
link.target = '_blank';
link.href = this.options.link;
link.innerHTML = this.options.text;
// create a linkage between this control and the hyperlink bit, since we will be toggling CSS for that hyperlink section
container.link = link;
// clicking the control (the image bit) expands the left-hand hyperlink/text bit
L.DomEvent
.addListener(container, 'mousedown', L.DomEvent.stopPropagation)
.addListener(container, 'click', L.DomEvent.stopPropagation)
.addListener(container, 'dblclick', L.DomEvent.stopPropagation)
.addListener(container, 'click', function () {
var link = this.link;
if ( L.DomUtil.hasClass(link, 'leaflet-credits-showlink') ) {
L.DomUtil.removeClass(link, 'leaflet-credits-showlink');
} else {
L.DomUtil.addClass(link, 'leaflet-credits-showlink');
}
});
// afterthought keep a reference to our container and to the link,
// in case we need to change their content later via setText() et al
this._container = container;
this._link = link;
// all done
return container;
},
setText: function (html) {
this._link.innerHTML = html;
}
});