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

Update clustering on google maps

mohamed6996 opened this issue · comments

The problem i want to solve is to update the clusters at run time
say the initial list contains 100 items and are shown on the map, when i do some filteration, the list will be 50, so how to update the cluster to show only 50 not 100 ?

@override
  Widget build(BuildContext context) {
    super.build(context);
    final appState = Provider.of<AppState>(context);
    return FutureBuilder(
      future: initMemoryClustering(appState.latlgm),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.waiting) {
          return Center(child: Text('waiting'));
        }
        //return Container(child: Text('${appState.latlgm.length}'));
        return Container(
          height: 400,
          child: GoogleMap(
            markers: markers,
            onCameraIdle: clusteringHelper.onMapIdle,
            onCameraMove: (newPosition) {
              clusteringHelper.onCameraMove(newPosition, forceUpdate: false);
            },
            myLocationButtonEnabled: true,
            myLocationEnabled: true,
            scrollGesturesEnabled: true,
            zoomGesturesEnabled: true,
            tiltGesturesEnabled: true,
            mapType: MapType.normal,
            initialCameraPosition: cairo,
            onMapCreated: (GoogleMapController controller) {
              clusteringHelper.mapController = controller;
              _controller.complete(controller);
              clusteringHelper.updateMap();
              clusteringHelper.updateAggregatedPoints();
            },
          ),
        );
      },
    );



updateMarkers(Set<Marker> markers) {
    setState(() {
      this.markers = markers;
    });
  }

  initMemoryClustering(List<LatLngAndGeohash> list) {
    clusteringHelper = ClusteringHelper.forMemory(
      list: list,
      updateMarkers: updateMarkers,
      aggregationSetup: AggregationSetup(markerSize: 130),
    );
  }

  @override
  bool get wantKeepAlive => true;

@mohamed6996 use _clusteringHelper.updateData(list);