Add project files.

This commit is contained in:
Bernard Darnton
2020-10-12 06:03:49 +13:00
parent 15357aad6b
commit 9576c5aa5b
61 changed files with 1993 additions and 0 deletions
@@ -0,0 +1,6 @@
namespace BlazorDeviceInterop.Components.LeafletMap
{
public abstract class InteractiveLayer : Layer
{
}
}
@@ -0,0 +1,13 @@
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class LatLng
{
public double Lat { get; set; }
public double Lng { get; set; }
public LatLng(double lat, double lng)
{
Lat = lat;
Lng = lng;
}
}
}
@@ -0,0 +1,20 @@
using Microsoft.JSInterop;
using System.Threading.Tasks;
namespace BlazorDeviceInterop.Components.LeafletMap
{
public abstract class Layer : InteropObject
{
public async Task<Layer> AddTo(Map map)
{
await _jsObjRef.JSRuntime.InvokeVoidAsync("LeafletMap.Layer.addTo", this, map);
return this;
}
public async Task<Layer> Remove()
{
await _jsObjRef.JSRuntime.InvokeVoidAsync("LeafletMap.Layer.remove", this);
return this;
}
}
}
@@ -0,0 +1,7 @@
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class LayerOptions
{
public string Attribution { get; set; }
}
}
@@ -0,0 +1,3 @@
@inherits LeafletMapBase
<div class="leafletMap" id="@Map.ElementId"></div>
@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.Threading.Tasks;
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class LeafletMapBase : ComponentBase
{
[Inject] public IJSRuntime JSRuntime { get; set; }
[Parameter] public Map Map { get; set; }
[Parameter] public TileLayer TileLayer { get; set; }
protected async override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await Map.BindToJsRuntime(JSRuntime);
await TileLayer.BindToJsRuntime(JSRuntime);
await TileLayer.AddTo(Map);
}
}
}
}
@@ -0,0 +1,23 @@
using Microsoft.JSInterop;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class Map : InteropObject
{
[JsonIgnore] public string ElementId { get; }
[JsonIgnore] public MapOptions Options { get; }
public Map(string elementId, MapOptions options)
{
ElementId = elementId;
Options = options;
}
protected override async Task<JsRuntimeObjectRef> CreateJsObjectRef(IJSRuntime jsRuntime)
{
return await jsRuntime.InvokeAsync<JsRuntimeObjectRef>("LeafletMap.map", ElementId, Options);
}
}
}
@@ -0,0 +1,8 @@
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class MapOptions
{
public LatLng Center { get; set; }
public int Zoom { get; set; }
}
}
@@ -0,0 +1,22 @@
using Microsoft.JSInterop;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class Marker : InteractiveLayer
{
[JsonIgnore] public LatLng LatLng { get; }
[JsonIgnore] public MarkerOptions Options { get; }
public Marker(LatLng latlng, MarkerOptions options)
{
LatLng = latlng;
Options = options;
}
protected override async Task<JsRuntimeObjectRef> CreateJsObjectRef(IJSRuntime jsRuntime)
{
return await jsRuntime.InvokeAsync<JsRuntimeObjectRef>("LeafletMap.marker", LatLng, Options);
}
}
}
@@ -0,0 +1,6 @@
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class MarkerOptions
{
}
}
@@ -0,0 +1,6 @@
namespace BlazorDeviceInterop.Components.LeafletMap
{
public abstract class Path : InteractiveLayer
{
}
}
@@ -0,0 +1,33 @@
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class Polyline : Path
{
[JsonIgnore] public IEnumerable<LatLng> LatLngs { get; }
[JsonIgnore] public PolylineOptions Options { get; }
public Polyline(IEnumerable<LatLng> latLngs, PolylineOptions options)
{
LatLngs = latLngs;
Options = options;
}
protected override async Task<JsRuntimeObjectRef> CreateJsObjectRef(IJSRuntime jsRuntime)
{
return await jsRuntime.InvokeAsync<JsRuntimeObjectRef>("LeafletMap.polyline", LatLngs.ToArray(), Options);
}
public async Task<Polyline> AddLatLng(LatLng latLng)
{
await _jsObjRef.JSRuntime.InvokeVoidAsync("LeafletMap.Polyline.addLatLng", this, latLng);
return this;
}
}
}
@@ -0,0 +1,6 @@
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class PolylineOptions : LayerOptions
{
}
}
@@ -0,0 +1,23 @@
using Microsoft.JSInterop;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class TileLayer : Layer
{
[JsonIgnore] public string UrlTemplate { get; }
[JsonIgnore] public TileLayerOptions Options { get; }
public TileLayer(string urlTemplate, TileLayerOptions options)
{
UrlTemplate = urlTemplate;
Options = options;
}
protected override async Task<JsRuntimeObjectRef> CreateJsObjectRef(IJSRuntime jsRuntime)
{
return await jsRuntime.InvokeAsync<JsRuntimeObjectRef>("LeafletMap.tileLayer", UrlTemplate, Options);
}
}
}
@@ -0,0 +1,6 @@
namespace BlazorDeviceInterop.Components.LeafletMap
{
public class TileLayerOptions : LayerOptions
{
}
}