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

Custom Info windo

mohamed6996 opened this issue · comments

Currently, info window displays the title as count id. I need to to display q custom title.

ugly workaround:

  updateMarkers(Set<Marker> markers) {
    setState(() {
      _markers = markers.map(
        (item) => item.infoWindow.title != '1'
          ? item
          : () {
            for (var i = 0; i < widget.locations.length; i++) {
              if (
                widget.locations[i].geoPosition == item.location.geoPosition
              ) {
                return item.copyWith(
                  infoWindowParam: InfoWindow(
                    title: 'new title'
                    snippet: 'new snippet',
                  )
                );
              }
            }
            return item;
          }()
      ).toSet();

    });
  }

ugly workaround:

  updateMarkers(Set<Marker> markers) {
    setState(() {
      _markers = markers.map(
        (item) => item.infoWindow.title != '1'
          ? item
          : () {
            for (var i = 0; i < widget.locations.length; i++) {
              if (
                widget.locations[i].geoPosition == item.location.geoPosition
              ) {
                return item.copyWith(
                  infoWindowParam: InfoWindow(
                    title: 'new title'
                    snippet: 'new snippet',
                  )
                );
              }
            }
            return item;
          }()
      ).toSet();

    });
  }

Good work, @felpsio - I've tweaked your solution for my own use case where I have approximately 3000 markers and works fine...

  _updateMarkers(Set<Marker> markers) {
    //TODO see https://github.com/giandifra/clustering_google_maps/issues/15
    setState(() {
      _markers = markers
          .map((clusterMarker) => () {
                for (var i = 0; i < widget.markers.length; i++) {
                  var marker = widget.markers[i];
                  if (marker.position == clusterMarker.position) {
                    return clusterMarker.copyWith(
                      infoWindowParam: marker.infoWindow,
                      iconParam: marker.icon,
                    );
                  }
                }
                return clusterMarker;
              }())
          .toSet();
    });
  }