index.js (1400B)
1 import L from 'leaflet'; 2 import './style.css'; 3 4 function enableAdaptiveHeight(control) { 5 if (control._adaptiveHeightEnabled) { 6 return; 7 } 8 const originalOnAdd = control.onAdd; 9 10 L.Util.extend(control, { 11 _adaptiveHeightEnabled: true, 12 13 onAdd: function(map) { 14 const result = originalOnAdd.call(this, map); 15 this.__setupResizeEventsHandler(); 16 setTimeout(() => this.__setAdaptiveHeight(), 0); 17 return result; 18 }, 19 20 __setupResizeEventsHandler: function() { 21 this._map.on('resize', this.__setAdaptiveHeight, this); 22 }, 23 24 __setAdaptiveHeight: function() { 25 const mapHeight = this._map.getSize().y; 26 let maxHeight; 27 maxHeight = (mapHeight - 28 this._container.offsetTop - // controls above 29 (this._container.parentNode.offsetHeight - this._container.offsetTop - 30 this._container.offsetHeight) - // controls below 31 70); // margin 32 this._form.style.maxHeight = maxHeight + 'px'; 33 } 34 } 35 ); 36 37 if (control._map) { 38 control.__setupResizeEventsHandler(); 39 setTimeout(() => control.__setAdaptiveHeight(), 0); 40 } 41 } 42 43 export default enableAdaptiveHeight;