-
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: update Geolocations demos (#875)
Co-authored-by: Argo Zhang <argo@live.ca>
- Loading branch information
Showing
5 changed files
with
164 additions
and
172 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
src/BootstrapBlazor.Shared/Demos/Geolocations/GeolocationNormal.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
@using BootstrapBlazor.Shared.Samples | ||
@inject IStringLocalizer<Geolocations> Localizer | ||
@inject IJSRuntime JSRuntime | ||
@implements IAsyncDisposable | ||
|
||
<div> | ||
@if (WatchID == 0) | ||
{ | ||
<Button Text="@Localizer["GetLocationButtonText"]" OnClick="GetLocation"></Button> | ||
<Button Text="@Localizer["WatchPositionButtonText"]" OnClick="WatchPosition"></Button> | ||
} | ||
else | ||
{ | ||
<Button Text="@Localizer["ClearWatchPositionButtonText"]" OnClick="ClearWatchPosition"></Button> | ||
} | ||
@if (Model != null) | ||
{ | ||
<div class="form-inline row g-3 mt-3"> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Longitude" ShowLabel="true" DisplayText="@Localizer["Longitude"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Latitude" ShowLabel="true" DisplayText="@Localizer["Latitude"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Accuracy" ShowLabel="true" DisplayText="@Localizer["Accuracy"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Altitude" ShowLabel="true" DisplayText="@Localizer["Altitude"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.AltitudeAccuracy" ShowLabel="true" DisplayText="@Localizer["AltitudeAccuracy"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Heading" ShowLabel="true" DisplayText="@Localizer["Heading"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Speed" ShowLabel="true" DisplayText="@Localizer["Speed"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.CurrentDistance" ShowLabel="true" DisplayText="@Localizer["CurrentDistance"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.TotalDistance" ShowLabel="true" DisplayText="@Localizer["TotalDistance"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.LastUpdateTime" ShowLabel="true" DisplayText="@Localizer["LastUpdateTime"]" /> | ||
</div> | ||
</div> | ||
} | ||
<BlockLogger @ref="Trace" class="mt-3" /> | ||
</div> | ||
|
||
@code { | ||
private JSInterop<GeolocationNormal>? Interop { get; set; } | ||
|
||
[NotNull] | ||
private BlockLogger? Trace { get; set; } | ||
|
||
private GeolocationItem? Model { get; set; } | ||
|
||
/// <summary> | ||
/// 获得/设置 获取持续定位监听器ID | ||
/// </summary> | ||
private long WatchID { get; set; } | ||
|
||
private async Task GetLocation() | ||
{ | ||
Interop ??= new JSInterop<GeolocationNormal>(JSRuntime); | ||
var ret = await Geolocation.GetLocaltion(interop: Interop, component: this, callbackMethodName: nameof(GetLocationCallback)); | ||
Trace.Log(ret ? Localizer["GetLocationResultSuccess"] : Localizer["GetLocationResultFailed"]); | ||
} | ||
private async Task WatchPosition() | ||
{ | ||
try | ||
{ | ||
Interop ??= new JSInterop<GeolocationNormal>(JSRuntime); | ||
WatchID = await Geolocation.WatchPosition(Interop, this, nameof(GetLocationCallback)); | ||
Trace.Log(WatchID != 0 ? Localizer["WatchPositionResultSuccess"] : Localizer["WatchPositionResultFailed"]); | ||
Trace.Log($"WatchID : {WatchID}"); | ||
} | ||
catch (Exception) | ||
{ | ||
Trace.Log(Localizer["WatchPositionResultFailed"]); | ||
} | ||
} | ||
|
||
private async Task ClearWatchPosition() | ||
{ | ||
if (WatchID != 0) | ||
{ | ||
Interop ??= new JSInterop<GeolocationNormal>(JSRuntime); | ||
var ret = await Geolocation.ClearWatchPosition(Interop, WatchID); | ||
if (ret) | ||
{ | ||
WatchID = 0; | ||
} | ||
Trace.Log(ret ? Localizer["ClearWatchPositionResultSuccess"] : Localizer["ClearWatchPositionResultFailed"]); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="item"></param> | ||
[JSInvokable] | ||
public void GetLocationCallback(GeolocationItem item) | ||
{ | ||
Model = item; | ||
StateHasChanged(); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="disposing"></param> | ||
protected virtual async ValueTask DisposeAsync(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
if (Interop != null) | ||
{ | ||
if (WatchID != 0) | ||
{ | ||
await Geolocation.ClearWatchPosition(Interop, WatchID); | ||
} | ||
|
||
Interop.Dispose(); | ||
Interop = null; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public async ValueTask DisposeAsync() | ||
{ | ||
await DisposeAsync(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,14 @@ | ||
@page "/geolocations" | ||
@inject IStringLocalizer<Geolocations> Localizer | ||
|
||
<h3>@Localizer["Title"]</h3> | ||
<h3>@Localizer["GeolocationsTitle"]</h3> | ||
|
||
<DemoBlock Title="@Localizer["BaseUsageText"]" Introduction="@Localizer["IntroText1"]" Name="Normal"> | ||
<p>@Localizer["IntroText2"]</p> | ||
<DemoBlock Title="@Localizer["GeolocationNormalText"]" | ||
Introduction="@Localizer["GeolocationNormalIntro"]" | ||
Name="Normal" | ||
Demo="typeof(Demos.Geolocations.GeolocationNormal)"> | ||
<p>@Localizer["GeolocationNormalIntro2"]</p> | ||
<Tips> | ||
<p>@Localizer["IntroText3"]</p> | ||
<p>@Localizer["GeolocationNormalIntro3"]</p> | ||
</Tips> | ||
@if (WatchID == 0) | ||
{ | ||
<Button Text="@Localizer["GetLocationButtonText"]" OnClick="GetLocation"></Button> | ||
<Button Text="@Localizer["WatchPositionButtonText"]" OnClick="WatchPosition"></Button> | ||
} | ||
else | ||
{ | ||
<Button Text="@Localizer["ClearWatchPositionButtonText"]" OnClick="ClearWatchPosition"></Button> | ||
} | ||
@if (Model != null) | ||
{ | ||
<div class="form-inline row g-3 mt-3"> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Longitude" ShowLabel="true" DisplayText="@Localizer["Longitude"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Latitude" ShowLabel="true" DisplayText="@Localizer["Latitude"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Accuracy" ShowLabel="true" DisplayText="@Localizer["Accuracy"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Altitude" ShowLabel="true" DisplayText="@Localizer["Altitude"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.AltitudeAccuracy" ShowLabel="true" DisplayText="@Localizer["AltitudeAccuracy"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Heading" ShowLabel="true" DisplayText="@Localizer["Heading"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.Speed" ShowLabel="true" DisplayText="@Localizer["Speed"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.CurrentDistance" ShowLabel="true" DisplayText="@Localizer["CurrentDistance"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.TotalDistance" ShowLabel="true" DisplayText="@Localizer["TotalDistance"]" /> | ||
</div> | ||
<div class="col-12 col-sm-4"> | ||
<Display Value="@Model.LastUpdateTime" ShowLabel="true" DisplayText="@Localizer["LastUpdateTime"]" /> | ||
</div> | ||
</div> | ||
} | ||
<BlockLogger @ref="Trace" class="mt-3" /> | ||
</DemoBlock> |
109 changes: 0 additions & 109 deletions
109
src/BootstrapBlazor.Shared/Samples/Geolocations.razor.cs
This file was deleted.
Oops, something went wrong.