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

Cluster pop animation keeps popping when I zoom or move #415

Open
mistralaix opened this issue Jul 1, 2022 · 0 comments
Open

Cluster pop animation keeps popping when I zoom or move #415

mistralaix opened this issue Jul 1, 2022 · 0 comments
Assignees
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mistralaix
Copy link

Hi,

I am using the cluster manager in order to display my markers on my map. I wanted to add the pop animation on the appearance of my marker. However every time that I try to move or to zoom on the map, my markers keep re-appearing.
At the beginning, I was just using custom icons on my markers and they kept blinking every time I zoomed or moved on the map. In order to simplify the demonstration, I am just using the pop animation on the appearAnimation of the marker.

First I thought it might been due to the clearItems then to the cluster again so I tried to optimize the renderer a little bit:

func updateCluster(clusterManager: GMUClusterManager, markerItems: [MarkerItem]) {
    var markersToAdd: [POIItem] = []
    var markersToDelete: [POIItem] = []
    for markerItem in markerItems {
        if mapDisplayedItems.contains(where: { $0.id == markerItem.id }) == false {
            let position = CLLocationCoordinate2D(latitude: markerItem.lat, longitude: markerItem.lng)
            let mapItem = POIItem(position: position, id: markerItem.id, picture: nil, markerItem: markerItem)
            markersToAdd = markersToAdd + [mapItem]
        } else if let mapDisplayedItem = mapDisplayedItems.first(where: { $0.id == markerItem.id }), mapDisplayedItem.position.latitude == markerItem.lat && mapDisplayedItem.position.longitude == markerItem.lng {
            mapDisplayedItem.position = CLLocationCoordinate2D(latitude: markerItem.lat, longitude: markerItem.lng)
        }
    }
    for mapDisplayedItem in mapDisplayedItems {
        if markerItems.contains(where: { $0.id == mapDisplayedItem.id }) == false {
            markersToDelete = markersToDelete + [mapDisplayedItem]
        }
    }
    for markerToDelete in markersToDelete {
        mapDisplayedItems = mapDisplayedItems.filter({ $0.id != markerToDelete.id })
        clusterManager.remove(markerToDelete)
    }
    mapDisplayedItems = mapDisplayedItems + markersToAdd
    for markerToAdd in markersToAdd {
        clusterManager.add(markerToAdd)
    }
    if !markersToAdd.isEmpty || !markersToDelete.isEmpty {
        clusterManager.cluster()
    }
}

Then in my renderer method, I tried to optimize it too:

func renderer(_ renderer: GMUClusterRenderer, willRenderMarker marker: GMSMarker) {
    guard let myItem = marker.userData as? POIItem, var markerItem = myItem.markerItem, !markerItem.hasBeenRendered else {
        return
    }
    marker.appearAnimation = .pop
    markerItem.hasBeenRendered = true
}

Environment details

iOS: 15.4
GoogleMaps: 7.0.0
GooglePlaces: 7.0.0
GoogleUtilities 7.7.0
Google-Maps-iOS-Utils: 4.1.0

Thank you for your help!

@mistralaix mistralaix added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants