目录
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.
2年前26次提交
目录README.md

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群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号