question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clearing callouts when another is clicked

See original GitHub issue

I 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:closed
  • Created 10 months ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
charlennicommented, Nov 16, 2022

Ok, if you don’t want to use Pins, then you have to do it by hand.

The function CreatePointLayer() creates a MemoryLayerthat holds one or more Features. That are your pins. Each of this Feature has none (Feature isn’t drawn), one or more Styles. This Style tells Mapsui, how the Feature should be drawn. One of this Styles is the CalloutStyle. It says Mapsui, that at this place a callout should be drawn, but only, if CalloutStyle.Enabled=true.

To hide all callouts on your layer, you have to set Enabled=false for all Feature that have a CalloutStyle.

foreach(var feature in e.MapInfo?.Layer?.Features)
  foreach(var style in feature.Styles)
    if (style is CalloutStyle)
      ((CalloutStyle)style).Enabled = false;

That’s it.

Or you save the last Feature with a callout 😉

0reactions
RParkerEcommented, Nov 16, 2022

I found that e.MapInfo?.Layer extends from ILayer which has no definition for Features: 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> calloutlist to keep track of clicked callouts and updated the code section as shown below:

private static void MapOnInfo(object? sender, MapInfoEventArgs e)
        {
            var calloutStyle = e.MapInfo?.Feature?.Styles.Where(s => s is CalloutStyle).Cast<CalloutStyle>().FirstOrDefault();
            if (calloutStyle != null)
            {
                calloutlist.Add(calloutStyle);
                foreach (var callout in calloutlist)
                {
                    callout.Enabled = false;
                }
                calloutStyle.Enabled = !calloutStyle.Enabled;
                e.MapInfo?.Layer?.DataHasChanged(); // To trigger a refresh of graphics.
            }
            if (calloutlist.Count > 1)
                calloutlist.RemoveRange(0, calloutlist.Count - 1);
        }
Read more comments on GitHub >

github_iconTop Results From Across the Web

.NET Maui and MAPSUI Help - Clearing Callouts when ...
I am aware the following code is the logic dictating the callout displays, but not sure how to adjust it to "wipe" existing...
Read more >
About callout assets - Google Ads Help
Remove callouts · In your Google Ads account, click the Campaigns icon Campaigns Icon · Click the Assets drop down in the section...
Read more >
Use specific callout extensions in a campaign or ad group
Click the +Apply callouts button, which appears above the reporting table. Click Select callouts. Select the check boxes next to the callout extensions...
Read more >
Removing a callout? Creating enlarged plans? - AUGI Forums
There is no way to remove the callout unless you used your other method of duplicating floor plans and using the reference function....
Read more >
Clicking button it should reload the page, the callout must ...
My question is that clicking button it should reload the page, The callout must be perform asynchronous. Now its works like a reloading...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found