12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- L.DrawTooltip = L.Class.extend({
- initialize: function (map) {
- this._map = map;
- this._popupPane = map._panes.popupPane;
- this._container = L.DomUtil.create('div', 'leaflet-draw-tooltip', this._popupPane);
- this._singleLineLabel = false;
- },
- dispose: function () {
- this._popupPane.removeChild(this._container);
- this._container = null;
- },
- updateContent: function (labelText) {
- 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);
- L.DomUtil.setPosition(this._container, pos);
- return this;
- },
- showAsError: function () {
- L.DomUtil.addClass(this._container, 'leaflet-error-draw-tooltip');
- return this;
- },
- removeError: function () {
- L.DomUtil.removeClass(this._container, 'leaflet-error-draw-tooltip');
- return this;
- }
- });
|