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

Simplify OverviewMap usage #67

Open
mhdostal opened this issue May 31, 2022 · 0 comments
Open

Simplify OverviewMap usage #67

mhdostal opened this issue May 31, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@mhdostal
Copy link
Member

mhdostal commented May 31, 2022

It would be great if adding an overview map were simpler. One way of doing that would be to have a custom view modifier for the overview map in the toolkit:

MapView(map: map)
    .overviewMap(alignment: .topTrailing)

A proof of concept is as follows:

extension MapView {
    func overviewMap(alignment: Alignment) -> some View {
        MapViewWithOverviewMap(mapView: self, alignment: alignment)
    }
}

struct MapViewWithOverviewMap: View {
    let mapView: MapView
    let alignment: Alignment
    
    @State private var viewpoint: Viewpoint?
    @State private var visibleArea: Polygon?
    
    var body: some View {
        mapView
            .onViewpointChanged(kind: .centerAndScale) { viewpoint = $0 }
            .onVisibleAreaChanged { visibleArea = $0 }
            .overlay(alignment: alignment) {
                OverviewMap.forMapView(
                    with: viewpoint,
                    visibleArea: visibleArea
                )
                .frame(width: 200, height: 132)
                .padding()
            }
    }
}

As a proof of concept, it isn't without problems. We would need to change how those modifiers on map/scene view are implemented since users may also want to use them themselves (currently each subsequent use would override the previous).

The overview map could be customized with an overviewMapStyle(_:) modifiers, similar to other SwiftUI views. This should be explored as part of this issue; the OverviewMap already provides modifiers for symbol, map, and scaleFactor. Should they be combined into one overviewMapStyle(map:, symbol:, scaleFactor:)?

To get around the .onViewpointChanged(kind:)/.onVisibleAreaChanged() issue, maybe the .overviewMap(alignment:) modifier could take an optional binding to a Viewpoint and visible area Polygon and then update it alongside the local viewpoint and visible area.

Thanks to @philium for the suggestion!

@mhdostal mhdostal added the enhancement New feature or request label May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant