From cf744e853e3cd7275b2312a2e0df5f1b09b5085c Mon Sep 17 00:00:00 2001 From: Romuald Caplier Date: Wed, 29 May 2024 17:14:00 +0200 Subject: [PATCH] fix(datahub): map is reseted to an empty map when the MapViewComponent is opened. --- .../record-apis/record-apis.component.spec.ts | 2 ++ .../map/src/lib/utils/map-utils.service.ts | 2 +- .../lib/map-view/map-view.component.spec.ts | 26 ++++++++++++------ .../src/lib/map-view/map-view.component.ts | 5 ++++ .../docker-entrypoint-initdb.d/dump | Bin 460487 -> 460488 bytes 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/apps/datahub/src/app/record/record-apis/record-apis.component.spec.ts b/apps/datahub/src/app/record/record-apis/record-apis.component.spec.ts index 28c7318b45..699b7e7b08 100644 --- a/apps/datahub/src/app/record/record-apis/record-apis.component.spec.ts +++ b/apps/datahub/src/app/record/record-apis/record-apis.component.spec.ts @@ -4,6 +4,7 @@ import { TranslateModule } from '@ngx-translate/core' import { DatasetServiceDistribution } from '@geonetwork-ui/common/domain/model/record' import { MdViewFacade } from '@geonetwork-ui/feature/record' import { BehaviorSubject } from 'rxjs' +import { NO_ERRORS_SCHEMA } from '@angular/core' class MdViewFacadeMock { selectedApiLink$ = new BehaviorSubject([]) @@ -23,6 +24,7 @@ describe('RecordApisComponent', () => { await TestBed.configureTestingModule({ declarations: [RecordApisComponent], imports: [TranslateModule.forRoot()], + schemas: [NO_ERRORS_SCHEMA], providers: [ { provide: MdViewFacade, diff --git a/libs/feature/map/src/lib/utils/map-utils.service.ts b/libs/feature/map/src/lib/utils/map-utils.service.ts index a99f1ee611..1f0feb2d06 100644 --- a/libs/feature/map/src/lib/utils/map-utils.service.ts +++ b/libs/feature/map/src/lib/utils/map-utils.service.ts @@ -26,7 +26,6 @@ import { MapContextLayerWmsModel, } from '../map-context/map-context.model' import Collection from 'ol/Collection' -import { defaults as defaultControls } from 'ol/control.js' import MapBrowserEvent from 'ol/MapBrowserEvent' import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record' import { ProxyService } from '@geonetwork-ui/util/shared' @@ -34,6 +33,7 @@ import { WmsEndpoint, WmtsEndpoint } from '@camptocamp/ogc-client' import { LONLAT_CRS_CODES } from '../constant/projections' import { fromEPSGCode, register } from 'ol/proj/proj4' import proj4 from 'proj4/dist/proj4' +import { defaults as defaultControls } from 'ol/control/defaults' const FEATURE_PROJECTION = 'EPSG:3857' const DATA_PROJECTION = 'EPSG:4326' diff --git a/libs/feature/record/src/lib/map-view/map-view.component.spec.ts b/libs/feature/record/src/lib/map-view/map-view.component.spec.ts index 587b0d73e9..16cd5e363f 100644 --- a/libs/feature/record/src/lib/map-view/map-view.component.spec.ts +++ b/libs/feature/record/src/lib/map-view/map-view.component.spec.ts @@ -40,6 +40,15 @@ import { Interaction } from 'ol/interaction' import { DataService } from '@geonetwork-ui/feature/dataviz' import { DatasetDistribution } from '@geonetwork-ui/common/domain/model/record' +const recordMapExtent = [-30, -60, 30, 60] + +const emptyMapContext = { + layers: [], + view: { + extent: recordMapExtent, + }, +} as MapContextModel + const mapConfigMock = { MAX_ZOOM: 10, MAX_EXTENT: [-418263.418776, 5251529.591305, 961272.067714, 6706890.609855], @@ -72,6 +81,7 @@ class MdViewFacadeMock { } class MapUtilsServiceMock { + createEmptyMap = jest.fn() getLayerExtent = jest.fn(function () { return new Promise((resolve, reject) => { this._resolve = resolve @@ -87,7 +97,7 @@ class MapUtilsServiceMock { }) }) prioritizePageScroll = jest.fn() - getRecordExtent = jest.fn(() => [-30, -60, 30, 60]) + getRecordExtent = jest.fn(() => recordMapExtent) _returnImmediately = true _resolve = null _reject = null @@ -559,8 +569,8 @@ describe('MapViewComponent', () => { tick(50) discardPeriodicTasks() })) - it('does not emit immediately a map context', () => { - expect(mapComponent.context).toBe(null) + it('emit an empty map context', () => { + expect(mapComponent.context).toEqual(emptyMapContext) }) it('shows a loading indicator', () => { expect( @@ -677,8 +687,8 @@ describe('MapViewComponent', () => { fixture.detectChanges() })) describe('while extent is not ready', () => { - it('does not emit a map context', () => { - expect(mapComponent.context).toBeFalsy() + it('emit a empty map context', () => { + expect(mapComponent.context).toEqual(emptyMapContext) }) }) describe('when extent is received', () => { @@ -726,7 +736,7 @@ describe('MapViewComponent', () => { }, ], view: { - extent: [-30, -60, 30, 60], + extent: recordMapExtent, }, }) }) @@ -754,7 +764,7 @@ describe('MapViewComponent', () => { type: 'wms', }, ], - view: { extent: [-30, -60, 30, 60] }, + view: { extent: recordMapExtent }, }) }) it('provides selected link to the external viewer component', () => { @@ -768,7 +778,7 @@ describe('MapViewComponent', () => { }) describe('selecting another layer, while extent is not ready', () => { beforeEach(fakeAsync(() => { - mapUtilsService._resolve([-30, -60, 30, 60]) + mapUtilsService._resolve(recordMapExtent) tick() dropdownComponent.selectValue.emit(0) tick() diff --git a/libs/feature/record/src/lib/map-view/map-view.component.ts b/libs/feature/record/src/lib/map-view/map-view.component.ts index 565d59eaca..87e40b8fd8 100644 --- a/libs/feature/record/src/lib/map-view/map-view.component.ts +++ b/libs/feature/record/src/lib/map-view/map-view.component.ts @@ -34,6 +34,7 @@ import { distinctUntilChanged, finalize, map, + startWith, switchMap, tap, } from 'rxjs/operators' @@ -122,6 +123,10 @@ export class MapViewComponent implements OnInit, OnDestroy { }) ) ), + startWith({ + layers: [], + view: {}, + } as MapContextModel), withLatestFrom(this.mdViewFacade.metadata$), map(([context, metadata]) => { if (context.view.extent) return context diff --git a/support-services/docker-entrypoint-initdb.d/dump b/support-services/docker-entrypoint-initdb.d/dump index 8b4e5884f543706224bce956873974cb65ffcb84..0a433c68ec163548b3136110c93fbcc891a0406e 100644 GIT binary patch delta 1543 zcmYjQZBP|u6yE1@@j@A>a1j&%6^%@A@ABTgdu=pLP$bdoM_@7~n(6ovG&KUFrK5u~ zX?|XH5mC`JE45@c=Rj)qVTMyvqgGB+In$3aH8U#5)YQ&d{Nc{L?|b&ybKY~F^PK&B zO?vy9bUiYrpd^9>%^L?mwpV1+qPuz|wT$}aS6EK!g-790x>NYu zFg^{Z?&3^%mC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