Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenLayers HIDPI often causes GeoServer cache to fail. #915

Closed
jesade-vbg opened this issue Nov 19, 2021 · 11 comments · Fixed by #1141
Closed

OpenLayers HIDPI often causes GeoServer cache to fail. #915

jesade-vbg opened this issue Nov 19, 2021 · 11 comments · Fixed by #1141

Comments

@jesade-vbg
Copy link
Contributor

jesade-vbg commented Nov 19, 2021

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
Copy link
Contributor Author

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

@jesade-vbg
Copy link
Contributor Author

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

image

@Hallbergs
Copy link
Member

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?

@jesade-vbg
Copy link
Contributor Author

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

@Hallbergs
Copy link
Member

Ahh very nice! I like it!

@Hallbergs Hallbergs added this to the 3.x milestone Nov 23, 2021
@jesade-vbg
Copy link
Contributor Author

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

@Hallbergs
Copy link
Member

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

@jesade-vbg
Copy link
Contributor Author

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

@jesade-vbg
Copy link
Contributor Author

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

@jesade-vbg
Copy link
Contributor Author

Added this to wms layer admin
image

@jesade-vbg
Copy link
Contributor Author

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 jesade-vbg linked a pull request Aug 17, 2022 that will close this issue
@jesade-vbg jesade-vbg modified the milestones: 3.x, 3.11 Sep 1, 2022
@jacobwod jacobwod closed this as completed Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants