Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cluster perform no update after adding new marker to list #180

Closed
cwreden opened this issue Sep 20, 2023 · 5 comments
Closed

Cluster perform no update after adding new marker to list #180

cwreden opened this issue Sep 20, 2023 · 5 comments
Labels

Comments

@cwreden
Copy link

cwreden commented Sep 20, 2023

I am using the version 1.2.0 and trying to add new markers to list by button or search results.

When I using the flutter_map MarkerLayer the added maker is displayed on the map, but not for the cluster layer.

Maybe I missed something from the examples and you can give me a hint what I have to change.

Here a code snippet:

List<Marker> _markers = [];
List<Marker> _testMarkers = [];

...
PopupScope(
        popupController: _popupController,
        child: FlutterMap(
          mapController: mapController,
          options: MapOptions(
            zoom: 9.2,
            onTap: (_, __) => _popupController.hideAllPopups(),
          ),
          nonRotatedChildren: [
            RichAttributionWidget(
              attributions: [
                TextSourceAttribution(
                  'OpenStreetMap contributors',
                  onTap: () => Uri.parse('https://openstreetmap.org/copyright'),
                ),
              ],
            ),
          ],
          children: [
            TileLayer(
              urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
              userAgentPackageName: 'com.example.app',
            ),
            MarkerLayer(markers: _testMarkers),
            MarkerClusterLayerWidget(
                options: MarkerClusterLayerOptions(
                  markers: _markers,
                  popupOptions: PopupOptions(
                  //     popupSnap: PopupSnap.markerTop,
                      popupController: _popupController,
                      popupBuilder: (_, marker) {
                        return MarkerPopup(marker: marker,);
                      }),
                  builder: (context, markers) {
                    return Container(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(20),
                          color: Colors.blue),
                      child: Center(
                        child: Text(
                          markers.length.toString(),
                          style: const TextStyle(color: Colors.white),
                        ),
                      ),
                    );
                  },
                ),
            ),
          ],
        ),
      ),
...
addMarker() {
_markers.add(...);  // did not work
_testMarkers.add(...); // works
}

Best regards
Chris

@nahit-fidanci-alg
Copy link

I have the same issue. I tried to rebuild the whole widget tree but it didn't work.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Oct 26, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

@SimonTellier
Copy link

I don't know if anyone has answered your question, but I had the same problem as you.
You need to rebuild a new list of markers for your cluster to be updated.

    setState(() {
      markers = List.from(markers);
    });

@nahit-fidanci-alg
Copy link

@SimonTellier Thank you for your reply Simon. I started to use SuperCluster which makes things easier. But, your answer makes sense to me. The map cannot respond to changes in the list since it doesn't look up inside. I think a new list would need to be solved as you suggested. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants