forked from Leaflet/Leaflet.draw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTooltip.js
65 lines (54 loc) · 1.72 KB
/
Tooltip.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
L.Tooltip = L.Class.extend({
initialize: function (map) {
this._map = map;
this._popupPane = map._panes.popupPane;
this._container = map.options.drawControlTooltips ? L.DomUtil.create('div', 'leaflet-draw-tooltip', this._popupPane) : null;
this._singleLineLabel = false;
},
dispose: function () {
if (this._container) {
this._popupPane.removeChild(this._container);
this._container = null;
}
},
updateContent: function (labelText) {
if (!this._container) {
return this;
}
labelText.subtext = labelText.subtext || '';
// update the vertical position (only if changed)
if (labelText.subtext.length === 0 && !this._singleLineLabel) {
L.DomUtil.addClass(this._container, 'leaflet-draw-tooltip-single');
this._singleLineLabel = true;
}
else if (labelText.subtext.length > 0 && this._singleLineLabel) {
L.DomUtil.removeClass(this._container, 'leaflet-draw-tooltip-single');
this._singleLineLabel = false;
}
this._container.innerHTML =
(labelText.subtext.length > 0 ? '<span class="leaflet-draw-tooltip-subtext">' + labelText.subtext + '</span>' + '<br />' : '') +
'<span>' + labelText.text + '</span>';
return this;
},
updatePosition: function (latlng) {
var pos = this._map.latLngToLayerPoint(latlng),
tooltipContainer = this._container;
if (this._container) {
tooltipContainer.style.visibility = 'inherit';
L.DomUtil.setPosition(tooltipContainer, pos);
}
return this;
},
showAsError: function () {
if (this._container) {
L.DomUtil.addClass(this._container, 'leaflet-error-draw-tooltip');
}
return this;
},
removeError: function () {
if (this._container) {
L.DomUtil.removeClass(this._container, 'leaflet-error-draw-tooltip');
}
return this;
}
});