Open Jamey-7 opened 4 weeks ago
Hi Jamey,
I had a similar issue trying to find a way to assign an event to both clustered and un-clustered annotations. In the end I came up with the below:
onTapListener: (context) async {
var results = await mapboxMap!.queryRenderedFeatures(
RenderedQueryGeometry(value: jsonEncode(context.touchPosition.encode()), type: Type.SCREEN_COORDINATE),
RenderedQueryOptions(layerIds: ["unclustered-point", "cluster-count"])
);
// process the results
...
},
...
Add an onTapListener to your MapWidget, then use the queryRenderedFeatures method to query the tapped area. You can specify which layer(s) you are interested in querying in the RenderedQueryOptions. This returns an array of results (if any). You can then either get the first result or iterate the matches. For clustered items I then use getGeoJsonClusterExpansionZoom to zoom in upon tapping a clustered item.
I'm not sure if this is the best method, but it was the only solution I could find.
Has anyone found out a way when using clustering to be able to tap a unclustered item? I have tried everything and I can't figure out how to be able to make it so I can attach a method to a circle that is unclustered? I don't see a way to add clustering to point annotations I have tried but I am unable to get it to work for only the unclustered items of a group.
Here is my code: