Skip to content

Commit

Permalink
Minor formating changes in client side demo
Browse files Browse the repository at this point in the history
  • Loading branch information
valentasm committed Jun 14, 2024
1 parent 2fda669 commit c5a6d55
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 124 deletions.
4 changes: 1 addition & 3 deletions ClientSideDemo/App.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@using ClientSideDemo
@using ClientSideDemo.Shared
<Router AppAssembly="@typeof(Startup).Assembly">
<Router AppAssembly="@typeof(Startup).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
Expand Down
3 changes: 2 additions & 1 deletion ClientSideDemo/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

<h1>BlazorGoogleMaps!</h1>

Blazor interop for GoogleMap library
Blazor interop for GoogleMap library
<small>More demo at server side sample</small>
1 change: 0 additions & 1 deletion ClientSideDemo/Pages/MapEvents.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@page "/mapEvents"
@using GoogleMapsComponents
@using GoogleMapsComponents.Maps
@using ClientSideDemo.Shared

<h1>Map Events</h1>

Expand Down
26 changes: 13 additions & 13 deletions ClientSideDemo/Pages/MapInfoWindow.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

<h1>Google Map Info Window</h1>

<GoogleMap @ref="@map1" Id="map1" Options="@mapOptions"></GoogleMap>
<GoogleMap @ref="@_map1" Id="map1" Options="@_mapOptions"></GoogleMap>
<button @onclick="AddMarker">Add marker</button>

@functions {
private GoogleMap map1 = default!;
private GoogleMap _map1 = default!;

private MapOptions mapOptions = default!;
private MapOptions _mapOptions = default!;

//private List<Marker> markers = new List<Marker>();
private int markerCount;
private int _markerCount;

protected override void OnInitialized()
{
mapOptions = new MapOptions()
_mapOptions = new MapOptions()
{
Zoom = 13,
Center = new LatLngLiteral()
Expand All @@ -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()
{
Expand All @@ -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++;
}
}
96 changes: 48 additions & 48 deletions ClientSideDemo/Pages/MapPolyline.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<h1>Polylines</h1>

<GoogleMap @ref="@map1" Id="map1" Options="@mapOptions" OnAfterInit="async () => await OnAfterMapInit()"></GoogleMap>
<GoogleMap @ref="@_map1" Id="map1" Options="@_mapOptions" OnAfterInit="async () => await OnAfterMapInit()"></GoogleMap>
<button @onclick="StartDrawingPolyline">Start drawing polyline</button>
<button @onclick="EndDrawingPolyline">End drawing polyline</button>
<br />
Expand All @@ -16,24 +16,24 @@
<button @onclick="DrawingCircle">Drawing circle</button>

@functions {
private GoogleMap map1 = default!;
private GoogleMap _map1 = default!;

private MapOptions mapOptions = default!;
private MapOptions _mapOptions = default!;

private List<LatLngLiteral> path = new List<LatLngLiteral>();
private List<LatLngLiteral> _path = new List<LatLngLiteral>();

private List<Polyline> polylines = new List<Polyline>();
private Polyline? polyline;
private List<Polyline> _polylines = new List<Polyline>();
private Polyline? _polyline;

private List<Polygon> polygons = new List<Polygon>();
private Polygon? polygon;
private List<Polygon> _polygons = new List<Polygon>();
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()
Expand All @@ -47,119 +47,119 @@

private async Task OnAfterMapInit()
{
await map1.InteropObject.AddListener<MouseEvent>("click", async (e) => await OnClick(e));
await _map1.InteropObject.AddListener<MouseEvent>("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;
}
}

Expand Down
22 changes: 11 additions & 11 deletions ClientSideDemo/Pages/MapRoutes.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

<h1>Google Map</h1>

<GoogleMap @ref="@map1" Id="map1" Options="@mapOptions" Height="350px" OnAfterInit="@(async () => await OnAfterInitAsync())"></GoogleMap>
<GoogleMap @ref="@_map1" Id="map1" Options="@_mapOptions" Height="350px" OnAfterInit="@(async () => await OnAfterInitAsync())"></GoogleMap>
<button @onclick="@(_ => AddDirections())">Add Direction</button>
<button @onclick="@( _distanceTotalString => RemoveRoute())">Remove route</button>
<button @onclick="@( distanceTotalString => RemoveRoute())">Remove route</button>

<p>
Duration: @_durationTotalString <br />
Distance: @_distanceTotalString <br />
</p>

@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()
Expand All @@ -36,7 +36,7 @@

private async Task RemoveRoute()
{
await dirRend.SetMap(null);
await _dirRend.SetMap(null);

_durationTotalString = null;
_distanceTotalString = null;
Expand All @@ -45,17 +45,17 @@
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
});
}

private async Task AddDirections()
{
_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<DirectionsWaypoint>();
Expand All @@ -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))
Expand Down
Loading

0 comments on commit c5a6d55

Please sign in to comment.