Skip to content

Commit

Permalink
Merge pull request #30
Browse files Browse the repository at this point in the history
Fix deserializing of LatLng and LatLngBounds
  • Loading branch information
bjtrounson authored Nov 13, 2023
2 parents a2e5a34 + 40ee865 commit 1bef2ee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task<FeatureGroup> BringToBack()
/// <summary>
/// Returns the LatLngBounds of the Feature Group (created from bounds and coordinates of its children).
/// </summary>
/// <returns>IJSObjectReference</returns>
/// <returns>LatLngBounds</returns>
/// <exception cref="NullReferenceException"></exception>
public async Task<LatLngBounds?> GetBounds()
{
Expand Down
7 changes: 6 additions & 1 deletion BlazorLeafletInterop/Models/Basics/LatLng.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace BlazorLeafletInterop.Models.Basics;
using System.Text.Json.Serialization;

namespace BlazorLeafletInterop.Models.Basics;

public class LatLng
{
Expand All @@ -20,8 +22,11 @@ public LatLng(double lat, double lng, double alt)
Alt = alt;
}

[JsonPropertyName("lat")]
public double Lat { get; set; }
[JsonPropertyName("lng")]
public double Lng { get; set; }
[JsonPropertyName("alt")]
public double Alt { get; set; }

public double GetDistanceToPointInMiles(LatLng to)
Expand Down
6 changes: 5 additions & 1 deletion BlazorLeafletInterop/Models/Basics/LatLngBounds.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace BlazorLeafletInterop.Models.Basics;
using System.Text.Json.Serialization;

namespace BlazorLeafletInterop.Models.Basics;

public class LatLngBounds
{
Expand All @@ -15,8 +17,10 @@ public LatLngBounds(LatLng southwest, LatLng northeast)
}

// ReSharper disable once MemberCanBePrivate.Global
[JsonPropertyName("_southWest")]
public LatLng SouthWest { get; set; }
// ReSharper disable once MemberCanBePrivate.Global
[JsonPropertyName("_northEast")]
public LatLng NorthEast { get; set; }

public LatLngBounds Extend(LatLng point)
Expand Down
8 changes: 8 additions & 0 deletions ExampleApp/Pages/GeoJsonTest.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<h3>Blazor Leaflet Interop GeoJson Test</h3>
<button @onclick="@(() => GeoJsonLayer?.EachLayer(_onEachLayer))">Open Popup</button>
<button @onclick=GenerateNewFeatureCollection>Generate More Markers</button>
<button @onclick=GetBounds>Get GeoJSON bounds</button>
</div>

@code {
Expand Down Expand Up @@ -61,6 +62,13 @@
base.OnInitialized();
CreateRandomMarkersForFeatureCollection();
}

private async Task GetBounds()
{
if (GeoJsonLayer == null) return;
var bounds = await GeoJsonLayer.GetBounds();
if (bounds != null) Console.WriteLine(bounds.ToBBoxString());
}

private void GenerateNewFeatureCollection()
{
Expand Down

0 comments on commit 1bef2ee

Please sign in to comment.