UNPKG

leaflet-plugins

Version:

Miscellaneous plugins for Leaflet library for services that need to display route information and need satellite imagery from different providers

51 lines (40 loc) 1.27 kB
L.Icon.Text = L.Icon.extend({ initialize: function (text, options) { this._text = text; L.Icon.prototype.initialize.apply(this, [options]); }, createIcon: function () { var el = document.createElement('div'); el.appendChild(document.createTextNode(this._text)); this._setIconStyles(el, 'icon'); el.style.textShadow = '2px 2px 2px #fff'; el.style.whiteSpace = 'nowrap'; return el; }, createShadow: function () { return null; } }); L.Marker.Text = L.Marker.extend({ initialize: function (latlng, text, options) { L.Marker.prototype.initialize.apply(this, [latlng, options]); this._fakeicon = new L.Icon.Text(text); }, _initIcon: function () { L.Marker.prototype._initIcon.apply(this); var i = this._icon, s = this._shadow, obj = this.options.icon; this._icon = this._shadow = null; this.options.icon = this._fakeicon; L.Marker.prototype._initIcon.apply(this); this.options.icon = obj; if (s) { s.parentNode.removeChild(s); this._icon.appendChild(s); } i.parentNode.removeChild(i); this._icon.appendChild(i); var w = this._icon.clientWidth; this._icon.style.marginLeft = -w / 2 + 'px'; var off = new L.Point(w/2, 0); L.DomUtil.setPosition(i, off); if (s) L.DomUtil.setPosition(s, off); } });