BlazorLeaflet
BlazorLeaflet copied to clipboard
Icons Size and Anchor in webassembly core hosted
Hi, thanks for your Leaflet wrapper ! I'm using it in a webassembly core hosted (.NET Core 3.1), and when I set a size or an Anchor to a marker, there a not added to the map anymore. I never stop to my breakpoint at the begining addMarker function in leafletBlazorInterops.js
I think this is an sort of incompatibility width Size? and Point? types.
I replaced
public Size? Size { get; set; }
public Point? Anchor { get; set; }
by
public int Width { get; set; }
public int Height { get; set; }
public int AnchorX { get; set; }
public int AnchorY { get; set; }
and
iconSize: icon.size ? L.point(icon.size.value.width, icon.size.value.height) : null,
iconAnchor: icon.anchor ? L.point(icon.anchor.value.x, icon.anchor.value.y) : null,
by
iconSize: (icon.width != 0 && icon.height != 0) ? L.point(icon.width, icon.height) : null,
iconAnchor: (icon.anchorX != 0 || icon.anchorY != 0) ? L.point(icon.anchorX, icon.anchorY) : null,
to make it works
It appears to be something about how Blazor WASM serializes nullable value types. (Still investigating.)
This appears to be a Blazor issue. https://github.com/dotnet/aspnetcore/issues/23885
I have the same issue still with .NET 5. @Rizov74's fix works luckily.
I have the same issue in .NET Core 5, Blazor Server Side. @Rizov74 fix works fine!