From 0023a72a3f9ef23a54134199a24be5360045b0bf Mon Sep 17 00:00:00 2001 From: Alberto Fanjul Date: Fri, 23 Dec 2022 15:20:35 +0100 Subject: [PATCH] Add optional parameter maxHeight --- README.md | 1 + src/L.Control.Window.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 83fd3a7..8bf45d7 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ var winMtds = L.control.window(map) | closeButton | Render close button? | true | Boolean | | className | Sets container class to style window. | 'control-window' | String | | maxWidth | Sets maximum width of window container in pixels. | 600 | Number | +| maxHeight | Sets maximum height of window container in pixels. | undefined | Number | | prompt | JSON object for prompt buttons. | undefined | JSON ```{callback: ..., action: ..., buttonAction: ..., buttonOK: ..., buttonCancel: ...}``` | | prompt.callback | Function to run after OK button is clicked. | undefined | e.g. ```function(){alert('hello')}``` | | prompt.action | Function to run after ACTION button is clicked. | undefined | e.g. ```function(){alert('I\'ll do something')}``` | diff --git a/src/L.Control.Window.js b/src/L.Control.Window.js index cc66b4a..7df00c6 100644 --- a/src/L.Control.Window.js +++ b/src/L.Control.Window.js @@ -273,12 +273,16 @@ L.Control.Window = L.Control.extend({ margin += this._containerPromptButtons.offsetHeight-20 } - var el = L.DomUtil.get(this.options.element) - var rect = el.getBoundingClientRect(); - var height = rect.bottom -rect.top; + var maxHeight = this.options.maxHeight; + if (maxHeight==undefined) { + var el = L.DomUtil.get(this.options.element) + var rect = el.getBoundingClientRect(); + var height = rect.bottom -rect.top; - var maxHeight = height - margin; - this._containerContent.setAttribute('style','max-height:'+maxHeight+'px') + maxHeight = height - margin; + } + this._container.setAttribute('style','max-height:'+maxHeight+'px;overflow:hidden;max-width:'+this.options.maxWidth+'px'); + this._containerContent.setAttribute('style','max-height:'+(maxHeight-60)+'px') }, close : function(){ this.hide();