Ejemplo n.º 1
0
        private static IStyle GetDefaultStyle(theme theme)
        {
            string style = "";

            switch (GetThemeType(theme))
            {
            case ThemeType.Custom:
                style = ((themeCustom)theme.Item).defaultStyle;
                break;

            case ThemeType.Categorial:
                style = ((themeCategory)theme.Item).defaultStyle;
                break;

            case ThemeType.Gradient:
                break;

            case ThemeType.Quantity:
                style = ((themeQuantity)theme.Item).defaultStyle;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return((style != string.Empty) ? (IStyle)GetStyleConverter().ConvertFrom(style) : null);
        }
Ejemplo n.º 2
0
 private static CustomTheme GetCustomTheme(theme theme)
 {
     return(new CustomTheme(null)
     {
         DefaultStyle = GetDefaultStyle(theme)
     });
 }
Ejemplo n.º 3
0
        private static CategorialTheme GetCategorialTheme(theme theme)
        {
            var themeCategory = (themeCategory)theme.Item;
            var defaultStyle  = GetDefaultStyle(theme);

            var categorialTheme = new CategorialTheme(themeCategory.columnName, defaultStyle);

            foreach (themeItem catThemeItem in themeCategory.categoryThemeItems)
            {
                var categorialThemeItem = new CategorialThemeItem(catThemeItem.label, GetStyle(catThemeItem), null);
                categorialTheme.AddThemeItem(categorialThemeItem);
            }

            return(categorialTheme);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts from a a <see cref="SharpMap"/> <see cref="ITheme"/> object to a XML-like string
        /// </summary>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <param name="value"></param>
        /// <param name="destinationType"></param>
        /// <returns></returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (!(value is ITheme) || !destinationType.Equals(typeof(string)))
            {
                // Use the base converter if the target type is unsupported
                return(base.ConvertTo(context, culture, value, destinationType));
            }

            // Get the ITheme to convert from
            var to   = new theme();
            var from = (ITheme)value;

            switch (GetThemeType(from))
            {
            case ThemeType.Custom:
                to.Item = GetThemeCustom((CustomTheme)from);
                break;

            case ThemeType.Categorial:
                to.Item = GetThemeCategorial((CategorialTheme)from);
                break;

            case ThemeType.Gradient:
                to.Item = GetThemeGradient((GradientTheme)from);
                break;

            case ThemeType.Quantity:
                to.Item = GetThemeQuantity((QuantityTheme)from);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // Return the theme classes as an xml data string
            var sb  = new StringBuilder();
            var xml = new XmlSerializer(typeof(theme));

            xml.Serialize(new StringWriter(sb), to);

            return(sb.ToString());
        }
Ejemplo n.º 5
0
        private static GradientTheme GetGradientTheme(theme theme)
        {
            var themeGradient = (themeGradient)theme.Item;
            var minStyle      = (IStyle)GetStyleConverter().ConvertFrom(themeGradient.minStyle);
            var maxStyle      = (IStyle)GetStyleConverter().ConvertFrom(themeGradient.maxStyle);


            var gradTheme = new GradientTheme(themeGradient.columnName,
                                              themeGradient.minValue,
                                              themeGradient.maxValue,
                                              minStyle,
                                              maxStyle,
                                              // Color blend properties
                                              (themeGradient.fillColorBlends != null)
                                                  ? createColorBlendForTheme(themeGradient.fillColorBlends)
                                                  : null,
                                              (themeGradient.lineColorBlends != null)
                                                  ? createColorBlendForTheme(themeGradient.lineColorBlends)
                                                  : null,
                                              (themeGradient.textColorBlends != null)
                                                  ? createColorBlendForTheme(themeGradient.textColorBlends)
                                                  : null)
            {
                NoDataValues = ConvertNoDataValues(themeGradient.noDataValues, themeGradient.noDataValueType)
            };

            gradTheme.ThemeItems.Clear();

            foreach (themeItem gradThemeItem in themeGradient.gradientThemeItems)
            {
                var themeStyle        = GetStyle(gradThemeItem);
                var gradientThemeItem = new GradientThemeItem(themeStyle, gradThemeItem.label, gradThemeItem.intervalMaxValue.ToString());

                gradTheme.ThemeItems.Add(gradientThemeItem);
            }

            return(gradTheme);
        }
Ejemplo n.º 6
0
        private static ThemeType GetThemeType(theme theme)
        {
            var type = theme.Item.GetType();

            if (type.Equals(typeof(themeCustom)))
            {
                return(ThemeType.Custom);
            }
            if (type.Equals(typeof(themeCategory)))
            {
                return(ThemeType.Categorial);
            }
            if (type.Equals(typeof(themeGradient)))
            {
                return(ThemeType.Gradient);
            }
            if (type.Equals(typeof(themeQuantity)))
            {
                return(ThemeType.Quantity);
            }

            return(ThemeType.Custom);
        }
Ejemplo n.º 7
0
        private static QuantityTheme GetQuantityTheme(theme theme)
        {
            var themeQuantity = (themeQuantity)theme.Item;

            var quanTheme = new QuantityTheme(themeQuantity.columnName, GetDefaultStyle(theme))
            {
                NoDataValues = ConvertNoDataValues(themeQuantity.noDataValues, themeQuantity.noDataValueType)
            };

            foreach (themeItem quanThemeItem in themeQuantity.quantityThemeItems)
            {
                var themeStyle = GetStyle(quanThemeItem);
                var interval   = new Interval(quanThemeItem.intervalMinValue,
                                              quanThemeItem.intervalMaxValue);

                var themeItem = new QuantityThemeItem(interval, themeStyle)
                {
                    Label = quanThemeItem.label
                };
                quanTheme.ThemeItems.Add(themeItem);
            }

            return(quanTheme);
        }
Ejemplo n.º 8
0
        private static GradientTheme GetGradientTheme(theme theme)
        {
            var themeGradient = (themeGradient)theme.Item;
            var minStyle = (IStyle)GetStyleConverter().ConvertFrom(themeGradient.minStyle);
            var maxStyle = (IStyle)GetStyleConverter().ConvertFrom(themeGradient.maxStyle);


            var gradTheme = new GradientTheme(themeGradient.columnName,
                                              themeGradient.minValue,
                                              themeGradient.maxValue,
                                              minStyle,
                                              maxStyle,
                                              // Color blend properties
                                              (themeGradient.fillColorBlends != null)
                                                  ? createColorBlendForTheme(themeGradient.fillColorBlends)
                                                  : null,
                                              (themeGradient.lineColorBlends != null)
                                                  ? createColorBlendForTheme(themeGradient.lineColorBlends)
                                                  : null,
                                              (themeGradient.textColorBlends != null)
                                                  ? createColorBlendForTheme(themeGradient.textColorBlends)
                                                  : null)
                                {
                                    NoDataValues = ConvertNoDataValues(themeGradient.noDataValues, themeGradient.noDataValueType)
                                };

            gradTheme.ThemeItems.Clear();

            foreach (themeItem gradThemeItem in themeGradient.gradientThemeItems)
            {
                var themeStyle = GetStyle(gradThemeItem);
                var gradientThemeItem = new GradientThemeItem(themeStyle, gradThemeItem.label, gradThemeItem.intervalMaxValue.ToString());
                
                gradTheme.ThemeItems.Add(gradientThemeItem);
            }

            return gradTheme;
        }
Ejemplo n.º 9
0
 private static CustomTheme GetCustomTheme(theme theme)
 {
     return new CustomTheme(null) { DefaultStyle = GetDefaultStyle(theme) };
 }
Ejemplo n.º 10
0
        private static ThemeType GetThemeType(theme theme)
        {
            var type = theme.Item.GetType();

            if (type.Equals(typeof(themeCustom))) return ThemeType.Custom;
            if (type.Equals(typeof(themeCategory))) return ThemeType.Categorial;
            if (type.Equals(typeof(themeGradient))) return ThemeType.Gradient;
            if (type.Equals(typeof(themeQuantity))) return ThemeType.Quantity;

            return ThemeType.Custom;
        }
Ejemplo n.º 11
0
        private static IStyle GetDefaultStyle(theme theme)
        {
            string style = "";

            switch (GetThemeType(theme))
            {
                case ThemeType.Custom:
                    style = ((themeCustom)theme.Item).defaultStyle;
                    break;
                case ThemeType.Categorial:
                    style = ((themeCategory)theme.Item).defaultStyle;
                    break;
                case ThemeType.Gradient:
                    break;
                case ThemeType.Quantity:
                    style = ((themeQuantity)theme.Item).defaultStyle;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            return (style != string.Empty) ? (IStyle)GetStyleConverter().ConvertFrom(style) : null;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Converts from a a <see cref="SharpMap"/> <see cref="ITheme"/> object to a XML-like string
        /// </summary>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <param name="value"></param>
        /// <param name="destinationType"></param>
        /// <returns></returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (!(value is ITheme) || !destinationType.Equals(typeof (string)))
            {
                // Use the base converter if the target type is unsupported
                return base.ConvertTo(context, culture, value, destinationType);
            }

            // Get the ITheme to convert from
            var to = new theme();
            var from = (ITheme) value;
 
            switch (GetThemeType(from))
            {
                case ThemeType.Custom:
                    to.Item = GetThemeCustom((CustomTheme)from);
                    break;
                case ThemeType.Categorial:
                    to.Item = GetThemeCategorial((CategorialTheme)from);
                    break;
                case ThemeType.Gradient:
                    to.Item = GetThemeGradient((GradientTheme)from);
                    break;
                case ThemeType.Quantity:
                    to.Item = GetThemeQuantity((QuantityTheme) from);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
 
            // Return the theme classes as an xml data string
            var sb = new StringBuilder();
            var xml = new XmlSerializer(typeof (theme));
            xml.Serialize(new StringWriter(sb), to);
            
            return sb.ToString();
        }
Ejemplo n.º 13
0
        private static CategorialTheme GetCategorialTheme(theme theme)
        {
            var themeCategory = (themeCategory)theme.Item;
            var defaultStyle = GetDefaultStyle(theme);
            
            var categorialTheme = new CategorialTheme(themeCategory.columnName, defaultStyle);

            foreach (themeItem catThemeItem in themeCategory.categoryThemeItems)
            {
                var categorialThemeItem = new CategorialThemeItem(catThemeItem.label, GetStyle(catThemeItem), null);
                categorialTheme.AddThemeItem(categorialThemeItem);
            }

            return categorialTheme;
        }
Ejemplo n.º 14
0
        private static QuantityTheme GetQuantityTheme(theme theme)
        {
            var themeQuantity = (themeQuantity) theme.Item;

            var quanTheme = new QuantityTheme(themeQuantity.columnName, GetDefaultStyle(theme))
                                {
                                    NoDataValues = ConvertNoDataValues(themeQuantity.noDataValues, themeQuantity.noDataValueType)
                                };
                        
            foreach (themeItem quanThemeItem in themeQuantity.quantityThemeItems)
            {
                var themeStyle = GetStyle(quanThemeItem);
                var interval = new Interval(quanThemeItem.intervalMinValue,
                                            quanThemeItem.intervalMaxValue);

                var themeItem = new QuantityThemeItem(interval, themeStyle) {Label = quanThemeItem.label};
                quanTheme.ThemeItems.Add(themeItem);
            }
            
            return quanTheme;
        }