Пример #1
0
        public static CategorialTheme CreateCategorialTheme(string attribute, VectorStyle defaultStyle, ColorBlend blend,
                                                            int numberOfClasses, IList <IComparable> values, List <string> categories, int sizeMin, int sizeMax)
        {
            if (defaultStyle == null)
            {
                defaultStyle = new VectorStyle
                {
                    GeometryType = typeof(IPolygon)
                };
            }

            var categorialTheme = new CategorialTheme(attribute, defaultStyle);

            for (int i = 0; i < numberOfClasses; i++)
            {
                string label = (categories != null)
                                   ? categories[i]
                                   : values[i].ToString();

                Color color = (numberOfClasses > 1)
                                  ? blend.GetColor((float)i / (numberOfClasses - 1))
                                  : ((SolidBrush)defaultStyle.Fill).Color;

                var vectorStyle = (VectorStyle)defaultStyle.Clone();

                var size = sizeMin + (sizeMax - sizeMin) * i / (float)numberOfClasses;

                if (defaultStyle.GeometryType == typeof(IPoint))
                {
                    vectorStyle.Fill       = new SolidBrush(color);
                    vectorStyle.Line.Width = 16;
                    vectorStyle.Shape      = defaultStyle.Shape;
                }
                else if ((defaultStyle.GeometryType == typeof(IPolygon)) || (defaultStyle.GeometryType == typeof(IMultiPolygon)))
                {
                    vectorStyle.Fill = new SolidBrush(color);
                }
                else if ((defaultStyle.GeometryType == typeof(ILineString)) || (defaultStyle.GeometryType == typeof(IMultiLineString)))
                {
                    vectorStyle.Line = CreatePen(color, size, defaultStyle.Line);
                }
                else
                {
                    vectorStyle.Fill = new SolidBrush(color);
                }

                CategorialThemeItem categorialThemeItem = (values[i] != null)
                                                              ? new CategorialThemeItem(label, vectorStyle, vectorStyle.LegendSymbol, values[i])
                                                              : new CategorialThemeItem(label, vectorStyle, vectorStyle.LegendSymbol);


                categorialTheme.AddThemeItem(categorialThemeItem);
            }

            return(categorialTheme);
        }
        public override object Clone()
        {
            var categorialTheme = new CategorialTheme(AttributeName, (IStyle)defaultStyle.Clone());

            foreach (CategorialThemeItem categorialThemeItem in ThemeItems)
            {
                categorialTheme.ThemeItems.Add((CategorialThemeItem)categorialThemeItem.Clone());
            }

            if (NoDataValues != null)
            {
                categorialTheme.NoDataValues = NoDataValues.Cast <object>().ToArray();
            }

            return(categorialTheme);
        }