77 ColorFilters ,
88 Context ,
99 Dataset ,
10+ DisplayConfiguration ,
1011 LayerCollection ,
1112 NetCDFData ,
1213 NetCDFLayer ,
@@ -33,6 +34,10 @@ export default class MapStore {
3334
3435 public static proModeButtonEnabled = ref ( true ) ;
3536
37+ public static displayConfiguration : Ref < DisplayConfiguration > = ref (
38+ { default_displayed_layers : [ ] , enabled_ui : [ 'Collections' , 'Datasets' , 'Metadata' ] , default_tab : 'Scenarios' } ,
39+ ) ;
40+
3641 // Ability to toggle proMode so Staff users can see what other users see.
3742 public static proMode = computed ( ( ) => MapStore . userIsStaff . value && MapStore . proModeButtonEnabled . value ) ;
3843
@@ -103,10 +108,57 @@ export default class MapStore {
103108 MapStore . mapLayersByDataset [ datasetId ] = await UVdatApi . getDatasetLayers ( datasetId ) ;
104109 }
105110
111+ public static async getDisplayConfiguration ( initial = false ) {
112+ MapStore . displayConfiguration . value = await UVdatApi . getDisplayConfiguration ( ) ;
113+ // Loading first time process default map layers
114+ if ( initial && MapStore . displayConfiguration . value . default_displayed_layers . length ) {
115+ const datasetIds = MapStore . displayConfiguration . value . default_displayed_layers . map ( ( item ) => item . dataset_id ) ;
116+ const datasetIdLayers = await UVdatApi . getDatasetsLayers ( datasetIds ) ;
117+ const layerByDataset : Record < number , ( VectorMapLayer | RasterMapLayer | NetCDFData ) [ ] > = { } ;
118+ const toggleLayers : ( VectorMapLayer | RasterMapLayer | NetCDFLayer ) [ ] = [ ] ;
119+ const enabledLayers = MapStore . displayConfiguration . value . default_displayed_layers ;
120+ datasetIdLayers . forEach ( ( item ) => {
121+ if ( item . dataset_id !== undefined ) {
122+ if ( layerByDataset [ item . dataset_id ] === undefined ) {
123+ layerByDataset [ item . dataset_id ] = [ ] ;
124+ }
125+ layerByDataset [ item . dataset_id ] . push ( item ) ;
126+ }
127+ enabledLayers . forEach ( ( enabledLayer ) => {
128+ if ( item . type === 'netcdf' ) {
129+ if ( enabledLayer . dataset_id === item . dataset_id ) {
130+ const netCDFLayers = ( ( item as NetCDFData ) . layers ) ;
131+ for ( let i = 0 ; i < netCDFLayers . length ; i += 1 ) {
132+ const layer = netCDFLayers [ i ] ;
133+ if ( layer . id === enabledLayer . id ) {
134+ toggleLayers . push ( layer ) ;
135+ }
136+ }
137+ }
138+ } else if (
139+ enabledLayer . type === item . type
140+ && enabledLayer . id === item . id
141+ && enabledLayer . dataset_id === item . dataset_id ) {
142+ toggleLayers . push ( item ) ;
143+ }
144+ } ) ;
145+ } ) ;
146+ Object . keys ( layerByDataset ) . forEach ( ( datasetIdKey ) => {
147+ const datasetId = parseInt ( datasetIdKey , 10 ) ;
148+ if ( ! Number . isNaN ( datasetId ) ) {
149+ MapStore . mapLayersByDataset [ datasetId ] = layerByDataset [ datasetId ] ;
150+ }
151+ } ) ;
152+ // Now we enable these default layers
153+ return toggleLayers ;
154+ }
155+ return [ ] ;
156+ }
157+
106158 public static mapLayerFeatureGraphs = computed ( ( ) => {
107159 const foundMapLayerFeatureGraphs : { name : string , id : number ; graphs : VectorFeatureTableGraph [ ] } [ ] = [ ] ;
108160 MapStore . selectedVectorMapLayers . value . forEach ( ( item ) => {
109- if ( item . default_style . mapLayerFeatureTableGraphs && item . default_style . mapLayerFeatureTableGraphs . length ) {
161+ if ( item . default_style ? .mapLayerFeatureTableGraphs && item . default_style . mapLayerFeatureTableGraphs . length ) {
110162 foundMapLayerFeatureGraphs . push ( {
111163 name : item . name ,
112164 id : item . id ,
@@ -133,7 +185,7 @@ export default class MapStore {
133185 public static mapLayerVectorSearchable = computed ( ( ) => {
134186 const foundMapLayerSearchable : { name : string , id : number ; searchSettings : SearchableVectorData } [ ] = [ ] ;
135187 MapStore . selectedVectorMapLayers . value . forEach ( ( item ) => {
136- if ( item . default_style . searchableVectorFeatureData ) {
188+ if ( item . default_style ? .searchableVectorFeatureData ) {
137189 foundMapLayerSearchable . push ( {
138190 name : item . name ,
139191 id : item . id ,
0 commit comments