giandifra / clustering_google_maps

A Flutter package that recreate clustering technique in a Google Maps widget

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How create custom cluster markers?

pro100svitlo opened this issue · 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.