fis-sst / BlazorMaps

BlazorMaps is a Blazor library that provides a C# interface for maps provided by Leaflet.js library. It includes several Leaflet.js features which are easily accessible from C# level within a project and it does not require any use of JavaScript.
https://fis-sst.pl/en
MIT License
70 stars 26 forks source link

Marker.SetIcon crashes #22

Open Heshyo opened 2 years ago

Heshyo commented 2 years ago

Describe the bug Calling Marker.SetIcon to change the Icon crashes at the Javascript level.

To Reproduce

  1. Create a Marker and add it to the map
  2. Call SetIcon to update its Icon
  3. Exception in Javascript

Error

fail: WasmComponents.Map[0]
      Error occurred executing task work item.
Microsoft.JSInterop.JSException: t.icon.createIcon is not a function
TypeError: t.icon.createIcon is not a function
    at i._initIcon (https://unpkg.com/leaflet@1.7.1/dist/leaflet.js:5:72551)
    at i.setIcon (https://unpkg.com/leaflet@1.7.1/dist/leaflet.js:5:72179)
    at https://localhost:5001/_framework/blazor.webassembly.js:1:3332
    at new Promise (<anonymous>)
    at Object.beginInvokeJSFromDotNet (https://localhost:5001/_framework/blazor.webassembly.js:1:3306)
    at Object.St [as invokeJSFromDotNet] (https://localhost:5001/_framework/blazor.webassembly.js:1:59853)
    at _mono_wasm_invoke_js_blazor (https://localhost:5001/_framework/dotnet.6.0.6.z9b9uq0m6e.js:1:195300)
    at wasm://wasm/00971e46:wasm-function[219]:0x1a490
    at wasm://wasm/00971e46:wasm-function[167]:0xce5e
    at wasm://wasm/00971e46:wasm-function[166]:0xbd71
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.IJSObjectReference, Microsoft.JSInterop, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at FisSst.BlazorMaps.Marker.SetIcon(Icon icon) in A:\Test\BlazorMaps\FisSst.BlazorMaps\FisSst.BlazorMaps\Models\Markers\Marker.cs:line 47
   at WasmComponents.Map.UpdateIcon(Icon icon) in A:\Test\WasmComponents\Map.razor.cs:line 266

Additional context It seems the Icon isn't properly passed from C# to Javascript: in i._initIcon the t object is just empty, meaning t.icon is null leading to t.icon.createIcon is not a function.

samuelsshan commented 1 year ago

Yes, also has exception when marker.getIcon();