giandifra / clustering_google_maps

A Flutter package that recreate clustering technique in a Google Maps widget
MIT License
102 stars 47 forks source link

Custom Info windo #15

Open mohamed6996 opened 5 years ago

mohamed6996 commented 5 years ago

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

felpsio commented 5 years ago

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();

    });
  }
xni06 commented 4 years ago

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();
    });
  }