Skip to content

Commit

Permalink
Fixed couple warnings for nulabiliyt
Browse files Browse the repository at this point in the history
  • Loading branch information
valentasm committed Apr 3, 2023
1 parent 5774c99 commit 87dd9f6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 44 deletions.
8 changes: 4 additions & 4 deletions GoogleMapsComponents/Maps/DirectionsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DirectionsRequest
/// Settings that apply only to requests where travelMode is DRIVING.
/// This object will have no effect for other travel modes.
/// </summary>
public DrivingOptions DrivingOptions { get; set; }
public DrivingOptions? DrivingOptions { get; set; }

/// <summary>
/// If set to true, the DirectionsService will attempt to re-order the supplied intermediate waypoints to minimize overall cost of the route.
Expand All @@ -62,13 +62,13 @@ public class DirectionsRequest
/// Region code used as a bias for geocoding requests.
/// Optional.
/// </summary>
public string Region { get; set; }
public string? Region { get; set; }

/// <summary>
/// Settings that apply only to requests where travelMode is TRANSIT.
/// This object will have no effect for other travel modes.
/// </summary>
public TransitOptions TransitOptions { get; set; }
public TransitOptions? TransitOptions { get; set; }

/// <summary>
/// Type of routing requested.
Expand All @@ -88,6 +88,6 @@ public class DirectionsRequest
/// See the developer's guide for the maximum number of waypoints allowed.
/// Waypoints are not supported for transit directions. Optional.
/// </summary>
public IEnumerable<DirectionsWaypoint> Waypoints { get; set; }
public IEnumerable<DirectionsWaypoint>? Waypoints { get; set; }
}
}
18 changes: 9 additions & 9 deletions GoogleMapsComponents/Maps/DirectionsStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@ public class DirectionsStep
/// The distance covered by this step.
/// This property may be undefined as the distance may be unknown.
/// </summary>
public Distance Distance { get; set; }
public Distance? Distance { get; set; }

/// <summary>
/// The typical time required to perform this step in seconds and in text form.
/// This property may be undefined as the duration may be unknown.
/// </summary>
public Duration Duration { get; set; }
public Duration? Duration { get; set; }

/// <summary>
/// The ending location of this step.
/// </summary>
public LatLngLiteral EndLocation { get; set; }
public LatLngLiteral? EndLocation { get; set; }

/// <summary>
/// Instructions for this step.
/// </summary>
public string Instructions { get; set; }
public string? Instructions { get; set; }

/// <summary>
/// The starting location of this step.
/// </summary>
public LatLngLiteral StartLocation { get; set; }
public LatLngLiteral? StartLocation { get; set; }

/// <summary>
/// Sub-steps of this step.
/// Specified for non-transit sections of transit routes.
/// </summary>
public IEnumerable<DirectionsStep> Steps { get; set; }
public IEnumerable<DirectionsStep>? Steps { get; set; }

/// <summary>
/// Transit-specific details about this step.
/// This property will be undefined unless the travel mode of this step is TRANSIT.
/// </summary>
public TransitDetails Transit { get; set; }
public TransitDetails? Transit { get; set; }

/// <summary>
/// The mode of travel used in this step.
Expand All @@ -56,12 +56,12 @@ public class DirectionsStep


[JsonPropertyName("lat_lngs")]
public IEnumerable<LatLngLiteral> LatLngs { get; set; }
public IEnumerable<LatLngLiteral>? LatLngs { get; set; }

/// <summary>
/// A sequence of LatLngs describing the course of this step.
/// </summary>
[JsonPropertyName("path")]
public IEnumerable<LatLngLiteral> Path { get; set; }
public IEnumerable<LatLngLiteral>? Path { get; set; }
}
}
38 changes: 21 additions & 17 deletions GoogleMapsComponents/Maps/Extension/CircleList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public class CircleList : ListableEntityListBase<Circle, CircleOptions>
/// <returns>new instance of CircleList class will be returned with its Circles dictionary member populated with the corresponding results</returns>
public static async Task<CircleList> CreateAsync(IJSRuntime jsRuntime, Dictionary<string, CircleOptions> opts)
{
JsObjectRef jsObjectRef = new JsObjectRef(jsRuntime, Guid.NewGuid());
var jsObjectRef = new JsObjectRef(jsRuntime, Guid.NewGuid());

CircleList obj;
Dictionary<string, JsObjectRef> jsObjectRefs = await JsObjectRef.CreateMultipleAsync(
jsRuntime,
"google.maps.Circle",
opts.ToDictionary(e => e.Key, e => (object)e.Value));
Dictionary<string, Circle> objs = jsObjectRefs.ToDictionary(e => e.Key, e => new Circle(e.Value));
obj = new CircleList(jsObjectRef, objs);

var objs = jsObjectRefs.ToDictionary(e => e.Key, e => new Circle(e.Value));
var obj = new CircleList(jsObjectRef, objs);

return obj;
}
Expand All @@ -48,10 +48,14 @@ public static async Task<CircleList> CreateAsync(IJSRuntime jsRuntime, Dictionar
/// </param>
/// <param name="jsRuntime"></param>
/// <param name="opts"></param>
/// <param name="clickCallback"></param>
/// <returns>
/// The managed list. Assign to the variable you used as parameter.
/// </returns>
public static async Task<CircleList> SyncAsync(CircleList list, IJSRuntime jsRuntime, Dictionary<string, CircleOptions> opts, Action<MouseEvent, string, Circle> clickCallback = null)
public static async Task<CircleList> SyncAsync(CircleList? list,
IJSRuntime jsRuntime,
Dictionary<string, CircleOptions> opts,
Action<MouseEvent, string, Circle>? clickCallback = null)
{
if (opts.Count == 0)
{
Expand All @@ -68,7 +72,7 @@ public static async Task<CircleList> SyncAsync(CircleList list, IJSRuntime jsRun
list = await CircleList.CreateAsync(jsRuntime, new Dictionary<string, CircleOptions>());
if (clickCallback != null)
{
list.EntityClicked += (sender, e) =>
list.EntityClicked += (_, e) =>
{
clickCallback(e.MouseEvent, e.Key, e.Entity);
};
Expand Down Expand Up @@ -104,9 +108,9 @@ public async Task AddMultipleAsync(Dictionary<string, CircleOptions> opts)
await base.AddMultipleAsync(opts, "google.maps.Circle");
}

public Task<Dictionary<string, LatLngBoundsLiteral>> GetBounds(List<string> filterKeys = null)
public Task<Dictionary<string, LatLngBoundsLiteral>> GetBounds(List<string>? filterKeys = null)
{
List<string> matchingKeys = ComputeMathingKeys(filterKeys);
var matchingKeys = ComputeMathingKeys(filterKeys);

if (matchingKeys.Any())
{
Expand All @@ -123,9 +127,9 @@ public Task<Dictionary<string, LatLngBoundsLiteral>> GetBounds(List<string> filt
}
}

public Task<Dictionary<string, LatLngLiteral>> GetCenters(List<string> filterKeys = null)
public Task<Dictionary<string, LatLngLiteral>> GetCenters(List<string>? filterKeys = null)
{
List<string> matchingKeys = ComputeMathingKeys(filterKeys);
var matchingKeys = ComputeMathingKeys(filterKeys);

if (matchingKeys.Any())
{
Expand All @@ -142,9 +146,9 @@ public Task<Dictionary<string, LatLngLiteral>> GetCenters(List<string> filterKey
}
}

public Task<Dictionary<string, bool>> GetEditables(List<string> filterKeys = null)
public Task<Dictionary<string, bool>> GetEditables(List<string>? filterKeys = null)
{
List<string> matchingKeys = ComputeMathingKeys(filterKeys);
var matchingKeys = ComputeMathingKeys(filterKeys);

if (matchingKeys.Any())
{
Expand All @@ -161,9 +165,9 @@ public Task<Dictionary<string, bool>> GetEditables(List<string> filterKeys = nul
}
}

public Task<Dictionary<string, double>> GetRadiuses(List<string> filterKeys = null)
public Task<Dictionary<string, double>> GetRadiuses(List<string>? filterKeys = null)
{
List<string> matchingKeys = ComputeMathingKeys(filterKeys);
var matchingKeys = ComputeMathingKeys(filterKeys);

if (matchingKeys.Any())
{
Expand All @@ -182,23 +186,23 @@ public Task<Dictionary<string, double>> GetRadiuses(List<string> filterKeys = nu

public Task SetCenters(Dictionary<string, LatLngLiteral> centers)
{
Dictionary<Guid, object> dictArgs = centers.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value);
var dictArgs = centers.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value);
return _jsObjectRef.InvokeMultipleAsync(
"setCenter",
dictArgs);
}

public Task SetEditables(Dictionary<string, bool> editables)
{
Dictionary<Guid, object> dictArgs = editables.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value);
var dictArgs = editables.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value);
return _jsObjectRef.InvokeMultipleAsync(
"setEditable",
dictArgs);
}

public Task SetRadiuses(Dictionary<string, double> radiuses)
{
Dictionary<Guid, object> dictArgs = radiuses.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value);
var dictArgs = radiuses.ToDictionary(e => Circles[e.Key].Guid, e => (object)e.Value);
return _jsObjectRef.InvokeMultipleAsync(
"setRadius",
dictArgs);
Expand Down
4 changes: 2 additions & 2 deletions GoogleMapsComponents/Maps/Extension/ListableEntityListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public virtual async Task RemoveMultipleAsync(List<Guid> guids)
//Find the eventual match between required keys (if any) and yet stored markers key (if any)
//If filterKeys is null or empty all keys are returned
//Otherwise only eventually yet stored marker keys that matches with filterKeys
protected virtual List<string> ComputeMathingKeys(List<string> filterKeys = null)
protected virtual List<string> ComputeMathingKeys(List<string>? filterKeys = null)
{
List<string> matchingKeys;

Expand All @@ -202,7 +202,7 @@ protected virtual List<string> ComputeMathingKeys(List<string> filterKeys = null
}
else
{
matchingKeys = BaseListableEntities.Keys.Where(e => filterKeys.Contains(e)).ToList();
matchingKeys = BaseListableEntities.Keys.Where(filterKeys.Contains).ToList();
}

return matchingKeys;
Expand Down
24 changes: 12 additions & 12 deletions ServerSideDemo/Pages/MapCircleListPage.razor.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using GoogleMapsComponents;
using GoogleMapsComponents;
using GoogleMapsComponents.Maps;
using GoogleMapsComponents.Maps.Extension;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ServerSideDemo.Pages
{
Expand Down Expand Up @@ -37,8 +37,8 @@ protected override void OnInitialized()
/// </summary>
private async void CreateBunchOfCircles()
{
int howMany = this.bunchsize;
var bounds = await this.map1.InteropObject.GetBounds();
int howMany = bunchsize;
var bounds = await map1.InteropObject.GetBounds();
double maxRadius = (bounds.North - bounds.South) * 111111.0 / (10 + Math.Sqrt(howMany));
var colors = new string[] { "#FFFFFF", "#9132D1", "#FFD800", "#846A00", "#AAC643", "#C96A00", "#B200FF", "#CD6A00", "#00A321", "#7F6420" };
var rnd = new Random();
Expand All @@ -47,7 +47,7 @@ private async void CreateBunchOfCircles()
var color = colors[rnd.Next(0, colors.Length)];
var circleOptions = new CircleOptions
{
Map = this.map1.InteropObject,
Map = map1.InteropObject,
Center = new LatLngLiteral { Lat = bounds.South + rnd.NextDouble() * (bounds.North - bounds.South), Lng = bounds.West + rnd.NextDouble() * (bounds.East - bounds.West) },
Radius = (rnd.NextDouble() + 0.2) / 1.2 * maxRadius,
StrokeColor = color,
Expand All @@ -58,18 +58,18 @@ private async void CreateBunchOfCircles()
Visible = true,
ZIndex = 1000000,
};
this.circleOptionsByRef[(++this.lastId).ToString()] = circleOptions;
circleOptionsByRef[(++lastId).ToString()] = circleOptions;
}
await this.RefreshCircleList();
await RefreshCircleList();
}

private async Task RefreshCircleList()
{
this.circleList = await CircleList.SyncAsync(this.circleList, this.map1.JsRuntime, circleOptionsByRef, async (ev, sKey, entity) =>
circleList = await CircleList.SyncAsync(circleList, map1.JsRuntime, circleOptionsByRef, async (ev, sKey, entity) =>
{
// Circle has been clicked --> delete it.
this.circleOptionsByRef.Remove(sKey);
await this.RefreshCircleList();
circleOptionsByRef.Remove(sKey);
await RefreshCircleList();
});
}
}
Expand Down

0 comments on commit 87dd9f6

Please sign in to comment.