/// <summary> /// Sync list over lifetime: Create and remove list depending on entity count; /// entities will be removed, added or changed to mirror the given set. /// </summary> /// <param name="list"> /// The list to manage. May be null. /// </param> /// <param name="jsRuntime"></param> /// <param name="opts"></param> /// <returns> /// The managed list. Assign to the variable you used as parameter. /// </returns> public static async Task <PolylineList> SyncAsync(PolylineList list, IJSRuntime jsRuntime, Dictionary <string, PolylineOptions> opts, Action <MouseEvent, string, Polyline> clickCallback = null) { if (opts.Count == 0) { if (list != null) { await list.SetMultipleAsync(opts); list = null; } } else { if (list == null) { list = await PolylineList.CreateAsync(jsRuntime, new Dictionary <string, PolylineOptions>()); if (clickCallback != null) { list.EntityClicked += (sender, e) => { clickCallback(e.MouseEvent, e.Key, e.Entity); }; } } await list.SetMultipleAsync(opts); } return(list); }
/// <summary> /// Create circles list /// </summary> /// <param name="jsRuntime"></param> /// <param name="opts">Dictionary of desired Polyline keys and PolylineOptions values. Key as any type unique key. Not nessary Guid</param> /// <returns>new instance of PolylineList class will be returned with its Polylines dictionary member populated with the corresponding results</returns> public static async Task <PolylineList> CreateAsync(IJSRuntime jsRuntime, Dictionary <string, PolylineOptions> opts) { JsObjectRef jsObjectRef = new JsObjectRef(jsRuntime, Guid.NewGuid()); PolylineList obj; Dictionary <string, JsObjectRef> jsObjectRefs = await JsObjectRef.CreateMultipleAsync( jsRuntime, "google.maps.Polyline", opts.ToDictionary(e => e.Key, e => (object)e.Value)); Dictionary <string, Polyline> objs = jsObjectRefs.ToDictionary(e => e.Key, e => new Polyline(e.Value)); obj = new PolylineList(jsObjectRef, objs); return(obj); }