Reorganise project structure and namespaces. Remove Leaflet project and replace with Darnton.Blazor.Leaflet package.

This commit is contained in:
Bernard Darnton
2020-10-28 10:25:04 +13:00
parent 9576c5aa5b
commit 7dc4cea8ae
46 changed files with 431 additions and 441 deletions
+21 -6
View File
@@ -1,14 +1,16 @@
using BlazorDeviceInterop.Components.LeafletMap;
using BlazorDeviceInterop.Geolocation;
using Darnton.Blazor.Leaflet.LeafletMap;
using Darnton.Blazor.DeviceInterop.Geolocation;
using BlazorDeviceTestRig.Geolocation;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace BlazorDeviceTestRig.Pages
{
public class GeolocationBase : ComponentBase
public class GeolocationBase : ComponentBase, IDisposable
{
[Inject] public IJSRuntime JSRuntime { get; set; }
[Inject] public IGeolocationService GeolocationService { get; set; }
@@ -31,7 +33,7 @@ namespace BlazorDeviceTestRig.Pages
protected GeolocationResult LastWatchPositionResult { get; set; }
protected string LastWatchLatitude => LastWatchPositionResult?.Position?.Coords?.Latitude.ToString("F2");
protected string LastWatchLongitude => LastWatchPositionResult?.Position?.Coords?.Longitude.ToString("F2");
protected string LastWatchTimestamp => LastWatchPositionResult?.Position?.DateTime.ToString();
protected string LastWatchTimestamp => LastWatchPositionResult?.Position?.DateTimeOffset.ToString();
protected string ToggleWatchCommand => isWatching ? "Stop watching" : "Start watching";
public GeolocationBase() : base()
@@ -77,8 +79,7 @@ namespace BlazorDeviceTestRig.Pages
{
if (isWatching)
{
GeolocationService.WatchPositionReceived -= HandleWatchPositionReceived;
await GeolocationService.ClearWatch(WatchHandlerId.Value);
await StopWatching();
WatchHandlerId = null;
foreach (var marker in WatchMarkers)
{
@@ -96,6 +97,12 @@ namespace BlazorDeviceTestRig.Pages
StateHasChanged();
}
private async Task StopWatching()
{
GeolocationService.WatchPositionReceived -= HandleWatchPositionReceived;
await GeolocationService.ClearWatch(WatchHandlerId.Value);
}
private async void HandleWatchPositionReceived(object sender, GeolocationEventArgs e)
{
LastWatchPositionResult = e.GeolocationResult;
@@ -120,5 +127,13 @@ namespace BlazorDeviceTestRig.Pages
}
StateHasChanged();
}
public async void Dispose()
{
if (isWatching)
{
await StopWatching();
}
}
}
}