Skip to content

MapViewCamera OnLoad + Caching #78

@Archdoog

Description

@Archdoog

Issue

Related, but not specifically addressed in Issue #75 is the on appear camera behavior. When launching the MapView with a specific camera state, there's a synchronization issue (this may be in the underlying maplibre-native iOS implementation).

If the MapViewCamera is user tracking when the MapView is created, the map may start centered at 0.0, 0.0 and fly to the user location. The expected behavior is the MapView immediately renders the tracking mode and zoom level.

Mitigations

To correctly launch the MapView directly into user tracking, you can:

  1. Set tracking in the .onStyleLoaded callback modifier. This properly synchronizes something in the underlying MapView such that the camera will immediately appear to be tracking. This may not seamlessly start the MapView's camera, but often does. If not, step 2 may be needed.
  2. You can use the MapViewProxy view modifier to generated a cached camera with a MapViewCamera.centered state. In this case, you effectively create the MapView with the camera centered on the last proxy update (last visual state). Immediately after launching the MapView.

Potential Solutions

  1. Correcting any erroneous lock behavior. This library may be improperly allowing a camera position of centered to sneak back to the camera @binding in certain cases. Think if the defer in here is completing before a camera animation completes (MapViewCoordinator.swift#L57)[https://github.com/maplibre/swiftui-dsl/blob/689d0a26077b3c70f490c2b2507cbcdd1eb2f8b2/Sources/MapLibreSwiftUI/MapViewCoordinator.swift#L57].
  2. If option 1 fails, or there is something in native making this tricky to correct. We could consider an improved camera caching wrapper. Something that captures the proxy, caches correctly and gives the map view what it needs to resume state. This is a bad solution, but may offer a solid workaround for most developers.
  3. Lastly, MapViewCamera Improvements #75 may offer a path forward through other means. Though I'd expect we still need to solve this issue to succeed with that issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions