Skip to content

Commit d025366

Browse files
committed
[Bugfix] Disbale High DPI support
OpenLayers supports High DPI rendering. For WMS layers, it requested to the server images with Higher DPI that depends on device pixel ratio. With High DPI enabled, more images are requested and the rendering of QGIS label is too small. We prefer to disble High DPI support. Funded by Valabre
1 parent 519bb4e commit d025366

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

assets/src/modules/map.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ export default class map extends olMap {
120120
});
121121
};
122122

123+
// Disable High DPI for requests
124+
this._hidpi = false;
125+
123126
// Ratio between WMS single tiles and map viewport
124127
this._WMSRatio = 1.1;
125128

@@ -129,8 +132,8 @@ export default class map extends olMap {
129132
mainLizmap.initialConfig.options.wmsMaxHeight,
130133
];
131134

132-
// Get pixel ratio
133-
const pixelRatio = this.pixelRatio_;
135+
// Get pixel ratio, if High DPI is disabled do not use device pixel ratio
136+
const pixelRatio = this._hidpi ? this.pixelRatio_ : 1;
134137

135138
const useTileWms = this.getSize().reduce(
136139
(r /*accumulator*/, x /*currentValue*/, i /*currentIndex*/) => r || Math.ceil(x*this._WMSRatio*pixelRatio) > wmsMaxSize[i],
@@ -245,6 +248,7 @@ export default class map extends olMap {
245248
url: mainLizmap.serviceURL,
246249
serverType: 'qgis',
247250
ratio: WMSRatio,
251+
hidpi: this._hidpi,
248252
params: {
249253
LAYERS: node.wmsName,
250254
FORMAT: node.layerConfig.imageFormat,
@@ -278,7 +282,7 @@ export default class map extends olMap {
278282
TILED: 'true'
279283
},
280284
wrapX: false, // do not reused across the 180° meridian.
281-
//hidpi: false, pixelRatio is used in useTileWms and customTileGrid definition
285+
hidpi: this._hidpi, // pixelRatio is used in useTileWms and customTileGrid definition
282286
})
283287
});
284288

@@ -435,6 +439,7 @@ export default class map extends olMap {
435439
projection: qgisProjectProjection,
436440
serverType: 'qgis',
437441
ratio: this._WMSRatio,
442+
hidpi: this._hidpi,
438443
params: {
439444
LAYERS: baseLayerState.itemState.wmsName,
440445
FORMAT: baseLayerState.layerConfig.imageFormat,
@@ -459,7 +464,7 @@ export default class map extends olMap {
459464
TILED: 'true'
460465
},
461466
wrapX: false, // do not reused across the 180° meridian.
462-
//hidpi: false, pixelRatio is used in useTileWms and customTileGrid definition
467+
hidpi: this._hidpi, // pixelRatio is used in useTileWms and customTileGrid definition
463468
})
464469
});
465470
}

tests/end2end/playwright/viewport.spec.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
import { test, expect } from '@playwright/test';
23

34
test.describe('Viewport devicePixelRatio 1', () => {
@@ -34,9 +35,9 @@ test.describe('Viewport devicePixelRatio 1', () => {
3435
await page.waitForTimeout(1000);
3536

3637
// Check that the WMS Max Size has been well overwrite
37-
expect(await page.evaluate(() => lizMap.mainLizmap.initialConfig.options.wmsMaxHeight)).toBe(950);
38+
expect(await page.evaluate(() => globalThis.lizMap.mainLizmap.initialConfig.options.wmsMaxHeight)).toBe(950);
3839
expect(await page.evaluate(() => window.devicePixelRatio)).toBe(1);
39-
expect(await page.evaluate(() => lizMap.mainLizmap.map.getSize())).toStrictEqual([870, 575]);
40+
expect(await page.evaluate(() => globalThis.lizMap.mainLizmap.map.getSize())).toStrictEqual([870,575]);
4041
await page.unroute('**/service/getProjectConfig*')
4142

4243
// Catch GetMaps request;
@@ -67,6 +68,7 @@ test.describe('Viewport devicePixelRatio 1', () => {
6768
})
6869

6970
test.describe('Viewport devicePixelRatio 2', () => {
71+
// Force device pixel ratio to 2
7072
test.use({
7173
deviceScaleFactor: 2,
7274
});
@@ -103,19 +105,20 @@ test.describe('Viewport devicePixelRatio 2', () => {
103105
await page.waitForTimeout(1000);
104106

105107
// Check that the WMS Max Size has been well overwrite
106-
expect(await page.evaluate(() => lizMap.mainLizmap.initialConfig.options.wmsMaxHeight)).toBe(1900);
108+
expect(await page.evaluate(() => globalThis.lizMap.mainLizmap.initialConfig.options.wmsMaxHeight)).toBe(1900);
107109
expect(await page.evaluate(() => window.devicePixelRatio)).toBe(2);
108-
expect(await page.evaluate(() => lizMap.mainLizmap.map.getSize())).toStrictEqual([870, 620]);
110+
expect(await page.evaluate(() => globalThis.lizMap.mainLizmap.map.getSize())).toStrictEqual([870,620]);
109111
await page.unroute('**/service/getProjectConfig*')
110112

111113
// Catch GetMaps request;
114+
// Because we disable High DPI, the OL pixel ratio is forced to 1 even if the device pixel ratio is 2
112115
let GetMaps = [];
113116
await page.route('**/service*', async route => {
114117
const request = route.request();
115118
if (request.url().includes('GetMap')) {
116119
GetMaps.push(request.url());
117120
}
118-
}, { times: 4 });
121+
}, {times: 1}); // No tiles, if High DPI is enabled we got 4 tiles
119122

120123
// Activate world layer
121124
await page.getByLabel('world').check();
@@ -124,11 +127,11 @@ test.describe('Viewport devicePixelRatio 2', () => {
124127
await page.waitForTimeout(1000);
125128

126129
// Check GetMap requests
127-
expect(GetMaps).toHaveLength(4);
128-
for (const GetMap of GetMaps) {
129-
expect(GetMap).toContain('&WIDTH=870&')
130-
expect(GetMap).toContain('&HEIGHT=620&')
131-
expect(GetMap).toContain('&DPI=180&')
130+
expect(GetMaps).toHaveLength(1); // No tiles, if High DPI is enabled we got 4 tiles
131+
for(const GetMap of GetMaps) {
132+
expect(GetMap).toContain('&WIDTH=957&')
133+
expect(GetMap).toContain('&HEIGHT=682&')
134+
expect(GetMap).toContain('&DPI=96&')
132135
}
133136
await page.unroute('**/service*')
134137
})
@@ -164,11 +167,11 @@ test.describe('Viewport mobile', () => {
164167
await expect(await page.locator('#right-dock')).toBeInViewport();
165168

166169
// Choose a feature and check getFeatureInfo
167-
let getFeatureInfoRequestPromise = page.waitForRequest(request => request.method() === 'POST' && request?.postData().includes('GetFeatureInfo'));
170+
let getFeatureInfoRequestPromise = page.waitForRequest(request => request.method() === 'POST' && request.postData().includes('GetFeatureInfo'));
168171
await page.locator('#liz-atlas-select').selectOption('2');
169172
let getFeatureInfoRequest = await getFeatureInfoRequestPromise;
170173
let getFeatureInfoResponse = await getFeatureInfoRequest.response();
171-
await expect(await getFeatureInfoResponse.headerValue('content-type')).toContain('text/html');
174+
await expect(await getFeatureInfoResponse?.headerValue('content-type')).toContain('text/html');
172175
await expect(await page.locator('#liz-atlas-item-detail .lizmapPopupContent')).toBeInViewport();
173176
await expect(await page.locator('#liz-atlas-item-detail .lizmapPopupContent')).toContainText('MOSSON');
174177
// Close atlas

0 commit comments

Comments
 (0)