question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use "window.devicePixelRatio" instead of "L.Browser.Retina ? 2 : 1"

See original GitHub issue

Reading over #8185, I noticed the code used to set the pixel size of the canvas in L.Canvas: https://github.com/Leaflet/Leaflet/blob/0f987feda97584ef25b5e64fc166ed2f1ff581ae/src/layer/vector/Canvas.js#L108-L114

The problem with this approach is that Retina displays are not always 2 screen/device pixels per 1 CSS pixel - nowadays we can have values of window.devicePixelRatio of 3, 4, 1.5, 0.5 or anything in between. Specially when considering that mainstream browsers change the value of window.devicePixelRatio when zooming the whole interface with <kbd>Ctrl</kbd>+<kbd>+</kbd>/<kbd>Ctrl</kbd>+<kbd>-</kbd>.

I propose deprecating all instances of L.Browser.Retina ? 2 : 1 and similar approaches: using window.devicePixelRatio instead should just work better. Primarily for the L.Canvas renderer, to provide crisper rendering; but also for the mousewheel zoom factor (after some testing).

Doing this would break IE10 compatibility, and I consider that the chances of breaking something else in the way are quite high.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jonkoopscommented, Apr 25, 2022

Let’s start using the accepted label for v2 proposals we can all agree on, it will make it easier to create an overview of the changes we’d like to land.

0reactions
mournercommented, Apr 27, 2022

I propose deprecating all instances of L.Browser.Retina ? 2 : 1 and similar approaches

Looks like it’s only used in two instances 1) Canvas, 2) 2x tiles if retina. We want to keep the 2nd behavior so it’s down to just the canvas case (and any case we want it for in the future like scroll wheel). Which seems fine to me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Window.devicePixelRatio - Web APIs | MDN
The devicePixelRatio of Window interface returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the ...
Read more >
177836 - Update window.devicePixelRatio on browser zoom ...
If I zoom in on a non-retina screen so that an image of 300px now measures 600px on my screen, window.devicePixelRatio is still...
Read more >
Does devicePixelRatio change when the browser window is ...
Yes the devicePixelRatio changes, and you can detect it with matchMedia . I think that you should have a look at this topic...
Read more >
devicePixelRatio - QuirksBlog - QuirksMode
Thus <window.devicePixelRatio> equals 1. Retina iPhones have a width of 640 physical pixels in portrait mode. Still, websites that use the ...
Read more >
Targeting styles with media queries - WebPlatform.org
This tutorial shows how to use them to optimize a site for mobile handsets and tablet devices in addition to desktop browsers. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found