@@ -49,10 +49,10 @@ import { consume } from '@lit/context';
4949import { isSameLayer , LayerService } from 'src/features/layer/layer.service' ;
5050import { LayerInfoService } from 'src/features/layer/info/layer-info.service' ;
5151import { distinctUntilChanged , map , skip , take } from 'rxjs' ;
52- import { run } from 'src/utils/fn.utils' ;
5352import { getLayersConfig } from 'src/swisstopoImagery' ;
5453import { SessionService } from 'src/features/session' ;
5554import { initializeLayerHelpers } from 'src/layers/helpers' ;
55+ import { run } from 'src/utils/fn.utils' ;
5656
5757export type SearchLayer = SearchLayerWithLayer | SearchLayerWithSource ;
5858
@@ -123,7 +123,9 @@ export class SideBar extends LitElementI18n {
123123 private shareListenerAdded = false ;
124124
125125 private readonly shareDownListener = ( evt ) => {
126- if ( ! evt . composedPath ( ) . includes ( this ) ) this . activePanel = null ;
126+ if ( ! evt . composedPath ( ) . includes ( this ) ) {
127+ this . closePanel ( ) ;
128+ }
127129 } ;
128130
129131 private viewer : Viewer | null = null ;
@@ -206,8 +208,9 @@ export class SideBar extends LitElementI18n {
206208 } ) ;
207209
208210 const sliceOptions = getSliceParam ( ) ;
209- if ( sliceOptions ?. type && sliceOptions . slicePoints )
210- this . activePanel = 'tools' ;
211+ if ( sliceOptions ?. type && sliceOptions . slicePoints ) {
212+ this . openPanel ( 'tools' ) ;
213+ }
211214
212215 this . layerService . layerActivated$ . subscribe ( ( layer ) => {
213216 this . maybeShowVisibilityHint ( layer as LayerConfig ) ;
@@ -224,18 +227,49 @@ export class SideBar extends LitElementI18n {
224227 } ) ;
225228 }
226229
227- async togglePanel ( panelName , showHeader = true ) {
230+ async togglePanel ( panelName : string , showHeader = true ) {
231+ this . showHeader = showHeader ;
232+ if ( this . activePanel === panelName ) {
233+ this . closePanel ( panelName ) ;
234+ } else {
235+ this . openPanel ( panelName ) ;
236+ }
237+ }
238+
239+ private openPanel ( panelName : string ) : void {
240+ document . body . style . setProperty (
241+ '--sidebar-width' ,
242+ run ( ( ) => {
243+ switch ( panelName ) {
244+ case 'data' :
245+ return '440px' ;
246+ case 'settings' :
247+ case 'tools' :
248+ return '250px' ;
249+ case 'dashboard' :
250+ return 'min(1028px, calc(100vw - 144px))' ;
251+ case 'share' :
252+ return '436px' ;
253+ default :
254+ return '' ;
255+ }
256+ } ) ,
257+ ) ;
258+ this . activePanel = panelName ;
259+ }
260+
261+ private readonly handlePanelClose = ( ) => this . closePanel ( ) ;
262+
263+ private readonly closePanel = ( panelName ?: string ) : void => {
228264 if ( DashboardStore . projectMode . value === 'edit' ) {
229265 DashboardStore . showSaveOrCancelWarning ( true ) ;
230266 return ;
231267 }
232- this . showHeader = showHeader ;
233- if ( this . activePanel === panelName ) {
268+ if ( panelName === undefined || this . activePanel === panelName ) {
269+ document . body . style . setProperty ( '--sidebar-width' , '' ) ;
234270 this . activePanel = null ;
235- return ;
236271 }
237- this . activePanel = panelName ;
238- }
272+ } ;
239273
240274 async syncActiveLayers ( ) {
241275 const flatLayers = flattenLayers ( this . catalogLayers ! ) ;
@@ -570,18 +604,18 @@ export class SideBar extends LitElementI18n {
570604 < ngm-dashboard
571605 class ="ngm-side-bar-panel ngm-large-panel "
572606 ?hidden =${ this . activePanel !== 'dashboard' }
573- @close =${ ( ) => ( this . activePanel = null ) }
607+ @close =${ this . handlePanelClose }
574608 > </ ngm-dashboard >
575609 < ngm-layer-panel
576610 ?hidden ="${ this . activePanel !== 'data' } "
577611 .layers ="${ this . catalogLayers ?? [ ] } "
578- @close ="${ ( ) => ( this . activePanel = null ) } "
612+ @close ="${ this . handlePanelClose } "
579613 > </ ngm-layer-panel >
580614 < div .hidden =${ this . activePanel !== 'tools' } class ="ngm-side-bar-panel">
581615 < ngm-tools
582616 .toolsHidden =${ this . activePanel !== 'tools' }
583- @open =${ ( ) => ( this . activePanel = 'tools' ) }
584- @close=${ ( ) => ( this . activePanel = null ) }
617+ @open =${ ( ) => this . openPanel ( 'tools' ) }
618+ @close=${ this . handlePanelClose }
585619 > </ ngm-tools >
586620 </ div >
587621 < div
@@ -590,10 +624,7 @@ export class SideBar extends LitElementI18n {
590624 >
591625 < div class ="ngm-panel-header ">
592626 ${ i18next . t ( 'lsb_share' ) }
593- < div
594- class ="ngm-close-icon "
595- @click =${ ( ) => ( this . activePanel = null ) }
596- > </ div >
627+ < div class ="ngm-close-icon " @click =${ this . handlePanelClose } > </ div >
597628 </ div >
598629 ${ this . activePanel !== 'share'
599630 ? ''
@@ -605,10 +636,7 @@ export class SideBar extends LitElementI18n {
605636 >
606637 < div class ="ngm-panel-header ">
607638 ${ i18next . t ( 'lsb_settings' ) }
608- < div
609- class ="ngm-close-icon "
610- @click =${ ( ) => ( this . activePanel = null ) }
611- > </ div >
639+ < div class ="ngm-close-icon " @click =${ this . handlePanelClose } > </ div >
612640 </ div >
613641 < div class ="toolbar-settings ">
614642 < div class ="inner-toolbar-settings ">
0 commit comments