index.js (926B)
1 import L from 'leaflet'; 2 import './style.css'; 3 import '~/lib/leaflet.control.commons'; 4 5 L.Control.Caption = L.Control.extend({ 6 options: { 7 position: 'bottomright', 8 className: 'leaflet-control-caption' 9 }, 10 11 initialize: function(contents, options) { 12 L.setOptions(this, options); 13 this._contents = contents; 14 }, 15 16 onAdd: function(map) { 17 this._map = map; 18 this._container = L.DomUtil.create('div', this.options.className); 19 this._container.innerHTML = this._contents; 20 L.DomEvent.on(this._container, 'contextmenu', (e) => { 21 L.DomEvent.stopPropagation(e); 22 e.returnValue = true; 23 return true; 24 }); 25 return this._container; 26 }, 27 28 setContents: function(contents) { 29 this._contents = contents; 30 if (this._map) { 31 this._container.innerHTML = this._contents; 32 } 33 } 34 35 }); 36