Skip to content

Commit

Permalink
Selected basemap is saved with the state/permanent link.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwoodman committed May 15, 2023
1 parent 5381e87 commit d7d5415
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
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 d7d5415

Please sign in to comment.