lolochristen / OpenLayers.Blazor

An Map component for Blazor based on OpenLayers with support for swisstopo swiss maps.
MIT License
42 stars 15 forks source link

C# and Javascript Error : OnInternalCenterChanged(Coordinate coordinate) #37

Closed VibertJ closed 8 months ago

VibertJ commented 9 months ago

Hello, I have the following Javascript Error in my projet and I can see you have the exact same problem on your demo site : https://openlayers-blazor-demo.laurent-christen.ch/ blazor.webassembly.js:1 Uncaught (in promise) Error: System.NullReferenceException: Arg_NullReferenceException at OpenLayers.Blazor.Map.OnInternalCenterChanged(/Coordinate coordinate) at g.endInvokeDotNetFromJS (blazor.webassembly.js:1:3136) at Object.gn [as endInvokeDotNetFromJS] (blazor.webassembly.js:1:58655) ... Those errors accumulates (see my screenshot of DevTools) and seems to have secondaries effects on you demo project. (I'm not sure but markers don't work anymore) Any ideas of a fix ? Best regards, Jerome

image

In my Blazor server project, the debugger stops on OnInternalCenterChange (screenshot bellow) image

artemfomin commented 8 months ago

Same issue with OSM. No fix yet

artemfomin commented 8 months ago

As it is the first error thrown by JS might appear (yet untraceable) that other features like adding a marker don't work due to initial map JS object failure. Tried different ways of dynamic adding markers (from the one from examples to manual SetLayers()) but none works. As a surface fix might be in Map.cs:

public async Task OnInternalCenterChanged(Coordinate coordinate)
{
  if (coordinate?.Equals(this.Center) ?? true)
    return;
  this.Center = coordinate;
  await this.CenterChanged.InvokeAsync(coordinate);
}
lolochristen commented 8 months ago

The component had a major serialization issue with some local settings/globalization settings. When explicitly enforcing locals with a comma as decimal separators, I could also not add markers as coordinates have been invalid and raising events failed. The serialization issue is fixed (including some unit tests) in latest version 1.5.4. Please verify.

VibertJ commented 8 months ago

For my specific context (OpenStreetMap), you have fixed the Javascript error and made the add of Markers functional. I appreciate your effort ! 🙏🏼 Jerome