ichim / LeafletForBlazor-NuGet

LeafletForBlazor NuGet Package - You can quickly add a map control to your Blazor application - 2.2.2.2 version. #12 issue, StreamLegend customization
https://www.nuget.org/packages/LeafletForBlazor#versions-body-tab
73 stars 9 forks source link

Possible wrong conversion format for decimal separator #51

Open luciantin opened 3 weeks ago

luciantin commented 3 weeks ago

Hi Ichim, your map is amazing and thank you for all the hard work.

During development I noticed that points wouldn't show on some computers. I found that the array containing lat and lon coords was in the wrong format on the problematic computers it probably has to do with the local computers localization settings.

It uses a comma as the decimal separator

image

Correctly formats the decimal separator

image

ichim commented 3 weeks ago

Hello sir, i understood. I think this mistake is from .NET - cultureInfo/Globalization. Thanks for the report, sir!

ichim commented 3 weeks ago

Hello again,

I need more information!

image

I changed my windows settings so that the decimal separator is ",". The application works correctly. Use data stored in GeoJSON files or use Geometric.Points with StreamPoint collection??

luciantin commented 3 weeks ago

Hi, you are right that it works correctly even with wrong windows localization settings. I couldn't get the right format in dotnet by changing it in windows, it did not seem to affect CultureInfo.

This morning I got it working everywhere correctly, the way I fixed it globally was to set DefaultThreadCurrentCulture in Program.cs above builder.

        public static void Main(string[] args)
        {

            var cultureInfo = new CultureInfo("en-us");
            cultureInfo.NumberFormat.CurrencyDecimalSeparator = ".";  // prob not needed
            cultureInfo.NumberFormat.NumberDecimalSeparator = ".";   // prob not needed
            CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

            var builder = WebApplication.CreateBuilder(args);

            ....
          }

I used data fetched from a database as a decimal converted to a double in DisplayPointsFromArray.addPoint.

I cant change the code inside the .cs file but I'm sure that if you set the culture, just inside the thread that invokes js code, you could get it to behave in the same way.

image

A problem ex. would be : The culture of the thread is "Croatian", the decimal separator is a comma and because of that the string.Join(",", coordinates2) will use a comma and output coords to js in the format [14,234352,27,3463456].

I hope this was helpful.

ichim commented 3 weeks ago

Yes sir, i will be change/add and I make a new release!

ichim commented 3 weeks ago

Hello sir,

In a few minutes version 2.2.0.8 will be available

Thanks!