Hajk icon indicating copy to clipboard operation
Hajk copied to clipboard

OpenLayers HIDPI often causes GeoServer cache to fail.

Open jesade-vbg opened this issue 4 years ago • 11 comments

Turning on HIDPI changes the way OpenLayer requests tiles etc.

You can specify diffrent dpi:s in geoserver, 90, 180 etc. But OpenLayers requests the exact dpi as the device has, for example 72, 113, 155, 189 etc etc. Confirmed in docs: HiDPI >

Use the ol/Map#pixelRatio value when requesting the image from the remote server.

If you're lucky, it requests 180 as it's set up in GeoServer.

For example, OpenLayers adds this to the Url:

WIDTH=538
HEIGHT=538
FORMAT_OPTIONS=dpi:189

Resulting in this header from geoserver: geowebcache-cache-result: MISS === slow

Could we somehow force OpenLayers to request (as an example)?:

FORMAT_OPTIONS=dpi:90
WIDTH=256
HEIGHT=256

or double resolution for hidpi devices:

FORMAT_OPTIONS=dpi:180
WIDTH=512
HEIGHT=512

Everyone wants fast maps and sharp "crisp" maps. It would be nice to be able to deliver both.

jesade-vbg avatar Nov 19 '21 12:11 jesade-vbg

Spontaneous thought: Combine custom imageLoadFunction (or similar) with window.devicePixelRatio

jesade-vbg avatar Nov 19 '21 12:11 jesade-vbg

Quick test: Turned off HiDPI and Forced 180dpi 512x512 using tileLoadFunction on the left. (Chrome device emulator).

image

jesade-vbg avatar Nov 19 '21 14:11 jesade-vbg

I think the idea of forcing specific DPI:s is good! Would 90 and 180 be enough (one for ordinary devices and one for highDPI-devices)? Or do we want more?

Hallbergs avatar Nov 22 '21 10:11 Hallbergs

Maybe it could be configured like (devicePixelRatio: dpi): { "1.0": 90, "2.0": 180, }

jesade-vbg avatar Nov 22 '21 11:11 jesade-vbg

Ahh very nice! I like it!

Hallbergs avatar Nov 23 '21 06:11 Hallbergs

POC https://github.com/hajkmap/Hajk/tree/feature/915-custom-hdpi

jesade-vbg avatar Jan 28 '22 08:01 jesade-vbg

The code looks great, nicely commented and easy to understand. Will give it a go next week!

Hallbergs avatar Jan 28 '22 08:01 Hallbergs

Thanx! Don't forget to add useCustomHdpi: true in the layers config. I just noticed I forgot the first 'I' in hidpi :)

jesade-vbg avatar Jan 28 '22 09:01 jesade-vbg

@jesade-vbg: Note: dpi can't be float, round up.

jesade-vbg avatar Feb 01 '22 09:02 jesade-vbg

Added this to wms layer admin image

jesade-vbg avatar Jun 10 '22 08:06 jesade-vbg

Problems occur when having pixelRatio 3. ratio 1 and 2 seems to be working fine but 3 causes cache MISS in geoserver. geowebcache-cache-result:MISS geowebcache-miss-reason:request does not align to grid(s)

This also happens with the hidpi = true setting when requesting pixelRatio 3 270dpi, so its not my code.

I've found out that alot of people is having the exact same problem with openlayers + geoserver + pixelRatio 3. Feels like a rounding error. Still investigating........

If anyone has any idea, please let me know.

jesade-vbg avatar Jun 27 '22 08:06 jesade-vbg