arnaudleclerc / AzureMapsControl.Components

Razor Components for azure-maps-control
MIT License
34 stars 12 forks source link

RemoveHtmlMarkersAsync() Only removes the first marker #105

Open blackboxlogic opened 2 days ago

blackboxlogic commented 2 days ago

Describe the bug RemoveHtmlMarkersAsync() accepts a params array of markers, but it only removes the first marker passed in.

To Reproduce

@page "/Markers/HtmlMarkersRemove"
@rendermode InteractiveServer
@using AzureMapsControl.Components.Markers
@using AzureMapsControl.Components.Atlas

@using AzureMapsControl.Components.Map
<AzureMap Id="map"
          EventActivationFlags="MapEventActivationFlags
                                .None()
                                .Enable(MapEventType.Click, MapEventType.Load)"
          OnClick="OnMapClick" OnLoad="OnMapLoad" />

@code
{
    private List<HtmlMarker> Markers = new List<HtmlMarker>();

    public async Task OnMapLoad(MapEventArgs eventArgs)
    {
        for(int i = 0; i < 10; i++)
        {
            Markers.Add(new HtmlMarker(new HtmlMarkerOptions
                {
                    Position = new Position(47.3769 + i, 8.5417 + i)
                }, HtmlMarkerEventActivationFlags.None()));
        }
    }

    public bool Added = false;

    public async Task OnMapClick(MapMouseEventArgs eventArgs)
    {
        if (Added)
        {
            // foreach (var marker in Markers)
            // {
            //  await eventArgs.Map.RemoveHtmlMarkersAsync(marker);
            // }
            await eventArgs.Map.RemoveHtmlMarkersAsync(Markers);
        }
        else
        {
            await eventArgs.Map.AddHtmlMarkersAsync(Markers);
        }

        Added = !Added;
    }
}

Clicking once on the map adds 10 markers. Clicking again on the map only removes one marker. Replace the bulk operations with the loop version (currently commented out) and see that it works as expected.

Expected behavior RemoveHtmlMarkersAsync() should remove all the markers that are passed in.

Desktop (please complete the following information):

Additional context The console output correctly indicates that all 10 items are removed, but the visual on the map only removes the first. I have not confirmed that this isn't an issue with azure maps. I believe AddHtmlMarkersAsync() and UpdateHtmlMarkersAsync() are working correctly.