@inject IJSRuntime JSRuntime
@inject NavigationManager Nav
@code {
[Parameter]
public EventCallback ControlStateClick { get; set; }
[Parameter]
public EventCallback<(ControlState, bool)> EditorExtensionChanged { get; set; }
[CascadingParameter]
public bool MapIsActive { get; set; }
[Parameter]
public bool ShowGrid { get; set; }
[Parameter]
public bool ShowName { get; set; }
[Parameter]
public bool ShowMapSlam { get; set; }
[Parameter]
public bool NodesUndoable { get; set; }
[Parameter]
public bool MultiSelectedEdge { get; set; }
[Parameter]
public bool ZoneSelected { get; set; }
private double EdgeWidth = 0.15;
private double EdgeDirectionWidth = 0.3;
private double NodeRadius = 0.1;
private double OriginVectorWidth = 0.35;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
var width = await JSRuntime.InvokeAsync("getCssVariable", "--edge-stroke-width");
if (!string.IsNullOrEmpty(width))
{
if (double.TryParse(width.Replace("px", ""), out double edgewidth))
{
EdgeWidth = edgewidth;
}
}
else await JSRuntime.InvokeVoidAsync("setCssVariable", "--edge-stroke-width", $"{EdgeWidth}px");
var directionwidth = await JSRuntime.InvokeAsync("getCssVariable", "--edge-direction-stroke-width");
if (!string.IsNullOrEmpty(directionwidth))
{
if (double.TryParse(directionwidth.Replace("px", ""), out double edgedirectionwidth))
{
EdgeDirectionWidth = edgedirectionwidth;
}
}
else await JSRuntime.InvokeVoidAsync("setCssVariable", "--edge-direction-stroke-width", $"{EdgeDirectionWidth}px");
var radius = await JSRuntime.InvokeAsync("getCssVariable", "--node-r");
if (!string.IsNullOrEmpty(radius))
{
if (double.TryParse(radius.Replace("px", ""), out double noderadius))
{
NodeRadius = noderadius;
}
}
else await JSRuntime.InvokeVoidAsync("setCssVariable", "--node-r", $"{NodeRadius}px");
var originwidth = await JSRuntime.InvokeAsync("getCssVariable", "--origin-vector-stroke-width");
if (!string.IsNullOrEmpty(originwidth))
{
if (double.TryParse(originwidth.Replace("px", ""), out double originVectorWidth))
{
OriginVectorWidth = originVectorWidth;
}
}
else await JSRuntime.InvokeVoidAsync("setCssVariable", "--origin-vector-stroke-width", $"{OriginVectorWidth}px");
StateHasChanged();
}
private async Task ShowNameChanged() => await EditorExtensionChanged.InvokeAsync((ControlState.ShowName, ShowName));
private async Task ShowGridChanged() => await EditorExtensionChanged.InvokeAsync((ControlState.ShowGrid, ShowGrid));
private async Task ShowSlamMapChanged() => await EditorExtensionChanged.InvokeAsync((ControlState.ShowMapSlam, ShowMapSlam));
private async Task EdgeWidthChanged(double value)
{
EdgeWidth = value;
var width = $"{EdgeWidth}px";
await JSRuntime.InvokeVoidAsync("setCssVariable", "--edge-stroke-width", width);
}
private async Task EdgeDirectionWidthChanged(double value)
{
EdgeDirectionWidth = value;
var width = $"{EdgeDirectionWidth}px";
await JSRuntime.InvokeVoidAsync("setCssVariable", "--edge-direction-stroke-width", width);
}
private async Task NodeRadiusChanged(double value)
{
NodeRadius = value;
var width = $"{NodeRadius}px";
await JSRuntime.InvokeVoidAsync("setCssVariable", "--node-r", width);
}
private async Task OriginVectorWidthChanged(double value)
{
OriginVectorWidth = value;
var width = $"{OriginVectorWidth}px";
await JSRuntime.InvokeVoidAsync("setCssVariable", "--origin-vector-stroke-width", width);
}
}