bpillon / google_maps_cluster_manager

Simple Flutter clustering library for Google Maps
https://pub.dev/packages/google_maps_cluster_manager
MIT License
121 stars 94 forks source link

Dynamically change Cluster marker icon #32

Closed buraktabn closed 2 years ago

buraktabn commented 2 years ago

I can change the single Cluster easily by adding isSelected field into Place. When it comes to multiple Cluster, I found a workaround for now.

Future<Marker> Function(Cluster<Place>) get _markerBuilder => (cluster) async {
        return Marker(
          markerId: MarkerId(cluster.getId()),
          position: cluster.location,
          onTap: () => onMarkerPressed(cluster),
          icon: await _getMarkerBitmap(
            cluster.isMultiple,
            text: cluster.isMultiple ? cluster.count.toString() : null,
            isSelected: cluster.items.map((element) => element.isSelected).contains(true),
          ),
        );
      };

In my opinion, Cluster<T> should have a field called isSelected and ClusterManager<T extends ClusterItem> should have a function that updates the cluster by Cluster id. This way it would be easier to update Cluster. Does it make sense? If not, what would be the best practice here?

bpillon commented 2 years ago

Hello @buraktabn. I had the same problematic as you on a project. I implemented it with a variable that reference the active cluster by his id. I think the library goal is not to have a "selected" handling because how the selection works could really change depending on usage. Just an example I have in mind : How does it works when you move the map ? On one of my projects, I wanted the cluster to be unselected, in another one I wanted the opposite.