@page "/navigation-maps/editor/{Id:guid}" @attribute [Authorize] @using RobotNet.MapShares.Dtos @using RobotNet.MapShares.Enums @using RobotNet.Shares @using RobotNet.WebApp.Maps.Components.Editor @using RobotNet.WebApp.Maps.Components.Toolbar @inject IHttpClientFactory HttpClientFactory @inject IJSRuntime JSRuntime Map Designer
@OverlayIsStr
@code { [Parameter, EditorRequired] public Guid Id { get; set; } private EditorToolbar EditorToolbarRef = null!; private MapContainer MapContainerRef = null!; private bool ShowGrid = true; private bool ShowName = true; private bool ShowMapSlam = true; private bool MapIsActive; private bool MultiselectedEdge = false; private bool MultiselectedNode = false; private bool ZoneSelected = false; private bool NodesUndoable = false; private EditorState EditorState = EditorState.View; private ZoneType ZoneType = ZoneType.Operating; private bool OverlayIsShow = false; private string OverlayIsStr = "Loading..."; private HttpClient Http = default!; protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); if (!firstRender) return; Http = HttpClientFactory.CreateClient("MapManagerAPI"); await LoadMap(); } private async Task LoadMap() { try { OverlayIsShow = true; StateHasChanged(); var mapDataResult = await Http.GetFromJsonAsync>($"api/MapsData/{Id}"); if (mapDataResult is not null && mapDataResult.Data is not null) { MapIsActive = mapDataResult.Data.Active; await MapContainerRef.LoadMap(mapDataResult.Data); OverlayIsShow = false; } else OverlayIsStr = "Map Not Existed"; StateHasChanged(); } catch { OverlayIsStr = "Map Not Existed"; StateHasChanged(); return; } } private void EditorExtensionChanged((ControlState state, bool value) extension) { switch (extension.state) { case ControlState.ShowName: ShowName = extension.value; break; case ControlState.ShowGrid: ShowGrid = extension.value; break; case ControlState.ShowMapSlam: ShowMapSlam = extension.value; break; } StateHasChanged(); } private async Task ControlStateClick(ControlState state) { switch (state) { case ControlState.Undo: MapContainerRef.UndoEditorBackup(); break; case ControlState.FitScreen: await MapContainerRef.ScaleFitContentAsync(); break; case ControlState.Save: await MapContainerRef.SaveChanged(); break; case ControlState.ZoomIn: await MapContainerRef.ScaleZoom(0.5); break; case ControlState.ZoomOut: await MapContainerRef.ScaleZoom(-0.5); break; case ControlState.Delete: if (EditorState == EditorState.NavigationEdit || EditorState == EditorState.Scaner) await MapContainerRef.DeleteEdge(); else if (EditorState == EditorState.SettingZone) await MapContainerRef.DeleteZone(); break; case ControlState.CheckMap: await MapContainerRef.CheckMap(); break; } } private async Task EditorStateChanged(EditorState state) { if (EditorState != state) { EditorState = state; await MapContainerRef.EditStateChange(); EditorToolbarRef.SetEditorState(state); StateHasChanged(); } } private async Task AlignStateClick(AlignState state) { switch (state) { case AlignState.HorizontalLeft: MapContainerRef.HorizontalLeft(); break; case AlignState.HorizontalRight: MapContainerRef.HorizontalRight(); break; case AlignState.VerticalTop: MapContainerRef.VerticalTop(); break; case AlignState.VerticalBottom: MapContainerRef.VerticalBottom(); break; case AlignState.HorizontalCenter: MapContainerRef.HorizontalCenter(); break; case AlignState.VerticalCenter: MapContainerRef.VerticalCenter(); break; case AlignState.MergeNode: await MapContainerRef.MergeNode(); break; case AlignState.SplitNode: await MapContainerRef.SplitNode(); break; } } private void MapIsChecking(bool state) { if (state) { OverlayIsShow = true; OverlayIsStr = "Map Checking ..."; } else OverlayIsShow = false; StateHasChanged(); } }