@@ -41,6 +41,18 @@ import { Modes } from './types';
4141
4242const SETTINGS_ID = '@jupytergis/jupytergis-core:jupytergis-settings' ;
4343
44+ const DEFAULT_SETTINGS : IJupyterGISSettings = {
45+ proxyUrl : 'https://corsproxy.io' ,
46+ leftPanelDisabled : false ,
47+ rightPanelDisabled : false ,
48+ layersDisabled : false ,
49+ stacBrowserDisabled : false ,
50+ filtersDisabled : false ,
51+ objectPropertiesDisabled : false ,
52+ annotationsDisabled : false ,
53+ identifyDisabled : false ,
54+ } ;
55+
4456export class JupyterGISModel implements IJupyterGISModel {
4557 constructor ( options : JupyterGISModel . IOptions ) {
4658 const { annotationModel, sharedModel, settingRegistry } = options ;
@@ -61,17 +73,7 @@ export class JupyterGISModel implements IJupyterGISModel {
6173 this . _pathChanged = new Signal < JupyterGISModel , string > ( this ) ;
6274 this . _settingsChanged = new Signal < JupyterGISModel , string > ( this ) ;
6375
64- this . _jgisSettings = {
65- proxyUrl : 'https://corsproxy.io' ,
66- leftPanelDisabled : false ,
67- rightPanelDisabled : false ,
68- layersDisabled : false ,
69- stacBrowserDisabled : false ,
70- filtersDisabled : false ,
71- objectPropertiesDisabled : false ,
72- annotationsDisabled : false ,
73- identifyDisabled : false ,
74- } ;
76+ this . _jgisSettings = { ...DEFAULT_SETTINGS } ;
7577
7678 this . initSettings ( ) ;
7779 }
@@ -92,17 +94,9 @@ export class JupyterGISModel implements IJupyterGISModel {
9294 this . _updateLocalSettings ( ) ;
9395 const newSettings = this . _jgisSettings ;
9496
95- const keys : ( keyof IJupyterGISSettings ) [ ] = [
96- 'proxyUrl' ,
97- 'leftPanelDisabled' ,
98- 'rightPanelDisabled' ,
99- 'layersDisabled' ,
100- 'stacBrowserDisabled' ,
101- 'filtersDisabled' ,
102- 'objectPropertiesDisabled' ,
103- 'annotationsDisabled' ,
104- 'identifyDisabled' ,
105- ] ;
97+ const keys = Object . keys (
98+ DEFAULT_SETTINGS ,
99+ ) as ( keyof IJupyterGISSettings ) [ ] ;
106100
107101 keys . forEach ( key => {
108102 if ( oldSettings [ key ] !== newSettings [ key ] ) {
@@ -112,36 +106,23 @@ export class JupyterGISModel implements IJupyterGISModel {
112106 } ) ;
113107 } catch ( error ) {
114108 console . error ( `Failed to load settings for ${ SETTINGS_ID } :` , error ) ;
115- this . _jgisSettings = {
116- proxyUrl : 'https://corsproxy.io' ,
117- leftPanelDisabled : false ,
118- rightPanelDisabled : false ,
119- layersDisabled : false ,
120- stacBrowserDisabled : false ,
121- filtersDisabled : false ,
122- objectPropertiesDisabled : false ,
123- annotationsDisabled : false ,
124- identifyDisabled : false ,
125- } ;
109+ this . _jgisSettings = { ...DEFAULT_SETTINGS } ;
126110 }
127111 }
128112 }
129113
130114 private _updateLocalSettings ( ) : void {
131115 const composite = this . _settings . composite ;
132116
133- this . _jgisSettings = {
134- proxyUrl : ( composite . proxyUrl as string ) ?? 'https://corsproxy.io' ,
135- leftPanelDisabled : ( composite . leftPanelDisabled as boolean ) ?? false ,
136- rightPanelDisabled : ( composite . rightPanelDisabled as boolean ) ?? false ,
137- layersDisabled : ( composite . layersDisabled as boolean ) ?? false ,
138- stacBrowserDisabled : ( composite . stacBrowserDisabled as boolean ) ?? false ,
139- filtersDisabled : ( composite . filtersDisabled as boolean ) ?? false ,
140- objectPropertiesDisabled :
141- ( composite . objectPropertiesDisabled as boolean ) ?? false ,
142- annotationsDisabled : ( composite . annotationsDisabled as boolean ) ?? false ,
143- identifyDisabled : ( composite . identifyDisabled as boolean ) ?? false ,
144- } ;
117+ this . _jgisSettings = Object . entries ( DEFAULT_SETTINGS ) . reduce (
118+ ( acc , [ key , defaultValue ] ) => {
119+ const typedKey = key as keyof IJupyterGISSettings ;
120+ const compositeValue = composite [ typedKey ] ;
121+ ( acc as any ) [ typedKey ] = compositeValue ?? defaultValue ;
122+ return acc ;
123+ } ,
124+ { } as typeof DEFAULT_SETTINGS ,
125+ ) ;
145126 }
146127
147128 get jgisSettings ( ) : IJupyterGISSettings {
0 commit comments