Флаттер: обновление кластеризации на картах Google - PullRequest
1 голос
/ 20 октября 2019

Я использую Кластеризация для Flutter Google Maps Плагин для кластеризации карт Google. Проблема, которую я хочу решить, заключается в обновлении кластеров во время выполнения, скажем, что первоначальный список содержит 100 элементов и отображается на карте. Когда я выполняю фильтрацию, список будет 50, так как обновить кластер, чтобы он показывал только 50не 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;
...