diff --git a/packages/common/src/lib/tool/shared/toolbox.ts b/packages/common/src/lib/tool/shared/toolbox.ts index 276fb717b..b91ec2665 100644 --- a/packages/common/src/lib/tool/shared/toolbox.ts +++ b/packages/common/src/lib/tool/shared/toolbox.ts @@ -26,6 +26,8 @@ export class Toolbox { * Active tool history. Useful for activating the previous tool. */ private activeToolHistory: string[] = []; + private previousToolName: string; + private currentToolName: string; /** * Tool store @@ -118,6 +120,10 @@ export class Toolbox { this.activateTool(previous); } + getCurrentPreviousToolName(): [string, string] { + return [this.previousToolName, this.currentToolName]; + } + /** * Activate the tool below, if any */ @@ -198,6 +204,10 @@ export class Toolbox { this.activeToolHistory = this.activeToolHistory .filter((name: string) => name !== tool.name) .concat([tool.name]); + + this.previousToolName = this.currentToolName; + this.currentToolName = + this.activeToolHistory[this.activeToolHistory.length - 1]; } } diff --git a/packages/geo/src/lib/catalog/catalog-library/catalog-library.component.ts b/packages/geo/src/lib/catalog/catalog-library/catalog-library.component.ts index 7bcfeb59e..dcce09cbb 100644 --- a/packages/geo/src/lib/catalog/catalog-library/catalog-library.component.ts +++ b/packages/geo/src/lib/catalog/catalog-library/catalog-library.component.ts @@ -22,7 +22,7 @@ import { } from '@igo2/common'; import { IgoLanguageModule } from '@igo2/core/language'; import { MessageService } from '@igo2/core/message'; -import { StorageService } from '@igo2/core/storage'; +import { StorageScope, StorageService } from '@igo2/core/storage'; import { ObjectUtils } from '@igo2/utils'; import { Observable, Subscription } from 'rxjs'; @@ -100,6 +100,13 @@ export class CatalogLibaryComponent implements OnInit, OnDestroy { this.storageService.set('addedCatalogs', catalogs); } + get selectedCatalogId() { + return this.storageService.get('selectedCatalogId', StorageScope.SESSION); + } + set selectedCatalogId(id) { + this.storageService.set('selectedCatalogId', id, StorageScope.SESSION); + } + constructor( private capabilitiesService: CapabilitiesService, private messageService: MessageService, @@ -116,6 +123,14 @@ export class CatalogLibaryComponent implements OnInit, OnDestroy { ngOnInit() { this.store.state.clear(); + if (this.selectedCatalogId) { + const selectedCatalog = this.store + .all() + .find((item) => item.id === this.selectedCatalogId); + if (selectedCatalog) { + this.onCatalogSelect(selectedCatalog); + } + } this.predefinedCatalogs = this.predefinedCatalogs.map((c) => { c.id = Md5.hashStr((c.type || 'wms') + standardizeUrl(c.url)) as string; c.title = c.title === '' || !c.title ? c.url : c.title; @@ -141,6 +156,7 @@ export class CatalogLibaryComponent implements OnInit, OnDestroy { }, true ); + this.selectedCatalogId = catalog.id; this.catalogSelectChange.emit({ selected: true, catalog }); } diff --git a/packages/integration/src/lib/catalog/catalog-library-tool/catalog-library-tool.component.ts b/packages/integration/src/lib/catalog/catalog-library-tool/catalog-library-tool.component.ts index 079e8db44..824b0604c 100644 --- a/packages/integration/src/lib/catalog/catalog-library-tool/catalog-library-tool.component.ts +++ b/packages/integration/src/lib/catalog/catalog-library-tool/catalog-library-tool.component.ts @@ -7,7 +7,7 @@ import { import { LAYER_PLUS_ICON, ToolComponent } from '@igo2/common'; import { EntityStore } from '@igo2/common'; -import { StorageService } from '@igo2/core/storage'; +import { StorageScope, StorageService } from '@igo2/core/storage'; import { Catalog, CatalogLibaryComponent, CatalogService } from '@igo2/geo'; import { take } from 'rxjs/operators'; @@ -49,6 +49,18 @@ export class CatalogLibraryToolComponent implements OnInit { */ @Input() predefinedCatalogs: Catalog[] = []; + set selectedCatalogId(id) { + this.storageService.set('selectedCatalogId', id, StorageScope.SESSION); + } + + get currentTool() { + return this.toolState.toolbox.getCurrentPreviousToolName()[1]; + } + + get lastTool() { + return this.toolState.toolbox.getCurrentPreviousToolName()[0]; + } + constructor( private catalogService: CatalogService, private catalogState: CatalogState, @@ -60,6 +72,10 @@ export class CatalogLibraryToolComponent implements OnInit { * @internal */ ngOnInit() { + if (this.lastTool === 'catalogBrowser' && this.currentTool === 'catalog') { + this.selectedCatalogId = null; + } + if (this.store.count === 0) { this.loadCatalogs(); }