efremidze / Cluster

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

Missing styling of Annotation / View #103

Closed sebleclerc closed 5 years ago

sebleclerc commented 5 years ago

I upgraded from Cluster 2.2.8 to latest 2.4.1. After the upgrade, I had some errors stating that ClusterAnnotationStyle does not exists anymore.

New Issue Checklist

Issue Description

How am I suppose to style my pins on the map now? I read a little bit and saw the style property have been made private but that's pretty much it.

In the doc I see this:

let annotation = Annotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
annotation.style = .color(color, radius: 25) // .image(UIImage(named: "pin"))
clusterManager.add(annotation)

But the style property doesn't exists anymore.

I am clearly missing something here but can't find it...

Thanks!

Environment

iMentock commented 5 years ago

I am having this same issue.

edit I am reverting back to 2.2.8 till update on this issue.

efremidze commented 5 years ago

Sorry for the confusion. I've deprecated the ClusterAnnotationStyle and instead added new ClusterAnnotationView subclasses. You can now achieve the same UI using:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    let annotationView = CountClusterAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
    annotationView.countLabel.backgroundColor = color
    return annotationView
}

https://github.com/efremidze/Cluster/blob/master/Example/AnnotationView.swift

Feel free to provide feedback on the implementation.

efremidze commented 5 years ago

@sebleclerc @guapokat I've reintroduced the ClusterAnnotationStyle but you need to use the StyledClusterAnnotationView to support it. It's out in v2.4.3.

sebleclerc commented 5 years ago

@efremidze Thanks for the quick changes!

My original question was also about "regular" pin. What I did was to subclass Annotation and use that style property. After getting into the code again, I see what my problem was. I'll have to change that a bit to make sure I'm 100% good with the upcoming 2.5.0 release that will remove the style property.

efremidze commented 5 years ago

I can continue supporting the style property but it's error prone since the library doesn't consider the style property when grouping clusters. It currently just checks the first element in the cluster and uses it's style. I need to come up with a better solution to support multiple styles.

sebleclerc commented 5 years ago

My mind is more clear on what it involves removing the style property. I don't really care if it's removed, you probably know better than me if it could cause problem 😃

I used the style for the regular pins to store their color because different colors have different meaning in my app. I have removed the use of style for these.

As you mentioned, cluster view use the first element style, which is not something I want. I want to have all cluster views with the same color. If that would be possible when removing the style property, I'm totally fine.

efremidze commented 5 years ago

In your case it wouldn't cause a problem.

sebleclerc commented 5 years ago

Good to hear! Thanks a lot for the quick answer and changes.