Skip to content

Commit

Permalink
Merge pull request #4183 from rldhont/fix-display-in-legend-printing
Browse files Browse the repository at this point in the history
[Bugfix] JS: for layer not displayd in legend the visibility is equal to checked
  • Loading branch information
rldhont authored Feb 9, 2024
2 parents 1a1e7b9 + b9db1d0 commit 986838d
Show file tree
Hide file tree
Showing 7 changed files with 4,826 additions and 2 deletions.
13 changes: 11 additions & 2 deletions assets/src/modules/state/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class LayerItemState extends EventDispatcher {
this._minScaleDenominator = null;
this._maxScaleDenominator = null;
this._checked = this._parentGroup == null ? true : false;
this._visibility = null;
this._visibility = this._parentGroup == null ? true : null;
this._opacity = 1;
this._inGroupAsLayer = (this._parentGroup !== null
&& (this._parentGroup.groupAsLayer || this._parentGroup.isInGroupAsLayer)) ? true : false;
Expand Down Expand Up @@ -279,7 +279,11 @@ export class LayerItemState extends EventDispatcher {
// Set new value
this._checked = newVal;
// Propagation to parent if checked
if (this._checked && this._parentGroup != null && !this.isInGroupAsLayer) {
if (this._checked
&& this._parentGroup != null // if item has a parent
&& this.displayInLegend // if the item is display in legend
&& !this.isInGroupAsLayer // if the item is not in a group as layer
) {
this._parentGroup.checked = newVal;
// If the parent is mutually exclusive, unchecked other layer
if (this._parentGroup.mutuallyExclusive) {
Expand Down Expand Up @@ -484,6 +488,11 @@ export class LayerItemState extends EventDispatcher {
}
return this._visibility;
}
// if the item is not displayed in the legend
// the visibility depends on the checked state
else if (!this.displayInLegend) {
this._visibility = this._checked;
}
// if the parent layer tree group is visible
// the visibility depends if the layer tree item is checked
// else the layer tree item is not visible
Expand Down
40 changes: 40 additions & 0 deletions tests/end2end/playwright/display_in_layer_tree.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @ts-check
const { test, expect } = require('@playwright/test');

test.describe('Display in layer tree', () => {

test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map?repository=testsrepository&project=display_in_legend';
await page.goto(url, { waitUntil: 'networkidle' });
});

test('display in layer tree unchecked => layer not visible in layer tree and layer in print request', async ({ page }) => {
// layer not visible in layer tree
await expect(page.getByTestId('polygons')).toHaveCount(0);

// layer in print request
const getPrintRequest = request => {
const postData = request.postData();
expect(postData).toContain('SERVICE=WMS')
expect(postData).toContain('REQUEST=GetPrint')
expect(postData).toContain('map0%3ALAYERS=project-background-color%2Cpolygons')
};

await page.locator('#button-print').click();

page.once('request', getPrintRequest);
await page.locator('#print-launch').click();

await page.getByTestId('Shapefiles').locator('input').first().uncheck();
page.once('request', getPrintRequest);
await page.locator('#print-launch').click();

await page.getByTestId('townhalls_EPSG2154').locator('input').first().check();
page.once('request', getPrintRequest);
await page.locator('#print-launch').click();

await page.getByTestId('Shapefiles').locator('input').first().uncheck();
page.once('request', getPrintRequest);
await page.locator('#print-launch').click();
});
})
Loading

1 comment on commit 986838d

@3liz-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest weekly run of end2end "playwright" tests failed with this latest commit on the branch release_3_6 😣

CC @nboisteault and @Gustry, please have a look to the logs. Maybe it's a false positive ?

Visit https://github.com/3liz/lizmap-web-client/actions/runs/7866868314

Please sign in to comment.