Skip to content

Commit

Permalink
Merge pull request #822 from geonetwork/basemap-no-config
Browse files Browse the repository at this point in the history
Map: Add default baselayer to map when no mapConfig exists
  • Loading branch information
tkohr committed Mar 14, 2024
2 parents ecc0ab6 + 796704d commit 95b40cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libs/feature/map/src/lib/map-context/map-context.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,19 @@ describe('MapContextService', () => {
})
it('add layers', () => {
const layers = map.getLayers().getArray()
expect(layers.length).toEqual(3)
expect(layers.length).toEqual(4)
})
it('set view', () => {
const view = map.getView()
expect(view).toBeTruthy()
expect(view).toBeInstanceOf(View)
})
it('set first layer as baselayer', () => {
const baselayerUrls = (map.getLayers().item(0) as TileLayer<XYZ>)
.getSource()
.getUrls()
expect(baselayerUrls).toEqual(DEFAULT_BASELAYER_CONTEXT.urls)
})
})
describe('with config', () => {
const map = new Map({})
Expand Down Expand Up @@ -364,7 +370,7 @@ describe('MapContextService', () => {
})
it('add layers', () => {
const layers = map.getLayers().getArray()
expect(layers.length).toEqual(3)
expect(layers.length).toEqual(4)
})
it('set view', () => {
view = map.getView()
Expand Down
10 changes: 10 additions & 0 deletions libs/feature/map/src/lib/map-context/map-context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class MapContextService {
): Map {
if (mapConfig) {
mapContext = this.mergeMapConfigWithContext(mapContext, mapConfig)
} else {
mapContext.layers = this.addDefaultBaselayerContext(mapContext.layers)
}
if (
!mapContext.view?.extent &&
Expand Down Expand Up @@ -179,6 +181,14 @@ export class MapContextService {
return view
}

addDefaultBaselayerContext(
layers: MapContextLayerModel[]
): MapContextLayerModel[] {
return layers.includes(DEFAULT_BASELAYER_CONTEXT)
? layers
: [DEFAULT_BASELAYER_CONTEXT, ...layers]
}

mergeMapConfigWithContext(
mapContext: MapContextModel,
mapConfig: MapConfig
Expand Down

0 comments on commit 95b40cd

Please sign in to comment.