maplibre / maplibre-navigation-ios

MapLibre Navigation SDK for iOS
Other
36 stars 31 forks source link

NavigationViewController map view is blank (SwiftUI) #42

Closed michaelkirk closed 5 months ago

michaelkirk commented 6 months ago

Steps to Trigger Behavior

  1. Set up example app:
    git clone https://github.com/michaelkirk/maplibre-navigation-ios-example-app
    cd maplibre-navigation-ios-example-app
    git checkout mkirk/navigation-view-controller-blank
  2. Update ContentView with your accessToken
  3. run app

Link to Minimal Reproducible Example

https://github.com/michaelkirk/maplibre-navigation-ios-example-app/tree/mkirk/navigation-view-controller-blank

Expected Behavior

I expect some kind of map to be rendered.

Actual Behavior

Other UI is rendered, like the controls and user location puck, but the base map is just solid gray.

Screenshots (if applicable)

Screenshot 2024-05-14 at 19 34 04

Version(s) affected

Additional context

I'm using the NavigationViewController in SwiftUI via ViewControllerRepresentable. I haven't tried it in a non Swift UI app yet.

I can render a MapView and NavigationMapView just fine on it's own (via ViewRepresentable). It seems to only be an issue in the context of the NavigationViewController:

Screenshot 2024-05-14 at 19 52 33
michaelkirk commented 6 months ago

Update: I added a UIKit (non SwiftUI) App to my example repository and have confirmed the issue exists there as well.

michaelkirk commented 6 months ago

I was able to see a map rendered if I commented out these lines in NavigationViewController.swift:

 public func styleManager(_ styleManager: StyleManager, didApply style: Style) {
//        if self.mapView?.styleURL != style.mapStyleURL {
//            self.mapView?.style?.transition = MLNTransition(duration: 0.5, delay: 0)
//            self.mapView?.styleURL = style.mapStyleURL
//        }

        self.currentStatusBarStyle = style.statusBarStyle ?? .default
        setNeedsStatusBarAppearanceUpdate()
    }
Screenshot 2024-05-14 at 21 28 45

These are the values:

self.mapView?.styleURL = `maplibre://maps/style`
style.mapStyleURL = `mapbox://styles/mapbox/navigation-guidance-night-v4`

Should the mapbox URLs in MLNStyle.swift be updated to point to something maplibre?

I can pass in a custom style object with the proper URL to NavigationViewController(.... styles: [myCustomStyle]). But it's not quite trivial, because we still probably want to respect day vs. night.

Regardless of all that though, I'd expect the map style to change if the new style doesn't match the default style rather than to just print a blank view.

michaelkirk commented 6 months ago

Another thing - the map is very flickery while navigating. I don't experience this while panning the map.

It's true on both simulator and a physical device. I'm assuming that's a separate issue. I'll follow up with a new ticket and minimal example for that one tomorrow.

boldtrn commented 6 months ago

Should the mapbox URLs in MLNStyle.swift be updated to point to something maplibre?

Yes, actually the whole Mapbox Style part should be removed. The mapbox:// don't work anymore I think, so we should remove these. PRs would be very welcome, if you would like to work on this?

I think we should do two things:

I can pass in a custom style object with the proper URL to NavigationViewController(.... styles: [myCustomStyle]). But it's not quite trivial, because we still probably want to respect day vs. night.

Yes this currently works and you can handle the day and night switch in your app as well.

Another thing - the map is very flickery while navigating. I don't experience this while panning the map.

What do you mean with flickery? In the simulator it is very flickery and weird, but this does not happen on a real device. A new issue for this would make sense.

michaelkirk commented 5 months ago

Another thing - the map is very flickery while navigating. I don't experience this while panning the map. It's true on both simulator and a physical device.

What do you mean with flickery? In the simulator it is very flickery and weird, but this does not happen on a real device. A new issue for this would make sense.

You can see an example of the flickering from the earlier screen capture I uploaded. The green base map is flashing in and out of visibility while the blue route line is solid. This was happening on simulator and a real device. The problem seemed to go away when I switched to my own style rather than the maplibre default style, so I haven't looked into it further. I'm not sure if it's related to switching styles or some other issue.

Yes, actually the whole Mapbox Style part should be removed. The mapbox:// don't work anymore I think, so we should remove these. PRs would be very welcome, if you would like to work on this?

Sure, I'll take a stab at something.