Skip to content

Commit

Permalink
fix(compositions): Composition current base map visiblity
Browse files Browse the repository at this point in the history
Make sure layerdescriptor is defined before setting a visiblity
  • Loading branch information
FilipLeitner authored and jmacura committed Jul 29, 2024
1 parent 6b030ac commit e2f0696
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {Layer} from 'ol/layer';
import {
Observable,
catchError,
filter,
lastValueFrom,
of,
shareReplay,
switchMap,
take,
} from 'rxjs';
import {Source} from 'ol/source';
import {transformExtent} from 'ol/proj';
Expand Down Expand Up @@ -426,6 +428,33 @@ export class HsCompositionsParserService {
: true;

if (confirmed) {
/**
* If possible register layerAdditions subscribtion for a current_base_layer
* visiblity toggle.
*/
if (obj.current_base_layer && !obj.basemapComposition) {
this.hsEventBusService.layerAdditions
.pipe(
filter((l) => {
if (!l) {
return false;
}
const title = getTitle(l.layer);
return (
title === obj.current_base_layer.title ||
title === obj.current_base_layer
);
}),
take(1),
)
.subscribe((currentBaseLayer) => {
this.HsLayerManagerVisibilityService.changeBaseLayerVisibility(
true,
currentBaseLayer,
);
});
}

if (layers?.length > 0) {
layers.forEach((lyr) => {
// To suspend layerAdded events
Expand All @@ -440,26 +469,33 @@ export class HsCompositionsParserService {
this.hsLayerManagerService.updateLayerListPositions();
}

if (obj.current_base_layer) {
this.hsMapService
.getMap()
.getLayers()
.forEach((lyr: Layer<Source>) => {
if (
getTitle(lyr) == obj.current_base_layer.title ||
getTitle(lyr) == obj.current_base_layer
) {
const layerDescriptor =
this.hsLayerManagerService.getLayerDescriptorForOlLayer(
lyr,
/**
* basemapComposition doesnt trigger layerAdded events thus we need to
* make sure layeDescriptors are ready in a bit of a dirty way
*/
if (obj.current_base_layer && obj.basemapComposition) {
setTimeout(() => {
this.hsMapService
.getMap()
.getLayers()
.forEach((lyr: Layer<Source>) => {
const title = getTitle(lyr);
if (
title === obj.current_base_layer.title ||
title === obj.current_base_layer
) {
const layerDescriptor =
this.hsLayerManagerService.getLayerDescriptorForOlLayer(
lyr,
true,
);
this.HsLayerManagerVisibilityService.changeBaseLayerVisibility(
true,
layerDescriptor,
);
this.HsLayerManagerVisibilityService.changeBaseLayerVisibility(
true,
layerDescriptor,
);
}
});
}
});
}, 250);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,7 @@ export class HsLayerManagerService {
base = false,
): HsLayerDescriptor {
const layers = base ? 'baselayers' : 'layers';
const tmp = (this.data[layers] as Array<any>).filter(
(l) => l.layer == layer,
);
if (tmp.length > 0) {
return tmp[0];
}
return;
return (this.data[layers] as Array<any>).find((l) => l.layer == layer);
}

/**
Expand Down

0 comments on commit e2f0696

Please sign in to comment.