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

Is there a way to just renderer the visible clusters and items? #82

Closed
coyarzun89 opened this issue May 2, 2014 · 13 comments
Closed

Is there a way to just renderer the visible clusters and items? #82

coyarzun89 opened this issue May 2, 2014 · 13 comments

Comments

@coyarzun89
Copy link

coyarzun89 commented May 2, 2014

Hi,
I don't know if it is the default behavior, but both methods, onBeforeClusterItemRendered and onBeforeClusterRendered, are called every time that I zoom out the map, even when there are not clusters or items visible. Is there a way to just renderer the visible clusters and items?
I have a map with 1000 items, and every item has his own image, so I need to render only the visible elements.
Thanks!


From duplicate issue #82, from @kaads123:

Summary:

ClusterManager draws all the markers/clusters, not only visible ones. It should draw only those that are in visibleRegion. This causes a map with 2000 markers skip frames and ANR (even on new devices) when zooming in/out.

Steps to reproduce:

Add 2000 or more markers and try zooming in and zooming out fast. This can be reproduced in the sample app

Expected behavior:

Draw only those markers/clusters which are in visibleRegion.latLngBounds of the GoogleMap

Observed behavior:

Draws every marker added to ClusterManager

Device and Android version:

Moto G3 with Android 6.0.1
Nexus 6P with Android 7.1.2

Screenshots:

screenshot_20170628-182053

Zoomed out from 20f to 1f quickly

@ericpanorel
Copy link

You could try the same idea, that I mentioned in issue#29 Just replace Polylines with Markers

@coyarzun89
Copy link
Author

Thanks, that was really helpful. Is it normal that I still have a lot of call to the GC on the log? Is there a way to avoid it?

zamesilyasa added a commit to zamesilyasa/android-maps-utils that referenced this issue Jan 28, 2015
zamesilyasa added a commit to zamesilyasa/android-maps-utils that referenced this issue Mar 7, 2016
ScreenBasedAlgorithmAdapter is now derived from NonHierarchicalDistanceBasedAlgorithm
Added new ScreenBasedAlgorithm interface. Implementing this interface, Algorithm has map position and can skip clustering if it is not required.
Removed usage of instanceof checks in ClusterManager, which broke algorithms logic, in case of decorations.

googlemaps#82
@multivoltage
Copy link

@zamesilyasa ,I found your code. Sorry....but how I can edit Clustermanager?

@zamesilyasa
Copy link
Contributor

I honestly don't understand what are you trying to do

@multivoltage
Copy link

multivoltage commented Jun 23, 2016

I found your repo, which is fork of original google-maps-utilis. I cloned issue-82 branch in my pc. With Android Studio I add that project as module. Then i remove original gradle dependency for google-maps-utils. At this point I can use all classs like before. But i don't understand Clustmanager. I was thinking to find .setClusterOnlyVisibleArea(true); method. I noticed that you ClusterManager class is different from that in this link:
zamesilyasa@1cf9f4e

So, maybe I jump some step, I don't know

@zamesilyasa
Copy link
Contributor

That's because there is no such method anymore. Please, check VisibleClusteringDemoActivity.
The only thing you have to do, to use my patch is to set NonHierarchicalViewBasedAlgorithm to your cluster manager instance, that's it.

@multivoltage
Copy link

I am sorry. I'm learning github very slowly. You have reason. now, map is not fast, but also not slowly.

@nfajardo
Copy link

nfajardo commented Aug 18, 2017

Hello, i know this is closed but probably this helps someone. I manage 1500+ markers in the map. I just only did somethig like this (based on previous comments)

 boolean isInBounds = latLngBounds.contains(cluster.getPosition());

            if(isInBounds){
                return cluster.getSize() > 4 && currentZoom < 17 ;
            }else{
                return true;
            }

I put this in shouldRenderAsCluster method
And the map goes fast, because only renders the markers that is in the viewport and in a specific zoom value.

@SAPNA-BHOR
Copy link

@nfajardo what is latLngBounds? How you initialise this variable? are you changing this on the zoom change every time?

@nfajardo
Copy link

nfajardo commented Aug 22, 2017

Hi @SAPNA-BHOR
LatLngBounds latLngBounds; <--On top of the class

And in this methods
@OverRide
public void onCameraMove() {
latLngBounds = mMap.getProjection().getVisibleRegion().latLngBounds;
}
@OverRide
public void onCameraIdle() {
latLngBounds = mMap.getProjection().getVisibleRegion().latLngBounds;
}
and in onMapReady method.
also in this methods i call cluster method for the cluster manager...I do it here because the getMapProjection must do in the main thread ....

Hope this help you!

@CeccoCQ
Copy link

CeccoCQ commented Sep 5, 2017

I'm currently using this solution, but I noticed some bad effects with the clustering.
When I move the maps at certain zoom level (that shows clusters and markers together) too animations appears because the hidden zones of maps that contains my markers are rendered and the near clusters changes a lot of time.

So, I'm thinking, is there a way to increase the VisibleBounds with a simply offset to avoid this effect?

For example, let me suppose that the VisibleRegion was 100x100, is there a way to set the visible region to 120x120? So when the user drags the map, the nearest cluster doesn't show the bad animation. Is it possible?

@Divi28
Copy link

Divi28 commented Mar 7, 2018

Can any one help on my requirement...I have a json response which has 4 array object..Each array object has list of LatLng values (placing markers on those latlng)..My Cluster should be formed based on array objects..Each array object has a unique ID??

@stephenmcd
Copy link
Contributor

#217

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

9 participants