hulab / ClusterKit

An iOS map clustering framework targeting MapKit, Google Maps and Mapbox.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to handle GMSCircle

MarvinNazari opened this issue · comments

HI, awesome framework, really easy to handle clustering, I'm interested to know if u have some suggestion how u would handle adding circles for the pin, in my case is basically accuracy circle which I use GMSCircle to show that. But with cluster GMSMapViewDataSource there is no way to add the circle, I wonder if u know any workaround for any delegates call that I can use to add the circles my self, I only want to add the circles when the pins are unclustred.

Thanks.

Hi @MarvinNazari
I guess the datasource method should ask fo an overlay instead of a marker. As a workaround, you can create a circle view and set it as the marker's iconView.

@maxep: I already have a pin with custom view which I use iconView for, shouldn't circle be it's own overlay?

Not sure to understand what you mean by it's own overlay.
I've just checked and it's actually not possible to animate a GMSOverlay subclass other than a GMSMarker. So you cannot use a GMSCircle as a cluster or an annotation representation.

This is my use case, and i have already a pretty complicated custom view which i use for GMSMarker.iconView

class ViewController: UIViewController {

    lazy var mapView: GMSMapView = {
        let view = GMSMapView()
        return view
    }()
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        mapView.frame = view.bounds
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        [
            MapPinViewModel(coordinate: CLLocationCoordinate2D(latitude: 40.7589, longitude: -73.9851), accuracyRadius: 500)
        ].forEach { pin in
            pin.show(in: mapView)
        }
        
    }

}

struct MapPinViewModel {

    let coordinate: CLLocationCoordinate2D
    let accuracyRadius: Double
    
    func show(in mapView: GMSMapView) {
        mapMarker.map = mapView
        accuracyCircle.map = mapView
    }
    
    var mapMarker: GMSMarker {
        return GMSMarker(position: coordinate)
    }
    
    var accuracyCircle: GMSCircle {
        return GMSCircle(position: coordinate, radius: accuracyRadius)
    }
}