目录
Michael Sena

3 Support MapVisibility control (#22)

  • 3 Support MapVisibility control

[Problem]

  • We only support MKMapRect as a way to configure the visible region of the map. We should also support all the ways you can control the visible region of the map with MKMapView.

[Solution]

  • Switch away from a binding of MKMapRect? to a binding of MapVisibility and introduce a new enum.
3年前26次提交

SwiftUIAdvancedMap

Swift

A wrapper around MKMapView with more functionality than Map.

Points and Overlays Camera Styling
Points Screenshot Camera Control Sat Screenshot
Feature AdvancedMap MapKit.Map
Tap/Long Press Gestures with Map coordinates passed into the Handlers. ✅ ❌
Annotations with Drag and Drop support ✅
(UIKit Annotation Views)
✅
(SwiftUI Annotation Views)
Overlays ✅
(UIKit Overlay Views)
❌
Specify EdgeInsets for UI overlays ✅ ❌
Display User Location ✅
(via AnnoatationViewFactory)
✅
(as an initialization parameter)
Region State Changing Handler, a callback that informs when a map change Animation in progress. ✅ ❌
Binding to Optional map region so map is initially positioned around country bounding box. ✅ ❌
MKMapCamera support ✅ ❌

Tap or Click Gesture with Coordinate on Map.

struct TappableMap: View {
  var body: some View {
    // `.constant(nil)` uses MKMapView's behavior of starting the map over the phone's current country. 
    // Still scrollable by default.
    AdvancedMap(mapRect: .constant(nil))
      .onTapOrClickMapGesture { coordinate in
        print("Tapped map at: \(coordinate)")
      }
  }
}

Rendering Annotations

struct TappableMap: View {

  static let annotationViewFactory = AnnotationViewFactory(
    register: { mapView in
      mapView.register(MKMarkerAnnotationView.self, forAnnotationViewWithReuseIdentifier: String(describing: MKPointAnnotation.self))
    },
    view: { mapView, annotation in
      mapView.dequeueReusableAnnotationView(withIdentifier: String(describing: MKPointAnnotation.self), for: annotation)
    }
  )

  @State var mapVisibility: MapVisibility?
  @State var annotations: [MKPointAnnotation] = [MKPointAnnotation]()

  var body: some View {
    AdvancedMap(mapVisibility: $mapVisibility)
      .annotations(annotations, annotationViewFactory: Self.annotationViewFactory)
      .onTapOrClickMapGesture { coordinate in
        let annotation = MKPointAnnotation()
        annotation.coordinate = coordinate
        annotations.append(annotation)
      }
  }
}

Inspired by, and sometimes stealing from, the following projects:

关于
9.3 MB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号