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

contentScaleFactor independent from UIScreen mainScreen - issue with secondary screens like CarPlay #3214

Open
boldtrn opened this issue Feb 13, 2025 · 2 comments
Labels

Comments

@boldtrn
Copy link
Collaborator

boldtrn commented Feb 13, 2025

Is your feature request related to a problem? Please describe.

Maplibre-Native calculates the scaleFactor like this:

: [[UIScreen mainScreen] scale];

As far as I understand, this can lead to issues if your phone has a different scale than your CarPlay screen.

As described in the apple dev forum:

UIScreen.main will always return a UIScreen instance that corresponds to the iPhone's built-in display.
If your CarPlay-capable app is a Navigation app (and therefore receives a CPWindow to draw your map content into), you can get the UIScreen for the CarPlay display through your CPTemplateApplicationScene:

Describe the solution you'd like

Don't use the mainScreen, but use the screen where the map is drawn on (and maybe fallback to main if none is given).

The dev forum describes the solution like:

let carPlayScreen = templateApplicationScene.carWindow.screen

Describe alternatives you've considered

I assume there is also a way to get the screen from the view tree / hierarchy?

Alternatively it could also work that implementers pass a scale from the outside into MlnMapview?

Additional context

In our case, the CarPlay map is rendered too large proportionally to the screen size. So there is less area covered.

@boldtrn boldtrn added the iOS label Feb 13, 2025
@cachly
Copy link

cachly commented Feb 14, 2025

You should be able to just add this:

// Set the correct scale of the map
let carPlayScreen = self.templateApplicationScene?.carWindow.screen
if let scale = carPlayScreen?.scale {
    mapView.contentScaleFactor = scale
}

@StephanPartzsch
Copy link

Doesn't this scales the map on UIKit level, means after the map content was rendered? The metal rendering does not respect the contentScaleFactor of UIKit and therefore takes the wrong scaleFactor. This could lead to wrong sizes and unneeded performance overhead (if I am not completely wrong)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants