efremidze / Cluster

Easy Map Annotation Clustering 📍
MIT License
1.28k stars 121 forks source link

Adding a SwiftUI Example #120

Open dpelletier2017 opened 5 years ago

dpelletier2017 commented 5 years ago

Hi, Would it be possible to add a SwiftUI Example of how to incorporate Cluster into a project in SwiftUI project in Xcode 11? Thanks a lot!

efremidze commented 5 years ago
import SwiftUI
import MapKit

struct MapView: UIViewRepresentable {
    let manager: ClusterManager

    func makeUIView(context: Context) -> MKMapView {
        MKMapView(frame: .zero)
    }

    func updateUIView(_ view: MKMapView, context: Context) {
        view.delegate = self
    }
}

extension MapView: MKMapViewDelegate {
    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        return SomeAnnotationView()
    }

    func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
        manager.reload(mapView: mapView)
    }
}

struct MapView_Preview: PreviewProvider {
    static var previews: some View {
        MapView()
    }
}

More examples can be found on https://developer.apple.com/tutorials/swiftui/creating-and-combining-views

uzunnibrahim commented 3 years ago

Can you send me a more comprehensive swiftui example? People who have never used storyboards like me may have difficulty with some connections.

emrdgrmnci commented 1 year ago

shame on Apple still doesn't provide clustering for SwiftUI Map even in ios 17. I'm waiting for a step for this repo but it still has no SwiftUI support https://github.com/vospennikov/ClusterMap

Harry-KNIGHT commented 1 year ago

@emrdgrmnci Apple will, on next WWDC, say to us "The wonderful feature of clustering, iOS 18 minimum 🤡", so, clustering libraries has 3/5 of life I think.