From c5a6d550ae98a4b67730bf70ce3f905f2b878f10 Mon Sep 17 00:00:00 2001 From: Valentas Date: Fri, 14 Jun 2024 07:40:28 +0300 Subject: [PATCH] Minor formating changes in client side demo --- ClientSideDemo/App.razor | 4 +- ClientSideDemo/Pages/Index.razor | 3 +- ClientSideDemo/Pages/MapEvents.razor | 1 - ClientSideDemo/Pages/MapInfoWindow.razor | 26 +++---- ClientSideDemo/Pages/MapPolyline.razor | 96 ++++++++++++------------ ClientSideDemo/Pages/MapRoutes.razor | 22 +++--- ClientSideDemo/Pages/Maps.razor | 44 +++++------ ClientSideDemo/Shared/NavMenu.razor | 10 +-- ClientSideDemo/Shared/SurveyPrompt.razor | 15 ---- ClientSideDemo/Startup.cs | 5 -- 10 files changed, 102 insertions(+), 124 deletions(-) delete mode 100644 ClientSideDemo/Shared/SurveyPrompt.razor diff --git a/ClientSideDemo/App.razor b/ClientSideDemo/App.razor index 77bc96ec..534db983 100644 --- a/ClientSideDemo/App.razor +++ b/ClientSideDemo/App.razor @@ -1,6 +1,4 @@ -@using ClientSideDemo -@using ClientSideDemo.Shared - + diff --git a/ClientSideDemo/Pages/Index.razor b/ClientSideDemo/Pages/Index.razor index 82ce9c56..3b5483eb 100644 --- a/ClientSideDemo/Pages/Index.razor +++ b/ClientSideDemo/Pages/Index.razor @@ -2,4 +2,5 @@

BlazorGoogleMaps!

-Blazor interop for GoogleMap library \ No newline at end of file +Blazor interop for GoogleMap library +More demo at server side sample \ No newline at end of file diff --git a/ClientSideDemo/Pages/MapEvents.razor b/ClientSideDemo/Pages/MapEvents.razor index 28fc26ef..83d4b04d 100644 --- a/ClientSideDemo/Pages/MapEvents.razor +++ b/ClientSideDemo/Pages/MapEvents.razor @@ -1,7 +1,6 @@ @page "/mapEvents" @using GoogleMapsComponents @using GoogleMapsComponents.Maps -@using ClientSideDemo.Shared

Map Events

diff --git a/ClientSideDemo/Pages/MapInfoWindow.razor b/ClientSideDemo/Pages/MapInfoWindow.razor index 4bba706b..e0725555 100644 --- a/ClientSideDemo/Pages/MapInfoWindow.razor +++ b/ClientSideDemo/Pages/MapInfoWindow.razor @@ -4,20 +4,20 @@

Google Map Info Window

- + @functions { - private GoogleMap map1 = default!; + private GoogleMap _map1 = default!; - private MapOptions mapOptions = default!; + private MapOptions _mapOptions = default!; //private List markers = new List(); - private int markerCount; + private int _markerCount; protected override void OnInitialized() { - mapOptions = new MapOptions() + _mapOptions = new MapOptions() { Zoom = 13, Center = new LatLngLiteral() @@ -31,16 +31,16 @@ private async Task AddMarker() { - var position = await map1.InteropObject.GetCenter(); + var position = await _map1.InteropObject.GetCenter(); - var marker = await Marker.CreateAsync(map1.JsRuntime, new MarkerOptions() + var marker = await Marker.CreateAsync(_map1.JsRuntime, new MarkerOptions() { Position = position, - Map = map1.InteropObject, - Label = $"Test {markerCount}" + Map = _map1.InteropObject, + Label = $"Test {_markerCount}" }); - var infoWindow = await InfoWindow.CreateAsync(map1.JsRuntime, new InfoWindowOptions() + var infoWindow = await InfoWindow.CreateAsync(_map1.JsRuntime, new InfoWindowOptions() { Position = new LatLngLiteral() { @@ -50,15 +50,15 @@ //Content = "Test" }); - var infoWindowContent = $"Test {markerCount}"; + var infoWindowContent = $"Test {_markerCount}"; await marker.AddListener("click", async () => { await infoWindow.SetContent(infoWindowContent); await infoWindow.SetPosition(position); - await infoWindow.Open(map1.InteropObject); + await infoWindow.Open(_map1.InteropObject); }); - markerCount++; + _markerCount++; } } \ No newline at end of file diff --git a/ClientSideDemo/Pages/MapPolyline.razor b/ClientSideDemo/Pages/MapPolyline.razor index 1a79fe7e..0144814b 100644 --- a/ClientSideDemo/Pages/MapPolyline.razor +++ b/ClientSideDemo/Pages/MapPolyline.razor @@ -4,7 +4,7 @@

Polylines

- +
@@ -16,24 +16,24 @@ @functions { - private GoogleMap map1 = default!; + private GoogleMap _map1 = default!; - private MapOptions mapOptions = default!; + private MapOptions _mapOptions = default!; - private List path = new List(); + private List _path = new List(); - private List polylines = new List(); - private Polyline? polyline; + private List _polylines = new List(); + private Polyline? _polyline; - private List polygons = new List(); - private Polygon? polygon; + private List _polygons = new List(); + private Polygon? _polygon; - private Rectangle? rectangle; - private Circle? circle; + private Rectangle? _rectangle; + private Circle? _circle; protected override void OnInitialized() { - mapOptions = new MapOptions() + _mapOptions = new MapOptions() { Zoom = 13, Center = new LatLngLiteral() @@ -47,119 +47,119 @@ private async Task OnAfterMapInit() { - await map1.InteropObject.AddListener("click", async (e) => await OnClick(e)); + await _map1.InteropObject.AddListener("click", async (e) => await OnClick(e)); } private async Task StartDrawingPolyline() { - polyline = await Polyline.CreateAsync(map1.JsRuntime, new PolylineOptions() + _polyline = await Polyline.CreateAsync(_map1.JsRuntime, new PolylineOptions() { Draggable = true, Editable = true, - Map = map1.InteropObject + Map = _map1.InteropObject }); - path.Clear(); + _path.Clear(); } private void EndDrawingPolyline() { - if (polyline is { }) { - polylines.Add(polyline); + if (_polyline is { }) { + _polylines.Add(_polyline); } - polyline = null; - path.Clear(); + _polyline = null; + _path.Clear(); } private async Task StartDrawingPolygon() { - polygon = await Polygon.CreateAsync(map1.JsRuntime, new PolygonOptions() + _polygon = await Polygon.CreateAsync(_map1.JsRuntime, new PolygonOptions() { Draggable = true, Editable = true, - Map = map1.InteropObject + Map = _map1.InteropObject }); - path.Clear(); + _path.Clear(); } private void EndDrawingPolygon() { - if (polygon is { }) { - polygons.Add(polygon); + if (_polygon is { }) { + _polygons.Add(_polygon); } - polygon = null; - path.Clear(); + _polygon = null; + _path.Clear(); } private async Task DrawingRectangle() { - rectangle = await Rectangle.CreateAsync(map1.JsRuntime, new RectangleOptions() + _rectangle = await Rectangle.CreateAsync(_map1.JsRuntime, new RectangleOptions() { Draggable = true, Editable = true, - Map = map1.InteropObject + Map = _map1.InteropObject }); - path.Clear(); + _path.Clear(); } private async Task DrawingCircle() { - circle = await Circle.CreateAsync(map1.JsRuntime, new CircleOptions() + _circle = await Circle.CreateAsync(_map1.JsRuntime, new CircleOptions() { Draggable = true, Editable = true, - Map = map1.InteropObject, + Map = _map1.InteropObject, Radius = 1000 }); - path.Clear(); + _path.Clear(); } private async Task OnClick(MouseEvent e) { //Debug.WriteLine($"Onclick : {mouseEvent.LatLng}"); - path.Add(e.LatLng); + _path.Add(e.LatLng); - if (polyline != null) + if (_polyline != null) { //Debug.WriteLine($"Path length : {path.Count()}"); - await polyline.SetPath(path); + await _polyline.SetPath(_path); } - else if (polygon != null) + else if (_polygon != null) { - await polygon.SetPath(path); + await _polygon.SetPath(_path); } - else if (rectangle != null) + else if (_rectangle != null) { - if (path.Count < 2) + if (_path.Count < 2) { return; } var bounds = new LatLngBoundsLiteral() { - East = path[1].Lng, - North = path[0].Lat, - South = path[1].Lat, - West = path[0].Lng + East = _path[1].Lng, + North = _path[0].Lat, + South = _path[1].Lat, + West = _path[0].Lng }; - await rectangle.SetBounds(bounds); + await _rectangle.SetBounds(bounds); //path.Clear(); - rectangle = null; + _rectangle = null; } - else if (circle != null) + else if (_circle != null) { - await circle.SetCenter(path.First()); - circle = null; + await _circle.SetCenter(_path.First()); + _circle = null; } } diff --git a/ClientSideDemo/Pages/MapRoutes.razor b/ClientSideDemo/Pages/MapRoutes.razor index 6544ff5e..281bbe33 100644 --- a/ClientSideDemo/Pages/MapRoutes.razor +++ b/ClientSideDemo/Pages/MapRoutes.razor @@ -4,9 +4,9 @@

Google Map

- + - +

Duration: @_durationTotalString
@@ -14,15 +14,15 @@

@code { - private GoogleMap? map1; - private MapOptions mapOptions = default!; - private DirectionsRenderer dirRend = default!; + private GoogleMap? _map1; + private MapOptions _mapOptions = default!; + private DirectionsRenderer _dirRend = default!; private string? _durationTotalString; private string? _distanceTotalString; protected override void OnInitialized() { - mapOptions = new MapOptions() + _mapOptions = new MapOptions() { Zoom = 13, Center = new LatLngLiteral() @@ -36,7 +36,7 @@ private async Task RemoveRoute() { - await dirRend.SetMap(null); + await _dirRend.SetMap(null); _durationTotalString = null; _distanceTotalString = null; @@ -45,9 +45,9 @@ private async Task OnAfterInitAsync() { //Create instance of DirectionRenderer - dirRend = await DirectionsRenderer.CreateAsync(map1!.JsRuntime, new DirectionsRendererOptions() + _dirRend = await DirectionsRenderer.CreateAsync(_map1!.JsRuntime, new DirectionsRendererOptions() { - Map = map1.InteropObject + Map = _map1.InteropObject }); } @@ -55,7 +55,7 @@ { _durationTotalString = null; _distanceTotalString = null; - if (await dirRend.GetMap() is null) await dirRend.SetMap(map1!.InteropObject); + if (await _dirRend.GetMap() is null) await _dirRend.SetMap(_map1!.InteropObject); //Adding a waypoint var waypoints = new List(); @@ -69,7 +69,7 @@ dr.TravelMode = TravelMode.Driving; //Calculate Route - var directionsResult = await dirRend.Route(dr); + var directionsResult = await _dirRend.Route(dr); if (directionsResult != null) { foreach (var route in directionsResult.Routes.SelectMany(x => x.Legs)) diff --git a/ClientSideDemo/Pages/Maps.razor b/ClientSideDemo/Pages/Maps.razor index a747ef17..dce16aa6 100644 --- a/ClientSideDemo/Pages/Maps.razor +++ b/ClientSideDemo/Pages/Maps.razor @@ -6,7 +6,7 @@

Maps

-
+
@@ -16,16 +16,16 @@
-
+
@functions { - private Map map1 = default!, map2 = default!; + private Map _map1 = default!, _map2 = default!; - private ElementReference map1ElementRef, map2ElementRef; + private ElementReference _map1ElementRef, _map2ElementRef; protected override async Task OnAfterRenderAsync(bool firstRender) { - if (map1 == null) + if (_map1 == null) { var mapOptions1 = new MapOptions() { @@ -38,12 +38,12 @@ MapTypeId = MapTypeId.Roadmap }; - map1 = await Map.CreateAsync(JsRuntime, map1ElementRef, mapOptions1); + _map1 = await Map.CreateAsync(JsRuntime, _map1ElementRef, mapOptions1); //Debug.WriteLine("Init finished"); } - if (map2 == null) + if (_map2 == null) { var mapOptions2 = new MapOptions() { @@ -58,65 +58,65 @@ Tilt = 45 }; - map2 = await Map.CreateAsync(JsRuntime, map2ElementRef, mapOptions2); + _map2 = await Map.CreateAsync(JsRuntime, _map2ElementRef, mapOptions2); } } private async Task SyncBounds() { - var bounds = await map1.GetBounds(); - await map2.FitBounds(bounds); + var bounds = await _map1.GetBounds(); + await _map2.FitBounds(bounds); } private async Task SyncMapCenter() { - var latLng = await map1.GetCenter(); - await map2.SetCenter(latLng); + var latLng = await _map1.GetCenter(); + await _map2.SetCenter(latLng); } private async Task SetMapHeading() { - await map2.SetHeading(await map2.GetHeading() + 90); - var heading = await map2.GetHeading(); + await _map2.SetHeading(await _map2.GetHeading() + 90); + var heading = await _map2.GetHeading(); Console.WriteLine($"Map2 heading is {heading}"); } private async Task ToggleTilt() { - var tilt = await map2.GetTilt(); + var tilt = await _map2.GetTilt(); Console.WriteLine($"Map2 tilt is {tilt}"); if (tilt > 0) { - await map2.SetTilt(0); + await _map2.SetTilt(0); } else { - await map2.SetTilt(45); + await _map2.SetTilt(45); } } private async Task ZoomIn() { - var zoom = await map1.GetZoom(); - await map1.SetZoom(zoom + 1); + var zoom = await _map1.GetZoom(); + await _map1.SetZoom(zoom + 1); } private async Task ToggleMapType() { - var mapTypeId = await map1.GetMapTypeId(); + var mapTypeId = await _map1.GetMapTypeId(); Console.WriteLine($"Map type is {mapTypeId}"); if (mapTypeId != MapTypeId.Satellite) { - await map1.SetMapTypeId(MapTypeId.Satellite); + await _map1.SetMapTypeId(MapTypeId.Satellite); } else { - await map1.SetMapTypeId(MapTypeId.Roadmap); + await _map1.SetMapTypeId(MapTypeId.Roadmap); } } } \ No newline at end of file diff --git a/ClientSideDemo/Shared/NavMenu.razor b/ClientSideDemo/Shared/NavMenu.razor index e190ba60..1c407f92 100644 --- a/ClientSideDemo/Shared/NavMenu.razor +++ b/ClientSideDemo/Shared/NavMenu.razor @@ -19,27 +19,27 @@ diff --git a/ClientSideDemo/Shared/SurveyPrompt.razor b/ClientSideDemo/Shared/SurveyPrompt.razor deleted file mode 100644 index a83db0ba..00000000 --- a/ClientSideDemo/Shared/SurveyPrompt.razor +++ /dev/null @@ -1,15 +0,0 @@ - - -@code { - // Demonstrates how a parent component can supply parameters - [Parameter] public string? Title { get; set; } -} diff --git a/ClientSideDemo/Startup.cs b/ClientSideDemo/Startup.cs index 7337b302..73634535 100644 --- a/ClientSideDemo/Startup.cs +++ b/ClientSideDemo/Startup.cs @@ -5,17 +5,12 @@ namespace ClientSideDemo { public class Startup { - private static async Task Main(string[] args) { - var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("app"); - await builder.Build().RunAsync(); - } - } }