rorystephenson / flutter_map_supercluster

Very fast Marker clustering for flutter_map. Supports efficient adding/removing of Markers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failing to assign marker to initialMaker

701789262a opened this issue · comments

When I try to assign markers to a list and giving it to initialMarkers (doesn't matter if as a layer or a list of Marker), it throws:

../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_map_supercluster-3.0.0+1/lib/src/layer/expanded_cluster_manager.dart:99:71: Error: The argument type 'int' can't be assigned to the parameter type 'LayerCluster<Marker>'.
 - 'LayerCluster' is from 'package:supercluster/src/layer_element.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/supercluster-2.3.0/lib/src/layer_element.dart').
 - 'Marker' is from 'package:flutter_map/src/layer/marker_layer.dart' ('../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_map-4.0.0/lib/src/layer/marker_layer.dart').
          .childrenOf((layerCluster as ImmutableLayerCluster<Marker>).id)

This is how I set FlutterMap:

FlutterMap(
          nonRotatedChildren: <Widget>[
            SuperclusterLayer.immutable(
              controller: _superclusterController,
              calculateAggregatedClusterData: true,
              clusterWidgetSize: const Size(40, 40),
              anchor: AnchorPos.align(AnchorAlign.center),
              initialMarkers: layer,
              builder: (BuildContext context, LatLng position, int markerCount,
                  ClusterDataBase? extraClusterData) {
                return Container(child: Text("culo"));
              },
            )
          ],
          mapController: _mapController,
          options: MapOptions(
            onMapReady: () {
              _mapController.mapEventStream.listen((evt) {});
              // And any other `MapController` dependent non-movement methods
            },
            center: LatLng(41.902, 12.5),
            zoom: 7,
          ),
          children: [
            //MarkerLayer(markers: markers,),
            TileLayer(
              urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
              userAgentPackageName: 'com.example.app',
            ),
          ],
        ),

And this how I add Markers to list:

  loadJson() async {
    final String response =
        await rootBundle.loadString('TREMESTIERI_ETNEO.json');
    final data = await json.decode(response);
    for (var civ in data) {
      print(civ);
      markers.add(
        Marker(
            point: LatLng(
                double.parse(civ['latitude']), double.parse(civ['longitude'])),
            width: 50,
            height: 50,
            builder: (context) =>  IconButton(
                onPressed: () {
                  print("culo");
                },
                icon: Icon(
                  Icons.circle,
                ))),
      );
    }
    layer = MarkerLayer(
      markers: markers,
    );
  }

Even copying the example in example/ gives the same error

Hi @701789262a are you using 4.0.0? I accidentally pushed some dependency overrides in the examples. 4.0.0+1 should fix that (or 4.1.0 if you are using dart 3, I have just published it).

Closing for now but if this problem persists I'll reopen.