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
@@ -6,6 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Darnton.Blazor.Leaflet" Version="0.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
@@ -14,8 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BlazorDeviceInterop.Components\BlazorDeviceInterop.Components.csproj" />
<ProjectReference Include="..\BlazorDeviceInterop\BlazorDeviceInterop.csproj" />
<ProjectReference Include="..\Darnton.Blazor.DeviceInterop\Darnton.Blazor.DeviceInterop.csproj" />
</ItemGroup>
</Project>
@@ -1,5 +1,5 @@
using BlazorDeviceInterop.Components.LeafletMap;
using BlazorDeviceInterop.Geolocation;
using Darnton.Blazor.Leaflet.LeafletMap;
using Darnton.Blazor.DeviceInterop.Geolocation;
namespace BlazorDeviceTestRig.Geolocation
{
+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();
}
}
}
}
+1 -5
View File
@@ -1,13 +1,9 @@
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using BlazorDeviceInterop.Geolocation;
using Darnton.Blazor.DeviceInterop.Geolocation;
namespace BlazorDeviceTestRig
{
+1 -1
View File
@@ -6,6 +6,6 @@
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using BlazorDeviceInterop.Components.LeafletMap
@using Darnton.Blazor.Leaflet.LeafletMap
@using BlazorDeviceTestRig
@using BlazorDeviceTestRig.Shared
+3 -3
View File
@@ -23,12 +23,12 @@
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/BlazorDeviceInterop/js/Geolocation.js"></script>
<script src="_content/Darnton.Blazor.DeviceInterop/js/Geolocation.js"></script>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<script src="_content/BlazorDeviceInterop.Components/device-interop.js"></script>
<script src="_content/BlazorDeviceInterop.Components/leaflet-map/leaflet-map.js"></script>
<script src="_content/Darnton.Blazor.Leaflet/device-interop.js"></script>
<script src="_content/Darnton.Blazor.Leaflet/leaflet-map/leaflet-map.js"></script>
</body>
</html>