Clearing callouts when another is clicked
See original GitHub issueI am fairly new to C#/.NET and have been working through building an app. I know .NET7 recently released and brought map functionality to Maui, but have already implemented code using MAPSUI. There doesn’t seem to be great documentation surrounding the usage of this, however.
Looking through their getting started page and their examples on Github (specifically: SingleCalloutSample) I was able to get my list of places to show up on the map and when clicked display certain features.This has led to me only being able to toggle whether the callout is displayed or not. What I am hoping to figure out is how to disable all other callouts once another location is selected, so that only a single callout is displayed at a time.
I am aware the following code is the logic dictating the callout displays, but not sure how to adjust it to “wipe” existing callouts on click. Any help would be greatly appreciated:
private static void MapOnInfo(object? sender, MapInfoEventArgs e)
{
var calloutStyle = e.MapInfo?.Feature?.Styles.Where(s => s is CalloutStyle).Cast().FirstOrDefault();
if (calloutStyle != null)
{
calloutStyle.Enabled = !calloutStyle.Enabled;
e.MapInfo?.Layer?.DataHasChanged(); // To trigger a refresh of graphics.
}
}
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (5 by maintainers)

Top Related StackOverflow Question
Ok, if you don’t want to use Pins, then you have to do it by hand.
The function
CreatePointLayer()creates aMemoryLayerthat holds one or moreFeatures. That are your pins. Each of thisFeaturehas none (Featureisn’t drawn), one or moreStyles. ThisStyletells Mapsui, how theFeatureshould be drawn. One of thisStylesis theCalloutStyle. It says Mapsui, that at this place a callout should be drawn, but only, ifCalloutStyle.Enabled=true.To hide all callouts on your layer, you have to set
Enabled=falsefor allFeaturethat have aCalloutStyle.That’s it.
Or you save the last
Featurewith a callout 😉I found that
e.MapInfo?.Layerextends fromILayerwhich has no definition forFeatures:CS1061 'ILayer' does not contain a definition for 'Features' and no accessible extension method 'Features' accepting a first argument of type 'ILayer' could be found (are you missing a using directive or an assembly reference?)I did get this working by creating a
List<CalloutStyle> calloutlistto keep track of clicked callouts and updated the code section as shown below: