flutter
flutter copied to clipboard
Add support for custom cluster icon in Google Map Flutter
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.
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.
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 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?
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.
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?
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?
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
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?
any news on this? This is practically a beta library we have no ability to modify the icon of cluster
Any news?
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.
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.
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:
- 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?
- Custom Cluster Colors
- Custom Cluster Text
I'll keep following this issue. Thanks for consideration.
Cant wait for this my app looks ugly but clustering works really well
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).
I guess maps just arent that important to them even though i haven't build an app without one
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
Whats the status of this ?
Still waiting for this. Or is it possible to set the cluster color?
up please, it shows the default cluster marker only
@stuartmorgan-g Looks like it was implemented in newest Flutter version and customised clusters can be implemented, or are there any other obstacles?
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.
We will get GTA 6 before custom cluster markers.
Can we start with at lease color change ? Then move to custom elements later ?
No wonder flutter apps look bad when we cant get this simple feature
are there still plants on implementation? at least for a limited workaround?