Skip to content

Commit

Permalink
fix(datahub): map is reseted to an empty map when the MapViewComponen…
Browse files Browse the repository at this point in the history
…t is opened.
  • Loading branch information
Romuald Caplier authored and jahow committed Jun 7, 2024
1 parent 3e7f46f commit cf744e8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
Expand All @@ -23,6 +24,7 @@ describe('RecordApisComponent', () => {
await TestBed.configureTestingModule({
declarations: [RecordApisComponent],
imports: [TranslateModule.forRoot()],
schemas: [NO_ERRORS_SCHEMA],
providers: [
{
provide: MdViewFacade,
Expand Down
2 changes: 1 addition & 1 deletion libs/feature/map/src/lib/utils/map-utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ 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'
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'
Expand Down
26 changes: 18 additions & 8 deletions libs/feature/record/src/lib/map-view/map-view.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -72,6 +81,7 @@ class MdViewFacadeMock {
}

class MapUtilsServiceMock {
createEmptyMap = jest.fn()
getLayerExtent = jest.fn(function () {
return new Promise((resolve, reject) => {
this._resolve = resolve
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -726,7 +736,7 @@ describe('MapViewComponent', () => {
},
],
view: {
extent: [-30, -60, 30, 60],
extent: recordMapExtent,
},
})
})
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions libs/feature/record/src/lib/map-view/map-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
distinctUntilChanged,
finalize,
map,
startWith,
switchMap,
tap,
} from 'rxjs/operators'
Expand Down Expand Up @@ -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
Expand Down
Binary file modified support-services/docker-entrypoint-initdb.d/dump
Binary file not shown.

0 comments on commit cf744e8

Please sign in to comment.