Skip to content

Commit

Permalink
Merge pull request #260 from stuartwoodman/AUS-3919-Save-BaseMap-With…
Browse files Browse the repository at this point in the history
…-State

AUS-3919-Persist-BaseMap
  • Loading branch information
vjf authored May 25, 2023
2 parents 188b395 + 2a5f6e5 commit 68873fa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@angular/platform-server": "^15.2.8",
"@angular/router": "^15.2.8",
"@auscope/angular-cesium": "^15.0.1",
"@auscope/portal-core-ui": "^3.0.4",
"@auscope/portal-core-ui": "^3.0.7",
"@csiro-geoanalytics/ng": "^2.5.0",
"@ng-bootstrap/ng-bootstrap": "^14.1.0",
"@ng-select/ng-select": "^10.0.4",
Expand Down
25 changes: 17 additions & 8 deletions src/app/menupanel/layerpanel/layerpanel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { UserStateService } from 'app/services/user/user-state.service';
import { Bookmark } from 'app/models/bookmark.model';
import { AuthService } from 'app/services/auth/auth.service';
import { LayerManagerService } from 'app/services/ui/layer-manager.service';
import { environment } from 'environments/environment';


// Filter modes available in the dropdown layer filter selector
Expand Down Expand Up @@ -121,14 +122,14 @@ export class LayerPanelComponent implements OnInit {
* "layerGroup" - an instance of this.layerGroups[key].value
*/
public isLayerGroupVisible(layerGroupValue): boolean {
if (layerGroupValue.expanded && layerGroupValue.loaded) {
for (const layer of layerGroupValue.loaded) {
if (layer.hide === false) {
return true;
}
}
if (layerGroupValue.expanded && layerGroupValue.loaded) {
for (const layer of layerGroupValue.loaded) {
if (layer.hide === false) {
return true;
}
}
return false;
}
return false;
}

/**
Expand All @@ -140,7 +141,7 @@ export class LayerPanelComponent implements OnInit {
// Re-order layers by index field provided index field is present (it won't be in older states)
const orderedLayerKeys: string[] = [];
for (const layer of Object.keys(layerStateObj)) {
if (layer.toLowerCase() !== 'map') {
if (layer.toLowerCase() !== 'map' && layer.toLowerCase() !== 'basemap') {
// Add layer at 'index' position of array, else just push
if (layerStateObj[layer].hasOwnProperty('index')) {
orderedLayerKeys[layerStateObj[layer].index] = layer;
Expand Down Expand Up @@ -177,6 +178,14 @@ export class LayerPanelComponent implements OnInit {
alert('The specified state could not be found, it may have been deleted or made private.');
}

// Set base map if "baseMap" key is present
if (layerStateObj.hasOwnProperty('baseMap')) {
const baseMap = environment.baseMapLayers.find(bm => bm.value === layerStateObj['baseMap']);
if (baseMap) {
this.csMapService.setBaseMapLayer(baseMap.viewValue);
}
}

// Load state layers in corresponding FilterPanels
setTimeout(() => {
this.loadFilterPanelLayersFromState(layerStateObj);
Expand Down
9 changes: 8 additions & 1 deletion src/app/services/user/user-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AuscopeApiService } from '../api/auscope-api.service';
import { CsMapService, ManageStateService } from '@auscope/portal-core-ui';
import { v4 as uuidv4 } from 'uuid';
import { HttpResponse } from '@angular/common/http';
import { environment } from 'environments/environment';


@Injectable()
Expand Down Expand Up @@ -155,9 +156,15 @@ export class UserStateService {
public addState(name: string, description: string, isPublic: boolean): Observable<any> {
const id = uuidv4();
const state = this.manageStateService.getState();
// Add the base map to the state
const baseMapImagery = this.csMapService.getViewer().baseLayerPicker.viewModel.selectedImagery;
const baseMap = environment.baseMapLayers.find(bm => bm.viewValue === baseMapImagery.name);
if (baseMap) {
state.baseMap = baseMap.value;
}
// Add the index position of each layer to the state object
for (const layerKey of Object.keys(state)) {
if (layerKey.toLowerCase() !== 'map') {
if (layerKey.toLowerCase() !== 'map' && layerKey.toLowerCase() !== 'basemap') {
const layerIndex = this.csMapService.getLayerIndex(layerKey);
state[layerKey].index = layerIndex;
}
Expand Down

0 comments on commit 68873fa

Please sign in to comment.