Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Great job #1

Open
wojciech-kulik opened this issue Feb 2, 2020 · 1 comment
Open

Great job #1

wojciech-kulik opened this issue Feb 2, 2020 · 1 comment

Comments

@wojciech-kulik
Copy link

wojciech-kulik commented Feb 2, 2020

Thank you for this code :) Saved me a lot of time!

I see it's also based on: https://thoughtbot.com/blog/how-to-handle-large-amounts-of-data-on-maps

I implemented also code for animation (from this article):

nativeMap.DidAddAnnotationViews += NativeMap_DidAddAnnotationViews;

private void AddBouncingTo(UIView view)
        {
            var bounceAnimation = new CAKeyFrameAnimation { KeyPath = "transform.scale" };
            bounceAnimation.Values = new NSObject[] { NSNumber.FromDouble(0.05), NSNumber.FromDouble(1.1), NSNumber.FromDouble(0.9), NSNumber.FromDouble(1) };
            bounceAnimation.Duration = 0.6;
            var timingFunctions = new List<CAMediaTimingFunction>();
            for (var i = 0; i < 4; i++)
            {
                timingFunctions.Add(CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut));
            }
            bounceAnimation.TimingFunctions = timingFunctions.ToArray();
            bounceAnimation.RemovedOnCompletion = false;
            view.Layer.AddAnimation(bounceAnimation, "bounce");
        }

        private void NativeMap_DidAddAnnotationViews(object sender, MKMapViewAnnotationEventArgs e)
        {
            foreach (var view in e.Views)
            {
                AddBouncingTo(view);
            }
        }
@wojciech-kulik
Copy link
Author

wojciech-kulik commented Feb 2, 2020

Also you had issue with comparing sets and operations on them. Each time you create a new instance of FBAnnotationCluster, therefore a comparison of references always returns false.

To fix this you need to add to FBAnnotationCluster:

public override bool Equals(object obj)
{
    return obj.GetHashCode() == GetHashCode();
}

public override int GetHashCode()
{
    var formatted = $"{Coordinate.Latitude:F5} {Coordinate.Longitude:F5}";
    return formatted.GetHashCode();
}

It is easy to spot this bug when you add animations mentioned above :)

Here is missing code:
https://github.com/thoughtbot/TBAnnotationClustering/blob/master/TBAnnotationClustering/TBClusterAnnotation.m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant