flutter icon indicating copy to clipboard operation
flutter copied to clipboard

Add support for custom cluster icon in Google Map Flutter

Open Mohit8G opened this issue 1 year ago • 25 comments
trafficstars

Use case

So Clustering in Google map is just landed but we don't have any support for custom cluster icon. There are some package on pub.dev but they are not proper solution to the problem.

Proposal

Need some properties that can override default cluster marker. Like this https://developers.google.com/maps/documentation/android-sdk/utility/marker-clustering

The ClusterManager constructor creates a DefaultClusterRenderer and a NonHierarchicalDistanceBasedAlgorithm. You can change the ClusterRenderer and the Algorithm using the setAlgorithm(Algorithm<T> algorithm) and setRenderer(ClusterRenderer<T> view) methods of ClusterManager.

You can implement ClusterRenderer to customize the rendering of the clusters. DefaultClusterRenderer provides a good base to start from. By subclassing DefaultClusterRenderer, you can override the defaults.

Mohit8G avatar Aug 08 '24 13:08 Mohit8G

It looks like this is not going to be implementable without https://issuetracker.google.com/issues/140415468 (or, alternately, https://github.com/flutter/flutter/issues/150525), since the cluster renderer protocol requires a synchronous response. Usually when we have something that requires a synchronous response we pre-generated the necessary information, send it asynchronously, and store it on the platform thread for immediate response, but there's no way to pre-generate all possible images.

Even if clients didn't want the ability to change the icon dynamically (which they well might), they will almost certainly want to add a number, and that can be arbitrary as well.

stuartmorgan-g avatar Aug 09 '24 10:08 stuartmorgan-g

Please use a thumbs-up reaction on this comment specifically (in addition to the original feature request) if the following limited version of this feature would address your use case:

We could potentially implement an API that allowed pre-providing a map of {cluster count, image bitmap} cluster options, and have the cluster icon picked by finding the image in that map whose cluster count is the largest value that is <= the actual count. For instance, if someone provided {1: imageA, 10: imageB, 50: imageC, 100: imageD}, then any clusters of size 1-9 would use imageA, 10-49 would use imageB, 50-99 would use imageC, and anything larger would use imageD.

stuartmorgan-g avatar Aug 09 '24 10:08 stuartmorgan-g

@stuartmorgan Needed one suggestion for this as I am not a native developer, what if I fork this package and add custom cluster logic for my usecase on native side code will this reflect on the flutter side map view?

Rishyash avatar Aug 13 '24 15:08 Rishyash

I'm really happy that there is now official support for clustering, but the inability to alter the clusterOptions leaves it unusable in my opinion. Specially with custom map styles, the variety of colors makes it look really out of place. But let's be honest, green, red, blue, brown... Even without a custom map style, these colors look awful when put together, I can't believe any dev that cares about design would use these clusters as it is.

The clusterIcons also look too big in my personal opinion, so it would be nice to be able to adjust their scaling.

I am really not familiar with the limitations to implement this, but ideally there would be an example of the default renderer which would allow us to tweak all the details. As I can in js or with Fluster, but until then I really don't think I can use the official clustering.

PauloAlves311 avatar Oct 11 '24 20:10 PauloAlves311

I'm not sure what's the blocker, but I used to be able to do this with custom packages such as this one.

Now the above package is essentially incompatible with the new APIs, but in return I can't customize my pins anymore.

This is bad, like, real bad.

Set aside the custom icons or painted images I used to put in my clusters (these won't work now, yes, even plain text won't work): I can't even customize the (now new) default colors on the map. What was the decisional process behind these harlequin-like colors? I don't think these follow any proper visual guideline I know of. The colors seem to be static const and hardcoded, and that's it. This is clearly a mistake, no one can possibly think this is even remotely usable on any brand or visual identity.

Who can possibly use this feature? Why is this P3 only? Why did this feature land in the first place?

lucavenir avatar Oct 17 '24 15:10 lucavenir

I agree that clustering without the possibility of customizing the appearance is not very useful. However, I spent a bit of time looking into a possible solution, and it's definitely something I might be able to fix.

I understand that the ClusterManager constructor here should probably extend setAlgorithm and setRenderer, and then trickle that down all the way back to the interface?

Not really my department, but I might give it a go. Or has @stuartmorgan been working on this?

FeelHippo avatar Oct 25 '24 11:10 FeelHippo

When I read that flutter google maps offers its own clustering option, I immediately tried to implement it in my project, but when I realized that the cluster icons are not changeable and the numbers are fixed, it makes the whole thing completely unusable. I would be happy if you create the possibility to make the cluster icons freely switchable just like the marker icons and also provide the possibility that the numbers are not displayed in these 10,50,100 groups but for example in the exact amount of the cluster

Shajk0 avatar Oct 26 '24 18:10 Shajk0

Also facing this blocker, kind of unacceptable for such a big addition to be doing only the basics. I need to be able to customize at least the icon and it's size. Any news on if and when this can be added?

Homerwatch avatar Nov 10 '24 10:11 Homerwatch

any news on this? This is practically a beta library we have no ability to modify the icon of cluster

Homerwatch avatar Jan 11 '25 13:01 Homerwatch

Any news?

stefanvinteler avatar Jan 16 '25 07:01 stefanvinteler

Is it even possible to change the cluster default colors? Just implemented this on my app but the lack of customization options means I might have to look for another solutions.

mangeria avatar Jan 31 '25 06:01 mangeria

Is it even possible to change the cluster default colors? Just implemented this on my app but the lack of customization options means I might have to look for another solutions.

For now no customization can be made.

Mohit8G avatar Jan 31 '25 06:01 Mohit8G

Is it even possible to change the cluster default colors? Just implemented this on my app but the lack of customization options means I might have to look for another solutions.

For now no customization can be made.

It would be beneficial to at least have things like:

  1. Cluster Nesting.
  • Cluster Zoom. Markers will cluster when the map is zoomed out beyond certain level. Currently I have to be zoomed all the way to world map for cluster market to appear in countries, markers inside cities are not clustered at all.
  • Cluster Grouping. Controls how close markers need to be to form a cluster. Unit could be radius?
  1. Custom Cluster Colors
  2. Custom Cluster Text

I'll keep following this issue. Thanks for consideration.

mangeria avatar Jan 31 '25 06:01 mangeria

Cant wait for this my app looks ugly but clustering works really well

servefast-cto avatar Mar 26 '25 20:03 servefast-cto

Still no updates? It's been over half a year and no new features for the ClusterManager?

Besides marker customisation it would also be nice to be able to set a max zoom level at which clustering is disabled (e.g. if there are some pins that are just too close to each other).

niemsie avatar Mar 27 '25 09:03 niemsie

I guess maps just arent that important to them even though i haven't build an app without one

servefast-cto avatar Mar 27 '25 11:03 servefast-cto

Still can't wrap my head around the fact that almighty Google can't even support their own language. And is not just their language, maps is their own product too. This is so frustrating guys

Homerwatch avatar Mar 27 '25 12:03 Homerwatch

Whats the status of this ?

ivanpolish123 avatar Apr 04 '25 10:04 ivanpolish123

Still waiting for this. Or is it possible to set the cluster color?

andynvt avatar Apr 22 '25 04:04 andynvt

up please, it shows the default cluster marker only

andynvt avatar May 19 '25 08:05 andynvt

#150525

@stuartmorgan-g Looks like it was implemented in newest Flutter version and customised clusters can be implemented, or are there any other obstacles?

dimonkomaron avatar May 22 '25 13:05 dimonkomaron

Plugins code cannot rely on thread merging while there is an application-level opt-out for it, because they have no way of knowing what mode they will be running in.

stuartmorgan-g avatar May 22 '25 17:05 stuartmorgan-g

We will get GTA 6 before custom cluster markers.

matthew-niemann avatar May 23 '25 08:05 matthew-niemann

Can we start with at lease color change ? Then move to custom elements later ?

Dzivo avatar Jun 05 '25 18:06 Dzivo

No wonder flutter apps look bad when we cant get this simple feature

Dzivo avatar Jun 27 '25 09:06 Dzivo

are there still plants on implementation? at least for a limited workaround?

Coinners avatar Oct 10 '25 09:10 Coinners