android-maps-utils icon indicating copy to clipboard operation
android-maps-utils copied to clipboard

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

Open coyarzun89 opened this issue 12 years ago • 13 comments

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

coyarzun89 avatar May 02 '14 01:05 coyarzun89

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

ericpanorel avatar May 06 '14 20:05 ericpanorel

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?

coyarzun89 avatar May 10 '14 07:05 coyarzun89

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

multivoltage avatar Jun 23 '16 09:06 multivoltage

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

zamesilyasa avatar Jun 23 '16 11:06 zamesilyasa

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: https://github.com/zamesilyasa/android-maps-utils/commit/1cf9f4e553fded253b0fcb8d31f58640687de985

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

multivoltage avatar Jun 23 '16 12:06 multivoltage

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.

zamesilyasa avatar Jun 23 '16 12:06 zamesilyasa

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

multivoltage avatar Jun 23 '16 13:06 multivoltage

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.

nfajardo avatar Aug 18 '17 17:08 nfajardo

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

SAPNA-BHOR avatar Aug 22 '17 11:08 SAPNA-BHOR

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!

nfajardo avatar Aug 22 '17 12:08 nfajardo

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?

CeccoCQ avatar Sep 05 '17 07:09 CeccoCQ

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??

Divi28 avatar Mar 07 '18 02:03 Divi28

#217

stephenmcd avatar Apr 17 '18 01:04 stephenmcd