Code Monkey home page Code Monkey logo

Comments (5)

choefele avatar choefele commented on August 15, 2024

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.

TheoJL avatar TheoJL commented on August 15, 2024

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.

choefele avatar choefele commented on August 15, 2024

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.

TheoJL avatar TheoJL commented on August 15, 2024

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.

TheoJL avatar TheoJL commented on August 15, 2024

Yep, it worked.
@choefele thanks for pushing me in the right direction!

from cchmapclustercontroller.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.