Mehigh17 / BlazorLeaflet

BlazorLeaflet is a Blazor component wrapping Leaflet's APIs, offering a simple and homogeneous implementation of the Leaflet maps.
MIT License
180 stars 91 forks source link

Stop working after "RemoveLayer(Marker)" #59

Open markus-renezeder opened 3 years ago

markus-renezeder commented 3 years ago

Hello and thank you very much for sharing your code with us!

I was working with an "older" version of your code and it was working fine. After I found the possibility to use the map bounds in the current version, I updated the code. After the update the application stops working if I remove a marker from the map (the Blazor app stops, the map is still working).

You can reproduce it with your sample application by trying to draw a shape.

I did a little bit of research and restored the async function from the older version in LeafletInterop.cs which works for me.

//public static void RemoveLayer(IJSRuntime jsRuntime, string mapId, string layerId)
//{
//  jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.removeLayer", mapId, layerId).GetAwaiter().GetResult();
//  DisposeLayerReference(layerId);
//}

public static async ValueTask RemoveLayer(IJSRuntime jsRuntime, string mapId, string layerId)
{
    await jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.removeLayer", mapId, layerId);
    DisposeLayerReference(layerId);
}

I'm using .NET Core 5, Blazor Server Side.

BR Markus