remove leaflet
This commit is contained in:
@@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aperio_Control_Centre.Conne
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aperio_Control_Centre.ACSDatabase.UnitTest", "Aperio_Control_Centre.ACSDatabase.UnitTest\Aperio_Control_Centre.ACSDatabase.UnitTest.csproj", "{BBE2C3F1-196E-4AE2-998C-1808F3140F44}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aperio_Control_Centre.LeafletBlazor", "Aperio_Control_Centre.LeafletBlazor\Aperio_Control_Centre.LeafletBlazor.csproj", "{6F7BB4AC-DF6B-4318-913D-0EEAFC931641}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aperio_Control_Centre.Export", "Aperio_Control_Centre.Export\Aperio_Control_Centre.Export.csproj", "{96CDC7AE-E4DE-4C57-8E85-A0A6840CAFA4}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aperio_Control_Centre.Export.UnitTest", "Aperio_Control_Centre.Export.UnitTest\Aperio_Control_Centre.Export.UnitTest.csproj", "{A20E97F7-8AB2-4A9A-A8A8-9902134BB223}"
|
||||
@@ -97,14 +95,6 @@ Global
|
||||
{BBE2C3F1-196E-4AE2-998C-1808F3140F44}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BBE2C3F1-196E-4AE2-998C-1808F3140F44}.Release|x64.ActiveCfg = Release|x64
|
||||
{BBE2C3F1-196E-4AE2-998C-1808F3140F44}.Release|x64.Build.0 = Release|x64
|
||||
{6F7BB4AC-DF6B-4318-913D-0EEAFC931641}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6F7BB4AC-DF6B-4318-913D-0EEAFC931641}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6F7BB4AC-DF6B-4318-913D-0EEAFC931641}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{6F7BB4AC-DF6B-4318-913D-0EEAFC931641}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{6F7BB4AC-DF6B-4318-913D-0EEAFC931641}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6F7BB4AC-DF6B-4318-913D-0EEAFC931641}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6F7BB4AC-DF6B-4318-913D-0EEAFC931641}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{6F7BB4AC-DF6B-4318-913D-0EEAFC931641}.Release|x64.Build.0 = Release|Any CPU
|
||||
{96CDC7AE-E4DE-4C57-8E85-A0A6840CAFA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{96CDC7AE-E4DE-4C57-8E85-A0A6840CAFA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{96CDC7AE-E4DE-4C57-8E85-A0A6840CAFA4}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="libman.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="libman.json">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<SupportedPlatform Include="browser" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,58 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract base class for types that represent JavaScript objects.
|
||||
/// </summary>
|
||||
public abstract class InteropObject : IAsyncDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The JavaScript binder used to talk to the interop layer.
|
||||
/// </summary>
|
||||
internal LeafletMapJSBinder JSBinder;
|
||||
|
||||
/// <summary>
|
||||
/// The JavaScript runtime object reference.
|
||||
/// </summary>
|
||||
internal IJSObjectReference JSObjectReference;
|
||||
|
||||
/// <summary>
|
||||
/// Creates the JavaScript object, stores a reference to it and the
|
||||
/// JavaScript runtime object used to create it.
|
||||
/// </summary>
|
||||
/// <param name="jsBinder">The JavaScript binder used to talk to the interop layer.</param>
|
||||
/// <returns>A task that represents the async create operation.</returns>
|
||||
internal async Task BindJsObjectReference(LeafletMapJSBinder jsBinder)
|
||||
{
|
||||
JSBinder = jsBinder;
|
||||
JSObjectReference = await CreateJsObjectRef();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the JavaScript object
|
||||
/// </summary>
|
||||
/// <returns>The reference to the new JavaScript object.</returns>
|
||||
protected abstract Task<IJSObjectReference> CreateJsObjectRef();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (JSObjectReference != null)
|
||||
await JSObjectReference.DisposeAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="InvalidOperationException"/> if the JavaScript binding has not been
|
||||
/// set up for this object.
|
||||
/// </summary>
|
||||
/// <param name="nullBindingMessage">The error message to be used when an exception is thrown.</param>
|
||||
internal void GuardAgainstNullBinding(string nullBindingMessage)
|
||||
{
|
||||
if (JSBinder is null)
|
||||
{
|
||||
throw new InvalidOperationException(nullBindingMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A rectangular area in pixel coordinates.
|
||||
/// </summary>
|
||||
public class Bounds : InteropObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The top left corner of the bounds.
|
||||
/// </summary>
|
||||
public Point Min { get; set; }
|
||||
/// <summary>
|
||||
/// The bottom right corner of the bounds.
|
||||
/// </summary>
|
||||
public Point Max { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Bounds instance.
|
||||
/// </summary>
|
||||
/// <param name="min">The top left corner of the bounds.</param>
|
||||
/// <param name="max">The bottom right corner of the bounds.</param>
|
||||
public Bounds(Point min, Point max)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<IJSObjectReference> CreateJsObjectRef()
|
||||
{
|
||||
if (Min.JSBinder is null)
|
||||
{
|
||||
await Min.BindJsObjectReference(this.JSBinder);
|
||||
}
|
||||
Min.GuardAgainstNullBinding("Cannot create Bounds object. No JavaScript binding has been set up for the Min property.");
|
||||
if (Max.JSBinder is null)
|
||||
{
|
||||
await Max.BindJsObjectReference(this.JSBinder);
|
||||
}
|
||||
Max.GuardAgainstNullBinding("Cannot create Bounds object. No JavaScript binding has been set up for the Max property.");
|
||||
return await JSBinder.JSRuntime.InvokeAsync<IJSObjectReference>("L.bounds", Min.JSObjectReference, Max.JSObjectReference);
|
||||
}
|
||||
|
||||
/// <inheritsdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[{Min}, {Max}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="Layer"/> that the user can interact with.
|
||||
/// <see href="https://leafletjs.com/reference-1.7.1.html#interactive-layer"/>
|
||||
/// </summary>
|
||||
public abstract class InteractiveLayer : Layer
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A point with a latitude and longitude.
|
||||
/// <see href="https://leafletjs.com/reference-1.7.1.html#latlng"/>
|
||||
/// </summary>
|
||||
public class LatLng : InteropObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Latitude in degrees.
|
||||
/// </summary>
|
||||
public double Lat { get; set; }
|
||||
/// <summary>
|
||||
/// Longitude in degrees.
|
||||
/// </summary>
|
||||
public double Lng { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a LatLng
|
||||
/// </summary>
|
||||
/// <param name="lat">Latitude in degrees.</param>
|
||||
/// <param name="lng">Longitude in degrees.</param>
|
||||
public LatLng(double lat, double lng)
|
||||
{
|
||||
Lat = lat;
|
||||
Lng = lng;
|
||||
}
|
||||
|
||||
private static double ConvertToDouble(string? value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool success = double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out double outVal);
|
||||
if (success)
|
||||
{
|
||||
return outVal;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public LatLng(string? lat, string? lng)
|
||||
{
|
||||
Lat = ConvertToDouble(lat);
|
||||
Lng = ConvertToDouble(lng);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<IJSObjectReference> CreateJsObjectRef()
|
||||
{
|
||||
return await JSBinder.JSRuntime.InvokeAsync<IJSObjectReference>("L.latLng", Lat, Lng);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({Lat}, {Lng})";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A rectangular geographical area on a map.
|
||||
/// <see href="https://leafletjs.com/reference-1.7.1.html#latlngbounds"/>
|
||||
/// </summary>
|
||||
public class LatLngBounds : InteropObject
|
||||
{
|
||||
private readonly LatLng _corner1;
|
||||
private readonly LatLng _corner2;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a LatLngBounds instance.
|
||||
/// </summary>
|
||||
/// <param name="corner1">The first corner defining the bounds.</param>
|
||||
/// <param name="corner2">The second corner defining the bounds, diagonally opposite the first.</param>
|
||||
public LatLngBounds(LatLng corner1, LatLng corner2)
|
||||
{
|
||||
_corner1 = corner1;
|
||||
_corner2 = corner2;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<IJSObjectReference> CreateJsObjectRef()
|
||||
{
|
||||
return await JSBinder.JSRuntime.InvokeAsync<IJSObjectReference>("L.latLngBounds", _corner1.JSObjectReference, _corner2.JSObjectReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A layer that can be added to a <see cref="Map"/>.
|
||||
/// </summary>
|
||||
public abstract class Layer : InteropObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the layer to a <see cref="Map"/>.
|
||||
/// </summary>
|
||||
/// <param name="map">The <see cref="Map"/> to add the Layer to.</param>
|
||||
/// <returns>The Layer.</returns>
|
||||
public async Task<Layer> AddTo(Map map)
|
||||
{
|
||||
if (JSBinder is null)
|
||||
{
|
||||
await BindJsObjectReference(map.JSBinder);
|
||||
}
|
||||
GuardAgainstNullBinding("Cannot add layer to map. No JavaScript binding has been set up.");
|
||||
var module = await JSBinder.GetLeafletMapModule();
|
||||
await module.InvokeVoidAsync("LeafletMap.Layer.addTo", this.JSObjectReference, map.JSObjectReference);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the Layer from the <see cref="Map"/> it's currently active on.
|
||||
/// </summary>
|
||||
/// <returns>The Layer.</returns>
|
||||
public async Task<Layer> Remove()
|
||||
{
|
||||
GuardAgainstNullBinding("Cannot remove layer from map. No JavaScript binding has been set up.");
|
||||
var module = await JSBinder.GetLeafletMapModule();
|
||||
await module.InvokeVoidAsync("LeafletMap.Layer.remove", this.JSObjectReference);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
//using Microsoft.JSInterop;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
//namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// A layer group that can be added to a <see cref="Map"/>.
|
||||
// /// </summary>
|
||||
// public abstract class LayerGroup : InteropObject
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// Adds the layer to a <see cref="Map"/>.
|
||||
// /// </summary>
|
||||
// /// <param name="map">The <see cref="Map"/> to add the Layer to.</param>
|
||||
// /// <returns>The Layer.</returns>
|
||||
// public async Task<LayerGroup> AddTo(Map map)
|
||||
// {
|
||||
// if (JSBinder is null)
|
||||
// {
|
||||
// await BindJsObjectReference(map.JSBinder);
|
||||
// }
|
||||
// GuardAgainstNullBinding("Cannot add layergroup to map. No JavaScript binding has been set up.");
|
||||
// var module = await JSBinder.GetLeafletMapModule();
|
||||
// await module.InvokeVoidAsync("LeafletMap.layerGroup.addTo", this.JSObjectReference, map.JSObjectReference);
|
||||
// return this;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Removes the Layer from the <see cref="Map"/> it's currently active on.
|
||||
// /// </summary>
|
||||
// /// <returns>The Layer.</returns>
|
||||
// public async Task<LayerGroup> Remove()
|
||||
// {
|
||||
// GuardAgainstNullBinding("Cannot remove layergroup from map. No JavaScript binding has been set up.");
|
||||
// var module = await JSBinder.GetLeafletMapModule();
|
||||
// await module.InvokeVoidAsync("LeafletMap.layerGroup.remove", this.JSObjectReference);
|
||||
// return this;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//}
|
||||
@@ -1,14 +0,0 @@
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// The options used when creating a <see cref="Layer"/>.
|
||||
/// </summary>
|
||||
public class LayerOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The string shown in the attribution control.
|
||||
/// May be required to show, e.g., tile provider's copyright message.
|
||||
/// </summary>
|
||||
public string Attribution { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
@using Microsoft.JSInterop
|
||||
|
||||
<div class="leafletMap" id="@Map.ElementId"></div>
|
||||
|
||||
@code {
|
||||
|
||||
/// <summary>
|
||||
/// The JavaScript runtime instance used to create the <see cref="Map"/>.
|
||||
/// </summary>
|
||||
[Inject] public IJSRuntime JSRuntime { get; set; }
|
||||
/// <summary>
|
||||
/// The Leaflet <see cref="Map"/> to be rendered by the component.
|
||||
/// </summary>
|
||||
[Parameter] public Map Map { get; set; }
|
||||
/// <summary>
|
||||
/// The <see cref="TileLayer"/> to be added when the <see cref="Map"/> is rendered.
|
||||
/// </summary>
|
||||
[Parameter] public TileLayer TileLayer { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Action AfterRender { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected async override Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await Map.BindJsObjectReference(new LeafletMapJSBinder(JSRuntime));
|
||||
await TileLayer.AddTo(Map);
|
||||
AfterRender?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A leaflet Map object, used to create a Map on a page.
|
||||
/// <see href="https://leafletjs.com/reference-1.7.1.html#map-methods-for-getting-map-state"/>
|
||||
/// and <see href="https://leafletjs.com/reference-1.7.1.html#map-methods-for-modifying-map-state"/>.
|
||||
/// </summary>
|
||||
public class Map : InteropObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID of the HTML element the map will be rendered in.
|
||||
/// </summary>
|
||||
public string ElementId { get; }
|
||||
/// <summary>
|
||||
/// The <see cref="MapOptions"/> used to create the Map.
|
||||
/// </summary>
|
||||
public MapOptions Options { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Map.
|
||||
/// </summary>
|
||||
/// <param name="elementId">The ID of the HTML element the map will be rendered in.</param>
|
||||
/// <param name="options">The <see cref="MapOptions"/> used to create the Map.</param>
|
||||
public Map(string elementId, MapOptions options)
|
||||
{
|
||||
ElementId = elementId;
|
||||
Options = options;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<IJSObjectReference> CreateJsObjectRef()
|
||||
{
|
||||
return await JSBinder.JSRuntime.InvokeAsync<IJSObjectReference>("L.map", ElementId, Options);
|
||||
}
|
||||
|
||||
#region Get map state
|
||||
/// <summary>
|
||||
/// Gets the point at the centre of the map view.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="LatLng"/> representing the geographical centre of the map.</returns>
|
||||
public async Task<LatLng> GetCenter()
|
||||
{
|
||||
return await JSObjectReference.InvokeAsync<LatLng>("getCenter");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the geographical bounds of the map view.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="LatLngBounds"/> object representing the geographical bounds of the map.</returns>
|
||||
public async Task<LatLngBounds> GetBounds()
|
||||
{
|
||||
return await JSObjectReference.InvokeAsync<LatLngBounds>("getBounds");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the zoom level of the map view.
|
||||
/// </summary>
|
||||
/// <returns>The zoom level.</returns>
|
||||
public async Task<int> GetZoom()
|
||||
{
|
||||
return await JSObjectReference.InvokeAsync<int>("getZoom");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum zoom level of the map view.
|
||||
/// </summary>
|
||||
/// <returns>The minimum zoom level.</returns>
|
||||
public async Task<int> GetMinZoom()
|
||||
{
|
||||
return await JSObjectReference.InvokeAsync<int>("getMinZoom");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum zoom level of the map view.
|
||||
/// </summary>
|
||||
/// <returns>The maximum zoom level.</returns>
|
||||
public async Task<int> GetMaxZoom()
|
||||
{
|
||||
return await JSObjectReference.InvokeAsync<int>("getMaxZoom");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum zoom level on which the bounds fit the map view.
|
||||
/// </summary>
|
||||
/// <param name="bounds">The <see cref="LatLngBounds"/> to fit to the map.</param>
|
||||
/// <param name="inside">A flag indicating the fit direction. If true, method returns minimum zoom level
|
||||
/// on which the map fits into the bounds.</param>
|
||||
/// <param name="padding">The padding in pixels.</param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> GetBoundsZoom(LatLngBounds bounds, bool inside = false, Point? padding = null)
|
||||
{
|
||||
if (bounds.JSBinder is null)
|
||||
{
|
||||
await bounds.BindJsObjectReference(this.JSBinder);
|
||||
}
|
||||
bounds.GuardAgainstNullBinding("Cannot get bounds zoom. No JavaScript binding has been set up for the bounds parameter.");
|
||||
if (padding is not null)
|
||||
{
|
||||
if (padding.JSBinder is null)
|
||||
{
|
||||
await padding.BindJsObjectReference(this.JSBinder);
|
||||
}
|
||||
padding.GuardAgainstNullBinding("Cannot get bounds zoom. No JavaScript binding has been set up for the padding parameter.");
|
||||
}
|
||||
return await JSObjectReference.InvokeAsync<int>("getBoundsZoom", bounds.JSObjectReference, inside, padding?.JSObjectReference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the map container in pixels.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Point"/> representing the size of the map container in pixels.</returns>
|
||||
public async Task<Point> GetSize()
|
||||
{
|
||||
return await JSObjectReference.InvokeAsync<Point>("getSize");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bounds of the map view in projected pixel coordinates.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Bounds"/> representing the size of the map container in pixels.</returns>
|
||||
public async Task<Bounds> GetPixelBounds()
|
||||
{
|
||||
return await JSObjectReference.InvokeAsync<Bounds>("getPixelBounds");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the projected pixel coordinates of the top left point of the map layer.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Point"/> representing top left point of the map in pixels.</returns>
|
||||
public async Task<Point> GetPixelOrigin()
|
||||
{
|
||||
return await JSObjectReference.InvokeAsync<Point>("getPixelOrigin");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the world's bounds in pixel coordinates.
|
||||
/// </summary>
|
||||
/// <param name="zoom">The zoom level used to calculate the bounds. Current map zoom level is used if null or omitted.</param>
|
||||
/// <returns>A <see cref="Bounds"/> representing the size of the map container in pixels.</returns>
|
||||
public async Task<Bounds> GetPixelWorldBounds(int? zoom = null)
|
||||
{
|
||||
return await JSObjectReference.InvokeAsync<Bounds>("getPixelWorldBounds", zoom);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Set map state
|
||||
/// <summary>
|
||||
/// Sets the view of the map with the given centre and zoom.
|
||||
/// </summary>
|
||||
/// <param name="center">A <see cref="LatLng"/> representing the geogrpahical centre of the map.</param>
|
||||
/// <param name="zoom">The zoom level of the map.</param>
|
||||
/// <returns>The Map.</returns>
|
||||
public async Task<Map> SetView(LatLng center, int zoom)
|
||||
{
|
||||
if (center.JSBinder is null)
|
||||
{
|
||||
await center.BindJsObjectReference(this.JSBinder);
|
||||
}
|
||||
center.GuardAgainstNullBinding("Cannot set map view. No JavaScript binding has been set up for the center argument.");
|
||||
var module = await JSBinder.GetLeafletMapModule();
|
||||
await module.InvokeVoidAsync("LeafletMap.Map.setView", this.JSObjectReference, center.JSObjectReference, zoom);
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// The options used when creating a <see cref="Map"/>.
|
||||
/// </summary>
|
||||
public class MapOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The initial centre point of the <see cref="Map"/>.
|
||||
/// </summary>
|
||||
public LatLng Center { get; set; }
|
||||
/// <summary>
|
||||
/// The initial zoom level of the <see cref="Map"/>.
|
||||
/// </summary>
|
||||
public int Zoom { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A clickable, draggable icon that can be added to a <see cref="Map"/>
|
||||
/// <see href="https://leafletjs.com/reference-1.7.1.html#marker"/>
|
||||
/// </summary>
|
||||
public class Marker : InteractiveLayer
|
||||
{
|
||||
/// <summary>
|
||||
/// The initial position of the marker.
|
||||
/// </summary>
|
||||
[JsonIgnore] public LatLng LatLng { get; }
|
||||
/// <summary>
|
||||
/// The <see cref="MarkerOptions"/> used to create the marker.
|
||||
/// </summary>
|
||||
[JsonIgnore] public MarkerOptions Options { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a marker
|
||||
/// </summary>
|
||||
/// <param name="latlng">The initial position of the marker.</param>
|
||||
/// <param name="options">The <see cref="MarkerOptions"/> used to create the marker.</param>
|
||||
public Marker(LatLng latlng, MarkerOptions options)
|
||||
{
|
||||
LatLng = latlng;
|
||||
Options = options;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<IJSObjectReference> CreateJsObjectRef()
|
||||
{
|
||||
return await JSBinder.JSRuntime.InvokeAsync<IJSObjectReference>("L.marker", LatLng, Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// The options used when creating a <see cref="Marker"/>.
|
||||
/// </summary>
|
||||
public class MarkerOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the marker can be tabbed to with a keyboard and clicked by pressing enter.
|
||||
/// </summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public bool? Keyboard { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Text for the browser tooltip that appear on marker hover (no tooltip by default).
|
||||
/// </summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Text for the alt attribute of the icon image (useful for accessibility).
|
||||
/// </summary>
|
||||
public string Alt { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// By default, marker images zIndex is set automatically based on its latitude. Use this option if you want to
|
||||
/// put the marker on top of all others (or below), specifying a high value like 1000 (or high negative value, respectively)
|
||||
/// </summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public int? ZIndexOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The opacity of the marker.
|
||||
/// </summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public double? Opacity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If true, the marker will get on top of others when you hover the mouse over it.
|
||||
/// </summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public bool? RiseOnHover { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// The z-index offset used for the riseOnHover feature.
|
||||
/// </summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public int? RiseOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Map pane where the markers icon will be added.
|
||||
/// </summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public string Pane { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Map pane where the markers shadow will be added.
|
||||
/// </summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public string ShadowPane { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When true, a mouse event on this marker will trigger the same event on the map
|
||||
/// </summary>
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public bool? BubblingMouseEvents { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A vector overlay <see cref="Layer"/>.
|
||||
/// <see href="https://leafletjs.com/reference-1.7.1.html#path"/>
|
||||
/// </summary>
|
||||
public abstract class Path : InteractiveLayer
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A point with x and y coordinates in pixels.
|
||||
/// </summary>
|
||||
public class Point : InteropObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The x coordinate in pixels.
|
||||
/// </summary>
|
||||
public double X { get; set; }
|
||||
/// <summary>
|
||||
/// The y corrdinate in pixels.
|
||||
/// </summary>
|
||||
public double Y { get; set; }
|
||||
/// <summary>
|
||||
/// Flag indicating whether coordinate values should be rounded.
|
||||
/// </summary>
|
||||
public bool Round { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a point
|
||||
/// </summary>
|
||||
/// <param name="x">The x coordinate in pixels.</param>
|
||||
/// <param name="y">The y corrdinate in pixels.</param>
|
||||
/// <param name="round">Flag indicating whether coordinate values should be rounded.</param>
|
||||
public Point(double x, double y, bool round = false)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Round = round;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<IJSObjectReference> CreateJsObjectRef()
|
||||
{
|
||||
return await JSBinder.JSRuntime.InvokeAsync<IJSObjectReference>("L.point", X, Y, Round);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({X}, {Y})";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A vector line overlay <see cref="Layer"/>.
|
||||
/// <see href="https://leafletjs.com/reference-1.7.1.html#polyline"/>
|
||||
/// </summary>
|
||||
public class Polyline : Path
|
||||
{
|
||||
/// <summary>
|
||||
/// An array of points defining the shape.
|
||||
/// </summary>
|
||||
[JsonIgnore] public IEnumerable<LatLng> LatLngs { get; }
|
||||
/// <summary>
|
||||
/// The <see cref="PolylineOptions"/> used to define the Polyline.
|
||||
/// </summary>
|
||||
[JsonIgnore] public PolylineOptions Options { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Polyline.
|
||||
/// </summary>
|
||||
/// <param name="latLngs">An array of points defining the shape.</param>
|
||||
/// <param name="options">The <see cref="PolylineOptions"/> used to define the polyline.</param>
|
||||
public Polyline(IEnumerable<LatLng> latLngs, PolylineOptions options)
|
||||
{
|
||||
LatLngs = latLngs;
|
||||
Options = options;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<IJSObjectReference> CreateJsObjectRef()
|
||||
{
|
||||
return await JSBinder.JSRuntime.InvokeAsync<IJSObjectReference>("L.polyline", LatLngs.ToArray(), Options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a point to the Polyline
|
||||
/// </summary>
|
||||
/// <param name="latLng">The point to add to the Polyline.</param>
|
||||
/// <returns>The Polyline.</returns>
|
||||
public async Task<Polyline> AddLatLng(LatLng latLng)
|
||||
{
|
||||
GuardAgainstNullBinding("Cannot remove layer from map. No JavaScript binding has been set up.");
|
||||
var module = await JSBinder.GetLeafletMapModule();
|
||||
await module.InvokeVoidAsync("LeafletMap.Polyline.addLatLng", this.JSObjectReference, latLng);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// The options used when creating a <see cref="Polyline"/>.
|
||||
/// </summary>
|
||||
public class PolylineOptions : LayerOptions
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// A raster <see cref="Layer"/> used to display tiled images.
|
||||
/// <see href="https://leafletjs.com/reference-1.7.1.html#tilelayer"/>
|
||||
/// </summary>
|
||||
public class TileLayer : Layer
|
||||
{
|
||||
/// <summary>
|
||||
/// A URL template string with formatting options for subdomain, zoom level, coordinates, and resolution.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// http://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png
|
||||
/// </code>
|
||||
/// </example>
|
||||
[JsonIgnore] public string UrlTemplate { get; }
|
||||
/// <summary>
|
||||
/// The <see cref="TileLayerOptions"/> used to create the TileLayer.
|
||||
/// </summary>
|
||||
[JsonIgnore] public TileLayerOptions Options { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a TileLayer
|
||||
/// </summary>
|
||||
/// <param name="urlTemplate">A URL template string with formatting options for subdomain, zoom level, coordinates, and resolution.</param>
|
||||
/// <param name="options">The <see cref="TileLayerOptions"/> used to create the TileLayer.</param>
|
||||
public TileLayer(string urlTemplate, TileLayerOptions options)
|
||||
{
|
||||
UrlTemplate = urlTemplate;
|
||||
Options = options;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<IJSObjectReference> CreateJsObjectRef()
|
||||
{
|
||||
return await JSBinder.JSRuntime.InvokeAsync<IJSObjectReference>("L.tileLayer", UrlTemplate, Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Aperio_Control_Centre.LeafletBlazor.LeafletMap
|
||||
{
|
||||
/// <summary>
|
||||
/// The options used to create a <see cref="TileLayer"/>.
|
||||
/// </summary>
|
||||
public class TileLayerOptions : LayerOptions
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Aperio_Control_Centre.LeafletBlazor
|
||||
{
|
||||
internal class LeafletMapJSBinder : IAsyncDisposable
|
||||
{
|
||||
internal IJSRuntime JSRuntime;
|
||||
private Task<IJSObjectReference> _leafletMapModule;
|
||||
|
||||
public LeafletMapJSBinder(IJSRuntime jsRuntime)
|
||||
{
|
||||
JSRuntime = jsRuntime;
|
||||
}
|
||||
|
||||
internal async Task<IJSObjectReference> GetLeafletMapModule()
|
||||
{
|
||||
return await (_leafletMapModule ??= JSRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Aperio_Control_Centre.LeafletBlazor/js/leaflet-map.js").AsTask());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (_leafletMapModule != null)
|
||||
{
|
||||
var mapModule = await _leafletMapModule;
|
||||
await mapModule.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
https://github.com/darnton/LeafletBlazor
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"defaultProvider": "cdnjs",
|
||||
"libraries": [
|
||||
{
|
||||
"library": "leaflet@1.9.3",
|
||||
"destination": "wwwroot/leaflet/",
|
||||
"files": [
|
||||
"leaflet.js",
|
||||
"leaflet.css",
|
||||
"leaflet.js.map",
|
||||
"leaflet.min.css",
|
||||
"leaflet.min.js",
|
||||
"images/layers-2x.png",
|
||||
"images/layers.png",
|
||||
"images/marker-icon-2x.png",
|
||||
"images/marker-icon.png",
|
||||
"images/marker-shadow.png"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
export let LeafletMap = {
|
||||
|
||||
Map: {
|
||||
|
||||
setView: function (map, center, zoom) {
|
||||
map.setView(center, zoom);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
Layer: {
|
||||
|
||||
addTo: function (layer, map) {
|
||||
layer.addTo(map);
|
||||
},
|
||||
|
||||
remove: function (layer) {
|
||||
layer.remove();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
Polyline: {
|
||||
|
||||
addLatLng: function (polyline, latlng, latlngs) {
|
||||
polyline.addLatLng(latlng, latlngs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#testMap {
|
||||
height: 750px;
|
||||
width: 100%;
|
||||
}
|
||||
@@ -44,7 +44,6 @@
|
||||
<ProjectReference Include="..\Aperio_Control_Centre.Aadp\Aperio_Control_Centre.Aadp.csproj" />
|
||||
<ProjectReference Include="..\Aperio_Control_Centre.ACSDatabase\Aperio_Control_Centre.ACSDatabase.csproj" />
|
||||
<ProjectReference Include="..\Aperio_Control_Centre.Export\Aperio_Control_Centre.Export.csproj" />
|
||||
<ProjectReference Include="..\Aperio_Control_Centre.LeafletBlazor\Aperio_Control_Centre.LeafletBlazor.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user