Skip to content

Commit

Permalink
VectorLayerService: fix _updateStyle() when only hidden layers are pr…
Browse files Browse the repository at this point in the history
…esent (#2839)
  • Loading branch information
taulinger authored Jan 23, 2025
1 parent 56a3568 commit 98cd73a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/modules/olMap/services/VectorLayerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class VectorLayerService {
styleService.updateStyle(olFeature, olMap, {
visible: olLayer.getVisible(),
// we check if the layer representing this olLayer is the topmost layer of all unhidden layers
top: active.filter(({ constraints: { hidden } }) => !hidden).pop().id === olLayer.get('id'),
top: active.filter(({ constraints: { hidden } }) => !hidden).pop()?.id === olLayer.get('id'),
opacity: olLayer.getOpacity()
});
}
Expand Down
22 changes: 22 additions & 0 deletions test/modules/olMap/services/VectorLayerService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,28 @@ describe('VectorLayerService', () => {

expect(styleServiceSpy).toHaveBeenCalledWith(olFeature, olMap, updateProperties);
});

it('calls #updateStyle of the underlying StyleService ignoring hidden layers (only one hidden layer present)', () => {
const id = 'id';
const state = {
layers: {
active: [
{ ...createDefaultLayer('hiddenLayer'), constraints: { hidden: true } } //topmost layer is a hidden layer
]
}
};
setup(state);
const updateProperties = { visible: false, top: false, opacity: 0.5 };
const olMap = new Map();
const olFeature = new Feature();
const olSource = new VectorSource();
const olLayer = new VectorLayer({ id: id, source: olSource, visible: updateProperties.visible, opacity: updateProperties.opacity });
const styleServiceSpy = spyOn(styleService, 'updateStyle');

instanceUnderTest._updateStyle(olFeature, olLayer, olMap);

expect(styleServiceSpy).toHaveBeenCalledWith(olFeature, olMap, updateProperties);
});
});

describe('sanitizeStyles', () => {
Expand Down

0 comments on commit 98cd73a

Please sign in to comment.