From e3c81d607aec52a61743441aafbcd8b6d578b757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20T=C3=B6rnqvist?= Date: Thu, 9 Jul 2026 23:56:28 +0200 Subject: [PATCH] Fix blurry map view in landscape on iPad (due to an orientation-varying scale factor) (#4373) --- platform/darwin/src/MLNDisplayUtils.mm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/platform/darwin/src/MLNDisplayUtils.mm b/platform/darwin/src/MLNDisplayUtils.mm index a13842c7c..b4b8c550f 100644 --- a/platform/darwin/src/MLNDisplayUtils.mm +++ b/platform/darwin/src/MLNDisplayUtils.mm @@ -1,17 +1,31 @@ #import "MLNDisplayUtils.h" +CGFloat MLNEffectiveScaleFactor(CGSize nativePixelBounds, CGSize logicalPointBounds) { + // `nativeBounds` is always portrait-up while `bounds` rotates with the interface orientation, + // so pair short side with short side to keep the ratio orientation independent. + CGFloat nativeShortSide = MIN(nativePixelBounds.width, nativePixelBounds.height); + CGFloat pointShortSide = MIN(logicalPointBounds.width, logicalPointBounds.height); + return pointShortSide > 0.0 ? nativeShortSide / pointShortSide : 0.0; +} + CGFloat MLNEffectiveScaleFactorForView(id viewOrNil) { #if TARGET_OS_IPHONE || TARGET_OS_TV UIView *view = (UIView *)viewOrNil; UIScreen *screen = view.window.screen ?: [UIScreen mainScreen]; - CGFloat logicalToPixelRatio = screen.nativeBounds.size.width / screen.bounds.size.width; + // `nativeScale` is orientation-independent and accounts for Display Zoom (unlike `scale`). + if ([screen respondsToSelector:@selector(nativeScale)] && screen.nativeScale > 0.0) { + return screen.nativeScale; + } + + CGFloat logicalToPixelRatio = + MLNEffectiveScaleFactor(screen.nativeBounds.size, screen.bounds.size); if (logicalToPixelRatio > 0.0) { return logicalToPixelRatio; } - return [screen respondsToSelector:@selector(nativeScale)] ? screen.nativeScale : screen.scale; + return screen.scale; #elif TARGET_OS_OSX