clustering_google_maps icon indicating copy to clipboard operation
clustering_google_maps copied to clipboard

How create custom cluster markers?

Open pro100svitlo opened this issue 5 years ago • 0 comments

Hi! First - thansk for this library!

It works fine. But I can't get how can I create my custom markers within clusters? It looks like you create them under the hood, but it would be nice if we (lib customers) will have an opportunity to ovverride createMaker function 😉 Right now I am using the next trik to fix it:

void _updateMarkers(Set<Marker> markers) async {
    final knownMarkers = _convertToKnownMarkerSet(markers);
    setState(() {
      this.currentMapMarkers = knownMarkers;
    });
  }

Set<Marker> _convertToKnownMarkerSet(Set<Marker> clusteredMarkers) {
    final Set<Marker> newMarkers = Set();
    for (Marker marker in clusteredMarkers) {
      final converted = _getKnownMarker(marker);
      newMarkers.add(converted);
    }
    return newMarkers;
  }

  Marker _getKnownMarker(Marker newMarker) {
    for (Marker marker in allMapMarkers) { //`allMapMarkers` is set of all my markers.
      if (marker.position == newMarker.position) {
        return marker;
      }
    }
    return newMarker;
  }

it works, but its dirty...

as proposition: it would be nice to have something similar to createFromMemory, but instead list of LatLngAndGeohash as param, pass list of Markers (which under the hood can be converted to list of LatLngAndGeohash, if needed). Then there will be no need to override createMarker 😉


The same question about claster marker icon, it would be nice to have an opportunity to override it create func.

pro100svitlo avatar Aug 26 '19 15:08 pro100svitlo