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

Don't cluster specific items #47

Open deargosep opened 2 years ago

deargosep commented 2 years ago

For example if I have user avatar on map, I don't need it to cluster, how do I do that?

oguibueno commented 1 year ago

For example if I have user avatar on map, I don't need it to cluster, how do I do that?

What you can do is to have 2 different sets. One for clustering items and another one for non clustering items, like this:

final Set<Marker> _nonClusteringMarkers = {};
final Set<Marker> _clusteringMarkers = {};

GoogleMap(
  markers: {..._nonClusteringMarkers, ..._clusteringMarkers},
);

Create two classes like:

class Place { ... }

class ClusterPlace extends Place with ClusterItem { ... }

The Place one you use for the non clustering markers and the ClusterPlace you use for the clustering markers.

At the ClusterManager you can do something like this:

ClusterManager _initClusterManager() {
    return ClusterManager<ClusterPlace>(
      _items,
      _updateClusteringMarkers,
      markerBuilder: _markerClusterBuilder,
    );
  }