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

GMUClusterRendererDelegate willRenderMarker called twice for each marker #58

Closed
SAPIENTechnologies opened this issue Nov 17, 2016 · 19 comments
Labels

Comments

@SAPIENTechnologies
Copy link

I have created the GMUClusterRendererDelegate in my code and implemented the willrenderMarker function. I notice that this function loops through the visible markers 2x for each marker. For instance, if I have 5 visible markers, the function gets called for each marker in succession, and then AGAIN for each marker in succession. Is this expected behavior?

@mountainvat
Copy link
Contributor

The expected behaviour is willRenderMarker should be called only once for each marker being added to the map. However whenever a recluster needs to be done (zooming in/out far enough from current zoom) the markers will be recreated and willRenderMarker will be called again. Was that what happens? We will try to reproduce on our side too.

@mountainvat
Copy link
Contributor

FYI: I've just briefly tried to reproduce on my side but failed. So I am waiting for more information.

@SAPIENTechnologies
Copy link
Author

Its very odd. Here is the only place where I call cluster()

func clusterMarkers () {
    //clear out the marker array
    self.markers.removeAll()

    //clear out the cluster manager items
    mapViewController.clusterManager.clearItems()

    self.clusterManager.add(trucks)

    // Call cluster() after items have been added to perform the clustering
    // and rendering on map.
    mapViewController.clusterManager.cluster()
    }

I call clusterMarkers from other places but I know its only called once because of the self.markers.removeAll() call. When I look at the self.markers array in my willRendermarker delegate function, it does not get cleared out in between the duplicate render calls. In other words:

I start out with the markers array empty
I start out with 5 items in my trucks array.
I add the trucks array to cluster manager
I call cluster()

in my willRenderMarker delegate function, it renders each marker which I then add to the markers array. But then it renders each marker again, invalidating the first set of markers. But I end up with 10 markers in my markers array. The first 5 are now invalid on the map.

I have put in some code to get past the problem in the WillRenderMarker delegate function, but I can’t seem to figure out why the markers are being rendered a second time.

Thank you for any input.

Regards,
info@sapien.com

On Nov 17, 2016, at 1:25 PM, Son Nguyen notifications@github.com wrote:

The expected behaviour is willRenderMarker should be called only once for each marker being added to the map. However whenever a recluster needs to be done (zooming in/out far enough from current zoom) the markers will be recreated and willRenderMarker will be called again. Was that what happens? We will try to reproduce on our side too.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #58 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AOoyM7ZU3IfrKsj8JKVtaf1FXFcQmS2Vks5q_MZdgaJpZM4K1n7T.

@mountainvat
Copy link
Contributor

So in the willRenderMarker handler, can you log the map's camera zoom out and paste them here?

@SAPIENTechnologies
Copy link
Author

Its always the same:

16.0
16.0
16.0
16.0
16.0
16.0
16.0
16.0
16.0
16.0
16.0
16.0

Regards,
info@sapien.com

On Nov 17, 2016, at 2:20 PM, Son Nguyen notifications@github.com wrote:

So in the willRenderMarker handler, can you log the map's camera zoom out and paste them here?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #58 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AOoyM2tK6xkn8j4JWvSfzoLaOl00lmgxks5q_NMtgaJpZM4K1n7T.

@mountainvat
Copy link
Contributor

There were 12 events in the log above. So sth strange here. Can you also log the camera lat,lng to see if they actually moved?

@SAPIENTechnologies
Copy link
Author

There are 4 trucks in my viewport here is the output

ID: 2
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 3
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 5
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 6
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 2
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 3
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 5
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 6
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

Regards,
info@sapien.com

On Nov 17, 2016, at 2:52 PM, Son Nguyen notifications@github.com wrote:

There were 12 events in the log above. So sth strange here. Can you also log the camera lat,lng to see if they actually moved?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #58 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AOoyMy5OO8K5aUBSjAkKDubTjK5nZ-1_ks5q_NqzgaJpZM4K1n7T.

@SAPIENTechnologies
Copy link
Author

Anything new based on the last logging I sent?

here it is again

There are 4 trucks in my viewport here is the output

ID: 2
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 3
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 5
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 6
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 2
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 3
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 5
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

ID: 6
Zoom level: 16.0
Latitude: 38.2556198811391
Longitude: -122.27283205837

Regards,
info@sapien.com

On Nov 17, 2016, at 2:52 PM, Son Nguyen notifications@github.com wrote:

There were 12 events in the log above. So sth strange here. Can you also log the camera lat,lng to see if they actually moved?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #58 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AOoyMy5OO8K5aUBSjAkKDubTjK5nZ-1_ks5q_NqzgaJpZM4K1n7T.

@mountainvat
Copy link
Contributor

The camera did not change throughout so I am not sure what's going on there. Are you able to check out the source, open the workspace/GoogleMapsUtils.xcodeproj and run the DemoApp target and see if it reproduce for the CustomMarkerViewController demo?

I was unable to reproduce using that demo.

Or else can you create a small repro project that I can take a look?

@SAPIENTechnologies
Copy link
Author

This problem still exists. I have created a stripped down version of my project. Is there a private location that I can upload it to for you to take a look at?

@domesticmouse
Copy link
Contributor

Please feel free to email me the repro, or link to it, at brettmorgan@google.com

@domesticmouse
Copy link
Contributor

I'm a tad confused, at first blush this app doesn't appear to include Google-Maps-iOS-Utils in the Podfile. It includes a bunch of other detail that isn't helpful with respect to debugging the issue.

I strongly suggest you build a minimal reproduction sample that includes only the GoogleMaps and Google-Maps-iOS-Utils pods, and post it up as a github repo that I can clone and fix.

Thanks!

@SAPIENTechnologies
Copy link
Author

SAPIENTechnologies commented May 26, 2017 via email

@SAPIENTechnologies
Copy link
Author

SAPIENTechnologies commented May 26, 2017 via email

@domesticmouse
Copy link
Contributor

The instructions in https://github.com/googlemaps/google-maps-ios-utils/blob/master/Swift.md are for the specific case for when you have a Podfile that has use_frameworks! declared in it. From memory your reproduction instance didn't have that in it. It also had a lot of other stuff. I like to get people to boil down their issues to a minimal reproduction, as that exercise frequently shows the problem directly, or failing that, limits the search I have to make to figure out the problem.

So, please create a minimal repro case of the issue you are facing. Thanks!

@PatoSalazarNascent
Copy link

PatoSalazarNascent commented Apr 16, 2018

Also have the same issue. Could not use the podfile as my app is using use_frameworks!. Will Render is getting called twice for each marker.

For one single marker and a cluster marker (of six clusterItems) if I print inside the willRender method I get

render
render
render
render

also calling cluster only once when a promise resolves.

    private func getHotpotsLocations() {
        hotspotProtocol.getItemsByBounds(bounds: getVisibleBounds())
            .then {
                [weak self = self]
                clusterItems -> Void in
                
                for item in clusterItems {
                    
                    if WifiHotspotsViewController.isCoordinateInvalid(coord: item.position) {
                        print("MAPKIT NAME ===> \(item.name)")
                        print("MAPKIT ADDRESS ===> \(item.address)")
                        print("MAPKIT LATITUDE ===> \(item.position.latitude)")
                        print("MAPKIT LONGITUDE ===> \(item.position.longitude)")
                        
                        continue
                    }
                    
                    self?.clusterManager.add(item)
                }
                
                self?.clusterManager.cluster()
            }
            .catch {
                error in
                
                print(error)
        }
    }

This is what is inside my willRender method

    internal func renderer(_ renderer: GMUClusterRenderer, willRenderMarker marker: GMSMarker) {
        print("render")
        if let clusterData = marker.userData as? GMUCluster {
            marker.iconView = UIImageView(image: getClusterIcon(itemsCount: clusterData.count))
        }
        else {
            marker.iconView = UIImageView(image: UIImage(named: "singlePin"))
        }
    }

@frios
Copy link

frios commented Apr 17, 2018

Do you call clusterManager.clearItems() sometime before this? I was looking at this call and saw that it calls clusterManager.algorithm.clearItems() then calls requestCluster(). That seemed to be the issue for me that created the duplicate willRender calls.

I fixed it by calling clusterManager.algorithm.clearItems() directly, bypassing the call to requestCluster().

@stale
Copy link

stale bot commented Oct 4, 2019

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

@stale stale bot added the stale label Oct 4, 2019
@stale
Copy link

stale bot commented Nov 3, 2019

Closing this. Please reopen if you believe it should be addressed. Thank you for your contribution.

@stale stale bot closed this as completed Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants