예제 #1
0
        /// <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 <MarkerList> SyncAsync(MarkerList list, IJSRuntime jsRuntime, Dictionary <string, MarkerOptions> opts, Action <MouseEvent, string, Marker> clickCallback = null)
        {
            if (opts.Count == 0)
            {
                if (list != null)
                {
                    await list.SetMultipleAsync(opts);

                    list = null;
                }
            }
            else
            {
                if (list == null)
                {
                    list = await MarkerList.CreateAsync(jsRuntime, new Dictionary <string, MarkerOptions>());

                    if (clickCallback != null)
                    {
                        list.EntityClicked += (sender, e) => {
                            clickCallback(e.MouseEvent, e.Key, e.Entity);
                        };
                    }
                }
                await list.SetMultipleAsync(opts);
            }
            return(list);
        }
예제 #2
0
        /// <summary>
        /// Create markers list
        /// </summary>
        /// <param name="jsRuntime"></param>
        /// <param name="opts">Dictionary of desired Marker keys and MarkerOptions values. Key as any type unique key. Not nessary Guid</param>
        /// <returns>new instance of MarkerList class will be returned with its Markers dictionary member populated with the corresponding results</returns>
        public static async Task <MarkerList> CreateAsync(IJSRuntime jsRuntime, Dictionary <string, MarkerOptions> opts)
        {
            JsObjectRef jsObjectRef = new JsObjectRef(jsRuntime, Guid.NewGuid());

            MarkerList obj;
            Dictionary <string, JsObjectRef> jsObjectRefs = await JsObjectRef.CreateMultipleAsync(
                jsRuntime,
                "google.maps.Marker",
                opts.ToDictionary(e => e.Key, e => (object)e.Value));

            Dictionary <string, Marker> objs = jsObjectRefs.ToDictionary(e => e.Key, e => new Marker(e.Value));

            obj = new MarkerList(jsObjectRef, objs);

            return(obj);
        }