index.js (1757B)
1 import L from 'leaflet'; 2 import './style.css'; 3 import '~/lib/controls-styles/controls-styles.css'; 4 import enableTopRow from '~/lib/leaflet.control.layers.top-row'; 5 6 function enableMinimize(control) { 7 if (control._minimizeEnabled) { 8 return; 9 } 10 11 enableTopRow(control); 12 13 const originalOnAdd = control.onAdd; 14 15 L.Util.extend(control, { 16 _minimizeEnabled: true, 17 18 onAdd: function(map) { 19 const container = originalOnAdd.call(this, map); 20 this.__injectMinimizeButtons(); 21 return container; 22 }, 23 24 __injectMinimizeButtons: function() { 25 const container = this._container; 26 const contentsWrapper = L.DomUtil.create('div', 'leaflet-control-content'); 27 while (container.childNodes.length) { 28 contentsWrapper.appendChild(container.childNodes[0]); 29 } 30 container.appendChild(contentsWrapper); 31 const minimizeButton = L.DomUtil.create('div', 'button-minimize'); 32 this._topRow.appendChild(minimizeButton); 33 const expandButton = L.DomUtil.create('div', 'leaflet-control-button-toggle', container); 34 expandButton.title = 'Select layers'; 35 L.DomEvent.on(expandButton, 'click', this.setExpanded, this); 36 L.DomEvent.on(minimizeButton, 'click', this.setMinimized, this); 37 }, 38 39 setExpanded: function() { 40 L.DomUtil.removeClass(this._container, 'minimized'); 41 }, 42 43 setMinimized: function() { 44 L.DomUtil.addClass(this._container, 'minimized'); 45 } 46 } 47 ); 48 } 49 50 export default enableMinimize;
