/// <summary>
        /// Retrieves an instance from script data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public static DirectionsStep FromScriptData(IDictionary <string, object> data)
        {
            if (data != null)
            {
                var    step = new DirectionsStep();
                object value;

                if (data.TryGetValue("distance", out value))
                {
                    step.Distance = Distance.FromScriptData((IDictionary <string, object>)value);
                }
                if (data.TryGetValue("duration", out value))
                {
                    step.Duration = Duration.FromScriptData((IDictionary <string, object>)value);
                }
                if (data.TryGetValue("end_location", out value))
                {
                    step.EndLocation = LatLng.FromScriptData((IDictionary <string, object>)value);
                }
                if (data.TryGetValue("instructions", out value))
                {
                    step.Instructions = (string)value;
                }
                if (data.TryGetValue("start_location", out value))
                {
                    step.StartLocation = LatLng.FromScriptData((IDictionary <string, object>)value);
                }

                return(step);
            }
            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Retrieves an instance from script data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public static DirectionsChangedEventArgs FromScriptData(IDictionary <string, object> data)
        {
            var    args = new DirectionsChangedEventArgs();
            object value;

            if (data.TryGetValue("distance", out value))
            {
                args.Distance = Distance.FromScriptData(value as IDictionary <string, object>);
            }
            if (data.TryGetValue("duration", out value))
            {
                args.Duration = Duration.FromScriptData(value as IDictionary <string, object>);
            }
            if (data.TryGetValue("end_address", out value))
            {
                args.EndAddress = value as string;
            }
            if (data.TryGetValue("end_location", out value))
            {
                args.EndLocation = LatLng.FromScriptData(value as IDictionary <string, object>);
            }
            if (data.TryGetValue("start_address", out value))
            {
                args.StartAddress = value as string;
            }
            if (data.TryGetValue("start_location", out value))
            {
                args.StartLocation = LatLng.FromScriptData(value as IDictionary <string, object>);
            }

            if (data.TryGetValue("steps", out value))
            {
                object[] items = value as object[];
                if (items != null)
                {
                    var list = new List <DirectionsStep>();
                    for (int i = 0; i < items.Length; i++)
                    {
                        var item = DirectionsStep.FromScriptData(items[i] as IDictionary <string, object>);
                        if (item != null)
                        {
                            list.Add(item);
                        }
                    }
                    args.Steps = list.ToArray();
                }
            }

            return(args);
        }