Inheritance: SharpMap.Rendering.Thematics.GradientThemeBase
コード例 #1
2
ファイル: GradientThemeTest.cs プロジェクト: lishxi/_SharpMap
        public void ReturnMaxColorForMaxValue()
        {
            var minVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Red) };
            var maxVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Blue) };

            var theme = new GradientTheme("red to blue", 10.0, 100.123, minVectorStyle, maxVectorStyle, null, null, null);

            var color = theme.GetFillColor(100.123);

            AssertColor(Color.Blue, color);
        }
コード例 #2
0
ファイル: GradientThemeTest.cs プロジェクト: lishxi/_SharpMap
 public void ClonePerformanceTest()
 {
     var colorBlend = new ColorBlend(new[] { Color.Black, Color.White }, new[] { 0.0f, 1.0f });
     var gradientTheme = new GradientTheme("aa", 0, 20, new VectorStyle(), new VectorStyle(), colorBlend,
                                           colorBlend, colorBlend, 5) { NoDataValues = new List<double> { -9999 } };
     TestHelper.AssertIsFasterThan(30,() => gradientTheme.Clone());
 }
コード例 #3
0
        public override object Clone()
        {
            var gradientTheme = new GradientTheme
            {
                AttributeName   = AttributeName,
                minValue        = minValue,
                maxValue        = maxValue,
                fillColorBlend  = (null != FillColorBlend) ? (ColorBlend)FillColorBlend.Clone() : null,
                lineColorBlend  = (null != LineColorBlend) ? (ColorBlend)LineColorBlend.Clone() : null,
                textColorBlend  = (null != TextColorBlend) ? (ColorBlend)TextColorBlend.Clone() : null,
                numberOfClasses = numberOfClasses,
                minColor        = minColor,
                maxColor        = maxColor
            };

            gradientTheme.themeItems.AddRange(ThemeItems.Select(ti => (IThemeItem)((GradientThemeItem)ti).Clone()));
            gradientTheme.minItem = (GradientThemeItem)gradientTheme.themeItems.First();
            gradientTheme.maxItem = (GradientThemeItem)gradientTheme.themeItems.Last();

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


            return(gradientTheme);
        }
コード例 #4
0
    private HtmlGenericControl LegendDiv(SharpMap.Layers.ILayer myLayer)
    {
        HtmlGenericControl legendDiv = new HtmlGenericControl("div");

        legendDiv.Style.Add("width", "2em");
        legendDiv.Style.Add("overflow", "hidden");
        legendDiv.Style.Add("position", "absolute");
        legendDiv.Style.Add("margin-left", "0.5em");
        legendDiv.Style.Add("margin-bottom", "0px");
        if (myLayer.GetType() == typeof(SharpMap.Layers.VectorLayer))
        {
            SharpMap.Layers.VectorLayer myVectorLayer = (myLayer as SharpMap.Layers.VectorLayer);

            SharpMap.Styles.VectorStyle myStyle = new SharpMap.Styles.VectorStyle();
            if (myVectorLayer.Theme != null)
            {
                if (myVectorLayer.Theme.GetType() == typeof(SharpMap.Rendering.Thematics.CustomTheme))
                {
                    SharpMap.Rendering.Thematics.CustomTheme myTheme = (myVectorLayer.Theme as SharpMap.Rendering.Thematics.CustomTheme);
                    myStyle = (myTheme.DefaultStyle as SharpMap.Styles.VectorStyle);
                }
                else if (myVectorLayer.Theme.GetType() == typeof(SharpMap.Rendering.Thematics.GradientTheme))
                {
                    SharpMap.Rendering.Thematics.GradientTheme myTheme = (myVectorLayer.Theme as SharpMap.Rendering.Thematics.GradientTheme);
                    myStyle = (myTheme.MinStyle as SharpMap.Styles.VectorStyle);
                }
            }
            else
            {
                myStyle = myVectorLayer.Style;
            }

            if (myStyle.Outline.Color.Name.ToString() != "Black")
            {
                string lineStyle = (myStyle.Outline.DashStyle.ToString() == "Dash") ? "dotted" : "solid";
                legendDiv.Style.Add("border", lineStyle + " " + myStyle.Outline.Width.ToString() + "px " + ColorToHex(myStyle.Outline.Color));
                legendDiv.Style.Add("height", "1em");
            }
            else
            {
                string lineStyle = (myStyle.Line.DashStyle.ToString() == "Dash") ? "dotted" : "solid";
                legendDiv.Style.Add("border-bottom", lineStyle + " " + myStyle.Line.Width.ToString() + "px " + ColorToHex(myStyle.Line.Color));
                legendDiv.Style.Add("height", "0.8em");
            }

            System.Drawing.SolidBrush fillBrush = (myVectorLayer.Style.Fill as System.Drawing.SolidBrush);
            if (fillBrush.Color.Name.ToString() != "Black")
            {
                HtmlGenericControl fillDiv = new HtmlGenericControl("div");
                fillDiv.Style.Add("border-left", "solid 2em " + ColorToHex(fillBrush.Color));
                fillDiv.Style.Add("height", "1.2em");
                fillDiv.Style.Add("overflow", "hidden");
                fillDiv.Style.Add("opacity ", ColorAlpha(fillBrush.Color) + "%");
                fillDiv.Style.Add("filter", "ALPHA(opacity=" + ColorAlpha(fillBrush.Color) + ")");
                legendDiv.Controls.Add(fillDiv);
            }
        }
        return(legendDiv);
    }
コード例 #5
0
ファイル: GradientThemeTest.cs プロジェクト: lishxi/_SharpMap
        public void GenerateThemeWithMaxDoubleAndMinDoubleValue()
        {
            var minVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Red) };
            var maxVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Blue) };

            var theme = new GradientTheme("red to blue", double.MinValue, double.MaxValue, minVectorStyle, maxVectorStyle, null, null, null);

            var color = theme.GetFillColor(100);

            AssertColor(Color.FromArgb(255, 127, 0, 127), color);
        }
コード例 #6
0
ファイル: GradientThemeTest.cs プロジェクト: lishxi/_SharpMap
        public void CloneGradientThemeWithNoDataValues()
        {
            var colorBlend = new ColorBlend(new[]{Color.Black, Color.White}, new[]{0.0f,1.0f});
            var gradientTheme = new GradientTheme("aa", 0, 20, new VectorStyle(), new VectorStyle(), colorBlend,
                                                  colorBlend, colorBlend)
                                                  {NoDataValues = new List<double>{-9999}};

            var gradientThemeClone = gradientTheme.Clone();

            Assert.AreEqual(gradientTheme.NoDataValues, ((GradientTheme)gradientThemeClone).NoDataValues);
        }
コード例 #7
0
ファイル: GradientThemeTest.cs プロジェクト: lishxi/_SharpMap
 public void GenerateThemeItems()
 {
     var colorBlend = new ColorBlend(new[] { Color.Black, Color.White }, new[] { 0.0f, 1.0f });
     var gradientTheme = new GradientTheme("aa", 0, 3, new VectorStyle(), new VectorStyle(), colorBlend,
                                           colorBlend, colorBlend,3) { NoDataValues = new List<double> { -9999 } };
     //assert 3 items were generated..at 0,1.5 and 3
     Assert.AreEqual(3,gradientTheme.ThemeItems.Count);
     Assert.AreEqual("0",gradientTheme.ThemeItems[0].Range);
     //use toString to make sure the machines decimal separator is used
     Assert.AreEqual(1.5.ToString(), gradientTheme.ThemeItems[1].Range);
     Assert.AreEqual("3", gradientTheme.ThemeItems[2].Range);
 }
コード例 #8
0
ファイル: GradientThemeTest.cs プロジェクト: lishxi/_SharpMap
        public void CloneGradientThemeWithNoDataValues()
        {
            var colorBlend = new ColorBlend(new[]{Color.Black, Color.White}, new[]{0.0f,1.0f});
            var gradientTheme = new GradientTheme("aa", 0, 20, new VectorStyle(), new VectorStyle(), colorBlend,
                                                  colorBlend, colorBlend,5)
                                                  {NoDataValues = new List<double>{-9999}};

            var gradientThemeClone = (GradientTheme)gradientTheme.Clone();

            Assert.AreEqual(gradientTheme.NoDataValues, (gradientThemeClone).NoDataValues);
            Assert.AreEqual(5,gradientThemeClone.NumberOfClasses);
            Assert.AreEqual(2,gradientThemeClone.FillColorBlend.Colors.Length);
        }
コード例 #9
0
ファイル: MapHelper.cs プロジェクト: junglewithyou/SharpMap
    public static Map InitializeGradientMap(Size size)
    {
        //Initialize a new map based on the simple map
        Map map = InitializeMap(size);
        //Set a gradient theme on the countries layer, based on Population density
        //First create two styles that specify min and max styles
        //In this case we will just use the default values and override the fill-colors
        //using a colorblender. If different line-widths, line- and fill-colors where used
        //in the min and max styles, these would automatically get linearly interpolated.
        VectorStyle min = new VectorStyle();
        VectorStyle max = new VectorStyle();
        //Create theme using a density from 0 (min) to 400 (max)
        GradientTheme popdens = new GradientTheme("PopDens", 0, 400, min, max);
        //We can make more advanced coloring using the ColorBlend'er.
        //Setting the FillColorBlend will override any fill-style in the min and max fills.
        //In this case we just use the predefined Rainbow colorscale
        popdens.FillColorBlend = ColorBlend.Rainbow5;
        (map.Layers[0] as VectorLayer).Theme = popdens;

        //Lets scale the labels so that big countries have larger texts as well
        LabelStyle lblMin = new LabelStyle();
        LabelStyle lblMax = new LabelStyle();
        lblMin.ForeColor = Color.Black;
        lblMin.Font = new Font(FontFamily.GenericSerif, 6);
        lblMax.ForeColor = Color.Blue;
        lblMax.BackColor = new SolidBrush(Color.FromArgb(128, 255, 255, 255));
        lblMin.BackColor = lblMax.BackColor;
        lblMax.Font = new Font(FontFamily.GenericSerif, 9);
        (map.Layers[3] as LabelLayer).Theme = new GradientTheme("PopDens", 0, 400, lblMin, lblMax);

        //Lets scale city icons based on city population
        //cities below 1.000.000 gets the smallest symbol, and cities with more than 5.000.000 the largest symbol
        VectorStyle citymin = new VectorStyle();
        VectorStyle citymax = new VectorStyle();
        citymin.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        citymin.SymbolScale = 0.5f;
        citymax.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        citymax.SymbolScale = 1f;
        (map.Layers[2] as VectorLayer).Theme = new GradientTheme("Population", 1000000, 5000000, citymin, citymax);

        //Turn off the river layer
        map.Layers[1].Enabled = false;
        return map;
    }
コード例 #10
0
ファイル: MapHelper.cs プロジェクト: cugkgq/Project
    public static SharpMap.Map InitializeGradientMap(System.Drawing.Size size)
    {
        //Initialize a new map based on the simple map
        SharpMap.Map map = InitializeMap(size);
        //Set a gradient theme on the countries layer, based on Population density
        //First create two styles that specify min and max styles
        //In this case we will just use the default values and override the fill-colors
        //using a colorblender. If different line-widths, line- and fill-colors where used
        //in the min and max styles, these would automatically get linearly interpolated.
        SharpMap.Styles.VectorStyle min = new SharpMap.Styles.VectorStyle();
        SharpMap.Styles.VectorStyle max = new SharpMap.Styles.VectorStyle();
        //Create theme using a density from 0 (min) to 400 (max)
        SharpMap.Rendering.Thematics.GradientTheme popdens = new SharpMap.Rendering.Thematics.GradientTheme("PopDens", 0, 400, min, max);
        //We can make more advanced coloring using the ColorBlend'er.
        //Setting the FillColorBlend will override any fill-style in the min and max fills.
        //In this case we just use the predefined Rainbow colorscale
        popdens.FillColorBlend = SharpMap.Rendering.Thematics.ColorBlend.Rainbow5;
        (map.Layers[0] as SharpMap.Layers.VectorLayer).Theme = popdens;

        //Lets scale the labels so that big countries have larger texts as well
        SharpMap.Styles.LabelStyle lblMin = new SharpMap.Styles.LabelStyle();
        SharpMap.Styles.LabelStyle lblMax = new SharpMap.Styles.LabelStyle();
        lblMin.ForeColor = Color.Black;
        lblMin.Font      = new Font(FontFamily.GenericSerif, 6);
        lblMax.ForeColor = Color.Blue;
        lblMax.BackColor = new SolidBrush(Color.FromArgb(128, 255, 255, 255));
        lblMin.BackColor = lblMax.BackColor;
        lblMax.Font      = new Font(FontFamily.GenericSerif, 9);
        (map.Layers[3] as SharpMap.Layers.LabelLayer).Theme = new SharpMap.Rendering.Thematics.GradientTheme("PopDens", 0, 400, lblMin, lblMax);

        //Lets scale city icons based on city population
        //cities below 1.000.000 gets the smallest symbol, and cities with more than 5.000.000 the largest symbol
        SharpMap.Styles.VectorStyle citymin = new SharpMap.Styles.VectorStyle();
        SharpMap.Styles.VectorStyle citymax = new SharpMap.Styles.VectorStyle();
        citymin.Symbol      = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        citymin.SymbolScale = 0.5f;
        citymax.Symbol      = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        citymax.SymbolScale = 1f;
        (map.Layers[2] as SharpMap.Layers.VectorLayer).Theme = new SharpMap.Rendering.Thematics.GradientTheme("Population", 1000000, 5000000, citymin, citymax);

        //Turn off the river layer
        map.Layers[1].Enabled = false;
        return(map);
    }
コード例 #11
0
        public override object Clone()
        {
            var gradientTheme = new GradientTheme(attributeName, minValue, maxValue, (IStyle)MinStyle.Clone(),
                                                  (IStyle)MaxStyle.Clone(),
                                                  (null != FillColorBlend) ? (ColorBlend)FillColorBlend.Clone() : null,
                                                  (null != LineColorBlend) ? (ColorBlend)LineColorBlend.Clone() : null,
                                                  (null != TextColorBlend) ? (ColorBlend)TextColorBlend.Clone() : null, numberOfClasses);

            gradientTheme.ThemeItems.Clear();

            foreach (var themeItem in ThemeItems)
            {
                gradientTheme.ThemeItems.Add((IThemeItem)((GradientThemeItem)themeItem).Clone());
            }

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

            return(gradientTheme);
        }
コード例 #12
0
        public static Map InitializeMap()
        {
            //Initialize a new map based on the simple map
              Map map = new Map();

              //Set up countries layer
              SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
              //Set the datasource to a shapefile in the App_data folder
              layCountries.DataSource = new SharpMap.Data.Providers.ShapeFile("GeoData/World/countries.shp", true);
              //Set fill-style to green
              layCountries.Style.Fill = new SolidBrush(Color.Green);
              //Set the polygons to have a black outline
              layCountries.Style.Outline = System.Drawing.Pens.Black;
              layCountries.Style.EnableOutline = true;
              layCountries.SRID = 4326;
              map.Layers.Add(layCountries);

              //set up cities layer
              SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
              //Set the datasource to a shapefile in the App_data folder
              layCities.DataSource = new SharpMap.Data.Providers.ShapeFile("GeoData/World/cities.shp", true);
              layCities.Style.SymbolScale = 0.8f;
              layCities.MaxVisible = 40;
              layCities.SRID = 4326;
              map.Layers.Add(layCities);

              //Set up a country label layer
              SharpMap.Layers.LabelLayer layLabel = new SharpMap.Layers.LabelLayer("Country labels");
              layLabel.DataSource = layCountries.DataSource;
              layLabel.Enabled = true;
              layLabel.LabelColumn = "Name";
              layLabel.Style = new SharpMap.Styles.LabelStyle();
              layLabel.Style.ForeColor = Color.White;
              layLabel.Style.Font = new Font(FontFamily.GenericSerif, 12);
              layLabel.Style.BackColor = new System.Drawing.SolidBrush(Color.FromArgb(128, 255, 0, 0));
              layLabel.MaxVisible = 90;
              layLabel.MinVisible = 30;
              layLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
              layLabel.SRID = 4326;
              layLabel.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;
              map.Layers.Add(layLabel);

              //Set up a city label layer
              SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City labels");
              layCityLabel.DataSource = layCities.DataSource;
              layCityLabel.Enabled = true;
              layCityLabel.LabelColumn = "Name";
              layCityLabel.Style = new SharpMap.Styles.LabelStyle();
              layCityLabel.Style.ForeColor = Color.Black;
              layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
              layCityLabel.MaxVisible = layLabel.MinVisible;
              layCityLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left;
              layCityLabel.Style.VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom;
              layCityLabel.Style.Offset = new PointF(3, 3);
              layCityLabel.Style.Halo = new Pen(Color.Yellow, 2);
              layCityLabel.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
              layCityLabel.SmoothingMode = SmoothingMode.AntiAlias;
              layCityLabel.SRID = 4326;
              layCityLabel.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
              layCityLabel.Style.CollisionDetection = true;
              map.Layers.Add(layCityLabel);

              //Set a gradient theme on the countries layer, based on Population density
              //First create two styles that specify min and max styles
              //In this case we will just use the default values and override the fill-colors
              //using a colorblender. If different line-widths, line- and fill-colors where used
              //in the min and max styles, these would automatically get linearly interpolated.
              VectorStyle min = new VectorStyle();
              VectorStyle max = new VectorStyle();
              //Create theme using a density from 0 (min) to 400 (max)
              GradientTheme popdens = new GradientTheme("PopDens", 0, 400, min, max);
              //We can make more advanced coloring using the ColorBlend'er.
              //Setting the FillColorBlend will override any fill-style in the min and max fills.
              //In this case we just use the predefined Rainbow colorscale
              popdens.FillColorBlend = SharpMap.Rendering.Thematics.ColorBlend.Rainbow5;
              layCountries.Theme = popdens;

              //Lets scale the labels so that big countries have larger texts as well
              LabelStyle lblMin = new LabelStyle();
              LabelStyle lblMax = new LabelStyle();
              lblMin.ForeColor = Color.Black;
              lblMin.Font = new Font(FontFamily.GenericSerif, 6);
              lblMax.ForeColor = Color.Blue;
              lblMax.BackColor = new SolidBrush(Color.FromArgb(128, 255, 255, 255));
              lblMin.BackColor = lblMax.BackColor;
              lblMax.Font = new Font(FontFamily.GenericSerif, 9);
              layLabel.Theme = new GradientTheme("PopDens", 0, 400, lblMin, lblMax);

              //Lets scale city icons based on city population
              //cities below 1.000.000 gets the smallest symbol, and cities with more than 5.000.000 the largest symbol
              VectorStyle citymin = new VectorStyle();
              VectorStyle citymax = new VectorStyle();
              string iconPath = "Images/icon.png";
              if (!File.Exists(iconPath))
              {
            throw new Exception(String.Format("Error file '{0}' could not be found, make sure it is at the expected location", iconPath));
              }

              citymin.Symbol = new Bitmap(iconPath);
              citymin.SymbolScale = 0.5f;
              citymax.Symbol = new Bitmap(iconPath);
              citymax.SymbolScale = 1f;
              layCities.Theme = new GradientTheme("Population", 1000000, 5000000, citymin, citymax);

              //limit the zoom to 360 degrees width
              map.MaximumZoom = 360;
              map.BackColor = Color.LightBlue;

              map.Zoom = 30;
              map.Center = new SharpMap.Geometries.Point(0, 0);

              return map;
        }
コード例 #13
0
        public static GradientTheme CreateGradientTheme(string attribute, VectorStyle defaultStyle, ColorBlend blend,
                                                        float minValue, float maxValue, int sizeMin, int sizeMax, bool skipColors, bool skipSizes, int numberOfClasses)
        {
            if (defaultStyle == null)
            {
                defaultStyle = new VectorStyle();
                defaultStyle.GeometryType = typeof(IPolygon);
            }

            Color minColor = (skipColors)? ((SolidBrush)defaultStyle.Fill).Color : blend.GetColor(0);
            Color maxColor = (skipColors) ? ((SolidBrush)defaultStyle.Fill).Color : blend.GetColor(1);

            var deltaWith = (defaultStyle.Outline.Width - defaultStyle.Line.Width);

            float minOutlineSize = deltaWith + sizeMin;
            float maxOutlineSize = deltaWith + sizeMax;

            // Use default styles if not working with VectorLayers (i.e. RegularGridCoverageLayers)
            var minStyle = (VectorStyle)defaultStyle.Clone();
            var maxStyle = (VectorStyle)defaultStyle.Clone();

            minStyle.GeometryType = defaultStyle.GeometryType;
            maxStyle.GeometryType = defaultStyle.GeometryType;

            if (defaultStyle.GeometryType == typeof(IPoint))
            {
                minStyle.Fill  = new SolidBrush(minColor);
                maxStyle.Fill  = new SolidBrush(maxColor);
                minStyle.Shape = defaultStyle.Shape;
                maxStyle.Shape = defaultStyle.Shape;
                if (!skipSizes)
                {
                    minStyle.Line.Width = sizeMin;
                    maxStyle.Line.Width = sizeMax;
                    minStyle.ShapeSize  = sizeMin;
                    maxStyle.ShapeSize  = sizeMax;
                }
            }
            else if ((defaultStyle.GeometryType == typeof(IPolygon)) || (defaultStyle.GeometryType == typeof(IMultiPolygon)))
            {
                minStyle.Fill    = new SolidBrush(minColor);
                maxStyle.Fill    = new SolidBrush(maxColor);
                minStyle.Outline = new Pen(defaultStyle.Outline.Color, minOutlineSize);
                maxStyle.Outline = new Pen(defaultStyle.Outline.Color, maxOutlineSize);
            }
            else if ((defaultStyle.GeometryType == typeof(ILineString)) || (defaultStyle.GeometryType == typeof(IMultiLineString)))
            {
                minStyle.Line    = new Pen(minColor, sizeMin);
                maxStyle.Line    = new Pen(maxColor, sizeMax);
                minStyle.Outline = new Pen(defaultStyle.Outline.Color, minOutlineSize);
                maxStyle.Outline = new Pen(defaultStyle.Outline.Color, maxOutlineSize);
            }
            else
            {
                minStyle.Fill    = new SolidBrush(minColor);
                maxStyle.Fill    = new SolidBrush(maxColor);
                minStyle.Outline = new Pen(minColor, minOutlineSize);
                maxStyle.Outline = new Pen(maxColor, maxOutlineSize);
            }

            var gradientTheme = new GradientTheme(attribute, minValue, maxValue, minStyle, maxStyle, blend, blend, null, numberOfClasses);

            return(gradientTheme);
        }
コード例 #14
0
ファイル: GradientThemeTest.cs プロジェクト: lishxi/_SharpMap
        public void GradientThemeScaleToTest()
        {
            var minStyle = new VectorStyle { Fill = new SolidBrush(Color.Red) };
            var maxStyle = new VectorStyle { Fill = new SolidBrush(Color.Blue) };

            var theme = new GradientTheme("NotLinkedToVariable", 0.0, 10.0, minStyle, maxStyle, null, null, null, 3);
            var colorMid = theme.GetFillColor(5.0);

            theme.ScaleTo(-10.0, 30.0);

            Assert.AreEqual(-10.0, theme.Min);
            Assert.AreEqual(30.0, theme.Max);
            Assert.AreEqual(3, theme.NumberOfClasses);
            Assert.AreEqual(3, theme.ThemeItems.Count);
            Assert.IsNull(theme.TextColorBlend);
            Assert.IsNull(theme.LineColorBlend);
            Assert.IsNull(theme.FillColorBlend);

            AssertColor(Color.Red, theme.GetFillColor(-10.0));
            AssertColor(colorMid, theme.GetFillColor(10.0));
            AssertColor(Color.Blue, theme.GetFillColor(30.0));

            theme.ScaleTo(-12.3, -12.3);

            Assert.AreEqual(-12.3, theme.Min);
            Assert.AreEqual(-12.3, theme.Max);
            Assert.AreEqual(3, theme.NumberOfClasses);
            Assert.AreEqual(2, theme.ThemeItems.Count); // Because max == min, only these values are defined and therefore < NumberOfClasses
            Assert.IsNull(theme.TextColorBlend);
            Assert.IsNull(theme.LineColorBlend);
            Assert.IsNull(theme.FillColorBlend);

            AssertColor(Color.Red, theme.GetFillColor(-12.3));
        }
コード例 #15
0
        private static themeGradient GetThemeGradient(GradientTheme theme)
        {
            // GradientTheme properties
            string minStyle = GetStyleConverter().ConvertToString(theme.MinStyle);
            string maxStyle = GetStyleConverter().ConvertToString(theme.MaxStyle);
            
            var gradThemeItems = new List<themeItem>();
            foreach (GradientThemeItem item in theme.ThemeItems)
            {
                // Add theme items (style and label) to the QuantityTheme
                // NOTE: Symbol isn't stored but generated during rebuilding in the QuantityThemeItem.AddStyle() method
                var gradThemeItem = new themeItem
                                        {
                                            label = item.Label,
                                            style = GetStyleConverter().ConvertToString(item.Style),
                                            intervalMaxValue = Convert.ToDouble(item.Range)
                                        };

                gradThemeItems.Add(gradThemeItem);
            }

            var themeGradient = new themeGradient
                                    {
                                        gradientThemeItems = gradThemeItems.ToArray(),
                                        columnName = theme.ColumnName,
                                        minValue = theme.Min,
                                        maxValue = theme.Max,
                                        minStyle = minStyle,
                                        maxStyle = maxStyle,
                                        noDataValues = GetNoDataValues(theme.NoDataValues),
                                        noDataValueType = GetNoDataValueType(theme.NoDataValues),

                                        // Color blends
                                        textColorBlends = (theme.TextColorBlend != null)
                                                ? CreateBlendsFromTheme(theme.TextColorBlend)
                                                : null,
                                        lineColorBlends = (theme.LineColorBlend != null)
                                                ? CreateBlendsFromTheme(theme.LineColorBlend)
                                                : null,
                                        fillColorBlends = (theme.FillColorBlend != null)
                                                ? CreateBlendsFromTheme(theme.FillColorBlend)
                                                : null
                                    };
            return themeGradient;
        }
コード例 #16
0
ファイル: ThemeFactory.cs プロジェクト: lishxi/_SharpMap
        public static GradientTheme CreateGradientTheme(string attribute, VectorStyle defaultStyle, ColorBlend blend, 
            float minValue, float maxValue, int sizeMin, int sizeMax, bool skipColors, bool skipSizes, int numberOfClasses)
        {
            if(defaultStyle == null)
            {
                defaultStyle = new VectorStyle();
                defaultStyle.GeometryType = typeof(IPolygon);
            }

            Color minColor = (skipColors)? ((SolidBrush) defaultStyle.Fill).Color : blend.GetColor(0);
            Color maxColor = (skipColors) ? ((SolidBrush)defaultStyle.Fill).Color : blend.GetColor(1);

            var deltaWith = (defaultStyle.Outline.Width - defaultStyle.Line.Width);

            float minOutlineSize = deltaWith + sizeMin;
            float maxOutlineSize = deltaWith + sizeMax;

            // Use default styles if not working with VectorLayers (i.e. RegularGridCoverageLayers)
            var minStyle = (VectorStyle) defaultStyle.Clone();
            var maxStyle = (VectorStyle) defaultStyle.Clone();

            minStyle.GeometryType = defaultStyle.GeometryType;
            maxStyle.GeometryType = defaultStyle.GeometryType;

            if (defaultStyle.GeometryType == typeof(IPoint))
            {
                minStyle.Fill = new SolidBrush(minColor);
                maxStyle.Fill = new SolidBrush(maxColor);
                minStyle.Shape = defaultStyle.Shape;
                maxStyle.Shape = defaultStyle.Shape;
                if (!skipSizes)
                {
                    minStyle.Line.Width = sizeMin;
                    maxStyle.Line.Width = sizeMax;
                    minStyle.ShapeSize = sizeMin;
                    maxStyle.ShapeSize = sizeMax;
                }
            }
            else if ((defaultStyle.GeometryType == typeof(IPolygon)) || (defaultStyle.GeometryType == typeof(IMultiPolygon)))
            {
                minStyle.Fill = new SolidBrush(minColor);
                maxStyle.Fill = new SolidBrush(maxColor);
                minStyle.Outline = new Pen(defaultStyle.Outline.Color, minOutlineSize);
                maxStyle.Outline = new Pen(defaultStyle.Outline.Color, maxOutlineSize);
            }
            else if ((defaultStyle.GeometryType == typeof(ILineString)) || (defaultStyle.GeometryType == typeof(IMultiLineString)))
            {
                minStyle.Line = new Pen(minColor, sizeMin);
                maxStyle.Line = new Pen(maxColor, sizeMax);
                minStyle.Outline = new Pen(defaultStyle.Outline.Color, minOutlineSize);
                maxStyle.Outline = new Pen(defaultStyle.Outline.Color, maxOutlineSize);
            }
            else
            {
                minStyle.Fill = new SolidBrush(minColor);
                maxStyle.Fill = new SolidBrush(maxColor);
                minStyle.Outline = new Pen(minColor, minOutlineSize);
                maxStyle.Outline = new Pen(maxColor, maxOutlineSize);
            }

            var gradientTheme = new GradientTheme(attribute, minValue, maxValue, minStyle, maxStyle, blend, blend, null, numberOfClasses);
            return gradientTheme;
       }
コード例 #17
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;
        }
コード例 #18
0
ファイル: GradientThemeTest.cs プロジェクト: lishxi/_SharpMap
        public void GetStyleForNoDataValue()
        {
            var minVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Red) };
            var maxVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Blue) };
            var theme = new GradientTheme("red to blue", 10.0, 100.123, minVectorStyle, maxVectorStyle, null, null, null)
                {
                    NoDataValues = new List<double> {12.3}
                };

            var result = (VectorStyle)theme.GetStyle(10.0);
            AssertColor(Color.Red, ((SolidBrush)result.Fill).Color); // Expecting SolidBrush
            AssertColor(Color.FromArgb(255, 138,43, 226), result.Line.Color);

            result = (VectorStyle)theme.GetStyle(12.3);
            AssertColor(Color.Transparent, ((SolidBrush)result.Fill).Color); // Expecting SolidBrush
            AssertColor(Color.Transparent, result.Line.Color);
        }