diff --git a/blazorators.sln b/blazorators.sln index caf38bc..fddfafd 100644 --- a/blazorators.sln +++ b/blazorators.sln @@ -34,7 +34,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Serialization", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Geolocation.WebAssembly", "src\Blazor.Geolocation.WebAssembly\Blazor.Geolocation.WebAssembly.csproj", "{0BAC9703-45EE-4E9E-A0F0-556F02FCB901}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor.Geolocation.Server", "src\Blazor.Geolocation.Server\Blazor.Geolocation.Server.csproj", "{A9F3FE17-EF4C-44B8-B265-7D7DBAA42F84}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Geolocation.Server", "src\Blazor.Geolocation.Server\Blazor.Geolocation.Server.csproj", "{A9F3FE17-EF4C-44B8-B265-7D7DBAA42F84}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/samples/Blazor.ExampleConsumer/Components/BingMap.razor b/samples/Blazor.ExampleConsumer/Components/BingMap.razor new file mode 100644 index 0000000..86c486a --- /dev/null +++ b/samples/Blazor.ExampleConsumer/Components/BingMap.razor @@ -0,0 +1,19 @@ +@inject IJSInProcessRuntime JavaScript + +
+ +@code { + [Parameter, EditorRequired] + public GeolocationPosition Position { get; set; } = null!; + + protected override void OnParametersSet() + { + if (Position is null or { Coords: null }) + { + return; + } + + JavaScript.InvokeVoid( + "app.loadMap", "map", Position.Coords.Latitude, Position.Coords.Longitude); + } +} diff --git a/samples/Blazor.ExampleConsumer/GlobalUsings.cs b/samples/Blazor.ExampleConsumer/GlobalUsings.cs new file mode 100644 index 0000000..83cb9f0 --- /dev/null +++ b/samples/Blazor.ExampleConsumer/GlobalUsings.cs @@ -0,0 +1,6 @@ +// Copyright (c) David Pine. All rights reserved. +// Licensed under the MIT License. + +global using System.Text.Json; +global using System.Text.Json.Serialization; +global using Microsoft.JSInterop; diff --git a/samples/Blazor.ExampleConsumer/Pages/ClientPosition.razor b/samples/Blazor.ExampleConsumer/Pages/ClientPosition.razor index 5a131c3..86de0b3 100644 --- a/samples/Blazor.ExampleConsumer/Pages/ClientPosition.razor +++ b/samples/Blazor.ExampleConsumer/Pages/ClientPosition.razor @@ -34,46 +34,6 @@@json
}
-}
-@code {
- readonly JsonSerializerOptions _opts = new()
- {
- WriteIndented = true,
- PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
- DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
- };
- readonly PositionOptions _options = new()
- {
- EnableHighAccuracy = true,
- MaximumAge = 0,
- Timeout = 15_000
- };
-
- GeolocationPosition? _position;
- GeolocationPositionError? _positionError;
- bool _isLoading = true;
-
- protected override void OnInitialized() =>
- Geolocation.GetCurrentPosition(
- component: this,
- onSuccessCallbackMethodName: nameof(OnPositionRecieved),
- onErrorCallbackMethodName: nameof(OnPositionError),
- options: _options);
-
- [JSInvokable]
- public void OnPositionRecieved(GeolocationPosition position)
- {
- _isLoading = false;
- _position = position;
- StateHasChanged();
- }
-
- [JSInvokable]
- public void OnPositionError(GeolocationPositionError positionError)
- {
- _isLoading = false;
- _positionError = positionError;
- StateHasChanged();
- }
-}
+