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

setVisibleCoordinateBounds seems inconsistent when map has pitch #3006

Open
krupupakku opened this issue Nov 11, 2024 · 0 comments
Open

setVisibleCoordinateBounds seems inconsistent when map has pitch #3006

krupupakku opened this issue Nov 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@krupupakku
Copy link

krupupakku commented Nov 11, 2024

Description
I'm building a map using maplibre on iOS and I'm trying to fit an area.
I'm using setVisibleCoordinateBounds and if the map is pitched seems it doesn't fit well the area (see video), or better, the camera is different depending on old position+altitude; this behaviour is different and consistent if the pitch is 0, fitting well and always in the same way the desired area. See videos for more context.

To Reproduce
I created a minimal app to reproduce the behavior:

Sample.swift

@main
struct Sample: App {
    var body: some Scene {
        WindowGroup {
            MapApp()
        }
    }
}

MapApp.swift

struct MapApp: View {
    var body: some View {
        ZStack {
            MapView().edgesIgnoringSafeArea(.all)
            VStack {
                Spacer()
                HStack {
                    Spacer()
                    Button(action: {
                        NotificationCenter.default.post(name: .fitBounds, object: nil)
                    }) {
                        Image(systemName: "inset.filled.center.rectangle")
                            .padding()
                            .background(.blue)
                            .foregroundColor(.white)
                            .clipShape(Circle())
                    }
                    .padding()
                }
            }
        }
    }
}

MapView.swift

struct MapView: UIViewRepresentable {
    let mapConfiguration = MapConfiguration()

    func makeUIView(context _: Context) -> MLNMapView {
        let mapView = MLNMapView()
        mapView.styleURL = URL(string: mapConfiguration.mapTilesURL)

        NotificationCenter.default.addObserver(forName: .fitBounds, object: nil, queue: .main)
        { _ in
            mapView.setVisibleCoordinateBounds(
                mapConfiguration.bounds,
                edgePadding: mapConfiguration.padding,
                animated: true,
                completionHandler: nil
            )
        }

        return mapView
    }

    func updateUIView(_ map: MLNMapView, context _: Context) {
        //Set them to 0.0 to make it fit the map properly 
        map.minimumPitch = 60.0
        map.maximumPitch = 60.0
    }
}

MapConfig.swift

class MapConfiguration {
    let mapTilesURL =
        "https://api.maptiler.com/maps/<yourmapurl>"

    private let sw = CLLocationCoordinate2D(
        latitude: 40.349511836947435, longitude: -3.8565100879514294)
    private let ne = CLLocationCoordinate2D(
        latitude: 40.351483217268736, longitude: -3.8552455074798626)
    private let paddingValue = 100.0

    var bounds: MLNCoordinateBounds {
        return MLNCoordinateBounds(
            sw: sw,
            ne: ne
        )
    }

    var padding: UIEdgeInsets {
        return UIEdgeInsets(
            top: paddingValue,
            left: paddingValue,
            bottom: paddingValue,
            right: paddingValue
        )
    }
}

Extensions.swift

extension Notification.Name {
    static let fitBounds = Notification.Name("fitBounds")
}

Expected behavior
Map should fit the area I desire with or without pitch

Screenshots

👎 note the polygon being fitted in different ways depending on the camera position. (pitch 60.0)

pitched.mov

👍 note the polygon being fitted in a consistent way not depending on the camera position (pitch 0.0)

notpitched.mov

Platform information (please complete the following
information):

  • OS: reproduced on iOS 17,18
  • Platform: iOS
  • MapLibre: reproduced on 6.5.2 and 6.8.0

Additional context
tried in both simulator and physical device

@krupupakku krupupakku added the bug Something isn't working label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant