Comments (5)
If I understand you correctly, you want to change the icon of an annotation view for a visible CCHMapClusterAnnotation
when this annotation view is selected. This can be done by changing the image property of the annotation view in mapView:didSelectAnnotationView:
. Something similar to
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
view.image = ... // selected image
}
You can change this back in mapView:didDeselectAnnotationView:
.
When you zoom, the clusters will change. So it probably doesn't make sense to keep the previously selected annotation view and perhaps you should unselect it.
from cchmapclustercontroller.
I can't rely on the annotationViews isSelected state because it will be deselected everytime the region changes. Correct me if I'm wrong but I need to keep track of the selected annotation myself.
If there is a way to keep the isSelected state after regionDidChange your solution will probably work very nice.
Edit: I agree that it doesn't make sense to keep the selected annotation if you zoom to much and the annotation gets grouped, but I think it does make sense if you just zoom a little bit.
from cchmapclustercontroller.
How about tracking the currently selected annotation independently from the selected
property (based on the example in this project).
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
...
// clusterAnnotationView.canShowCallout = YES;
...
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
[mapView deselectAnnotation:view.annotation animated:NO];
ClusterAnnotationView *clusterAnnotationView = (ClusterAnnotationView *)view;
clusterAnnotationView.blue = YES;
}
This will change the annotation view and you could remember the currently selected annotation in a property.
from cchmapclustercontroller.
Really appreciate the help. Actually I tried that and had problems getting the previous selected annotation back to its ordinary icon. More and more annotations will get blue until region change and all gets updated.
When I think about it, It may not be harder than this:
for (id<MKAnnotation> anno in self.mapView.annotations) {
if ([anno isKindOfClass:[CCHMapClusterAnnotation class]]) {
CCHMapClusterAnnotation *clusteredAnnotation = (CCHMapClusterAnnotation *)anno;
if ([clusteredAnnotation.annotations containsObject:self.previousAnnotation]) {
MKAnnotationView *clusteredAnnotationView = [self.mapView viewForAnnotation:clusteredAnnotation];
clusteredAnnotationView.image = [UIImage imageNamed:@"ordinaryIcon"];
}
}
}
I can't test the code until tomorrow, but it should work I hope.
from cchmapclustercontroller.
Yep, it worked.
@choefele thanks for pushing me in the right direction!
from cchmapclustercontroller.
Related Issues (20)
- Annotation views occasionally disappear while panning/zooming HOT 2
- willReuseMapClusterAnnotation does not work in Swift HOT 6
- showAnnotations:animated: adds the default pin instead of custom Annotation Views HOT 1
- Using own custom MKAnnotation subclass for uniqueLocations HOT 4
- Strange behavior when zooming in and out HOT 14
- Two markers at exact same location HOT 1
- How to get the instance of CCHMapClusterAnnotation? HOT 4
- Crash due to usage of KVO HOT 5
- Annotations and clusters get removed randomly when using MKMapTypeHybridFlyover HOT 7
- Cannot refer to custom subclass of MKAnnotation in viewForAnnotation HOT 3
- Cannot tap on Annotation View
- Can't see annotation while too zoomed out HOT 4
- Annotation coordinate is not properly updated HOT 2
- Displaying different annotation views HOT 1
- Make the representation of ClusterAnnotationView unchanged when zooming in or out HOT 5
- changing the annotation view when isUnique changes HOT 2
- Getting wrong annotation count on click of cluster in swift 3 HOT 1
- TV OS? HOT 1
- Removing Annotations doesn't work correctly HOT 6
- Is it possible for clusters to have sub clusters?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cchmapclustercontroller.