Пример #1
0
        private static ITheme CreateDefaultGradientTheme(string columnName, Tuple <double, double> tuple)
        {
            double minValue        = tuple.value1;
            double maxValue        = tuple.value2;
            string attribute       = columnName;
            int    numberOfClasses = 10;

            // use polygon for grids so style will be shown nicely in dialog
            var defaultStyle = new VectorStyle {
                GeometryType = typeof(IPolygon)
            };
            var blend = new ColorBlend(new Color[] { Color.Black, Color.White }, new float[] { 0, 1 });
            int size  = (int)defaultStyle.SymbolScale;

            GradientTheme gradientTheme = ThemeFactory.CreateGradientTheme(attribute, defaultStyle,
                                                                           blend,
                                                                           (float)Convert.ChangeType(minValue, typeof(float)),
                                                                           (float)Convert.ChangeType(maxValue, typeof(float)),
                                                                           size,
                                                                           size,
                                                                           false,
                                                                           false);

            return(gradientTheme);
        }
Пример #2
0
        private static GradientTheme CreateCountryTheme()
        {
            //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.
            var min = new VectorStyle();

            min.Outline = new Pen {
                Color = Color.Black
            };

            var max = new VectorStyle();

            max.Outline = new Pen {
                Color = Color.Black
            };

            //Create theme using a density from 0 (min) to 400 (max)
            var 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;
            //countries.Styles.Clear(); //remove styles added earlier
            return(popdens);
        }
Пример #3
0
        protected static ITheme GenerateDefaultTheme(IEnumerable values, string name, IList noDataValues,
                                                     object minValue, object maxValue)
        {
            if (minValue.Equals(double.NaN))
            {
                throw new ArgumentException("Nan is invalid as minvalue for theme");
            }


            double min = Convert.ToDouble(minValue);
            double max = Convert.ToDouble(maxValue);


            var minStyle = new VectorStyle {
                GeometryType = typeof(IPolygon)
            };
            var maxStyle = new VectorStyle {
                GeometryType = typeof(IPolygon)
            };


            minStyle.Fill = new SolidBrush(Color.Green);
            maxStyle.Fill = new SolidBrush(Color.Blue);
            var gradientTheme = new GradientTheme(name, min, max, minStyle, maxStyle, null, null, null)
            {
                NoDataValues = noDataValues
            };

            return(gradientTheme);
        }
Пример #4
0
        private void GenerateTheme()
        {
            var minVectorStyle = new VectorStyle();
            var maxVectorStyle = new VectorStyle();

            minVectorStyle.Fill = new SolidBrush(Color.Red);
            maxVectorStyle.Fill = new SolidBrush(Color.Blue);

            Theme = new GradientTheme("Red to Blue", values.Min(), values.Max(), minVectorStyle, maxVectorStyle, null, null, null);
        }
Пример #5
0
        public static string ToThemeId(this GradientTheme theme)
        {
            switch (theme)
            {
            case GradientTheme.Default:
                return("b38a3fad-0b4f-42ed-9d55-849a4615d181");

            default:
                throw new ArgumentOutOfRangeException(nameof(theme), theme, null);
            }
        }
        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());
        }
Пример #7
0
        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);
        }
        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);
        }
        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);
        }
Пример #10
0
        public void TestGradientTheme()
        {
            var tS = new GradientTheme("AttributeName", 10, 50,
                                       VectorStyle.CreateRandomLinealStyle(),
                                       VectorStyle.CreateRandomLinealStyle());
            GradientTheme tD = null;

            Assert.DoesNotThrow(() => tD = SandD(tS, GetFormatter()));
            Assert.IsNotNull(tD);

            Assert.AreEqual(tS.ColumnName, tD.ColumnName);
            Assert.AreEqual(tS.Min, tD.Min, "Min");
            StylesTest.AreVectorStylesEqual((VectorStyle)tS.MinStyle, (VectorStyle)tS.MinStyle);
            Assert.AreEqual(tS.Max, tD.Max, "Max");
            StylesTest.AreVectorStylesEqual((VectorStyle)tS.MaxStyle, (VectorStyle)tD.MaxStyle);
        }
Пример #11
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);
        }
Пример #12
0
    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);
    }
Пример #13
0
        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);
        }
Пример #14
0
        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);

            Assert.AreEqual(255, color.A);
            Assert.AreEqual(127, color.R);
            Assert.AreEqual(0, color.G);
            Assert.AreEqual(127, color.B);
        }
Пример #15
0
        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);
        }
        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));
        }
Пример #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
        private void GenerateTheme()
        {
            if (Theme != null)
            {
                if (Theme is GradientTheme)
                {
                    var gradientTheme = theme as GradientTheme;

                    if (gradientTheme != null)
                    {
                        var variable = Coverage.Components[0];
                        if (variable != null)
                        {
                            gradientTheme.Min = (double)variable.MinValue;
                            gradientTheme.Max = (double)variable.MaxValue;
                            gradientTheme.UpdateThemeItems();
                        }
                    }
                }

                return;
            }
            var minVectorStyle = new VectorStyle();
            var maxVectorStyle = new VectorStyle();

            minVectorStyle.Fill = new SolidBrush(Color.MediumSeaGreen);
            maxVectorStyle.Fill = new SolidBrush(Color.DarkBlue);

            if (values.Count == 0)
            {
                return;
            }

            AutoUpdateThemeOnDataSourceChanged = true;

            Theme = new GradientTheme("Green to Blue", values.Min(), values.Max(), minVectorStyle, maxVectorStyle, null, null, null);
        }
        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);
        }
Пример #20
0
        private static GradientTheme CreateCountryLabelTheme()
        {
            //Lets scale the labels so that big countries have larger texts as well
            var lblMin = new LabelStyle();
            var lblMax = new LabelStyle();

            lblMin.ForeColor = Color.Black;
            lblMin.Font      = new Font {
                FontFamily = "GenericSerif", Size = 6
            };
            lblMax.ForeColor = Color.Blue;
            lblMax.BackColor = new Brush {
                Color = new Color {
                    A = 128, R = 255, G = 255, B = 255
                }
            };
            lblMin.BackColor = lblMax.BackColor;
            lblMax.Font      = new Font {
                FontFamily = "GenericSerif", Size = 9
            };
            var labelTheme = new GradientTheme("PopDens", 0, 400, lblMin, lblMax);

            return(labelTheme);
        }
        ILegendItem CreateGradientThemeLegendItems(ILegendSettings settings, GradientTheme gt)
        {
            var res = new LegendItem {
                Label       = " (" + gt.ColumnName + ")",
                Indentation = settings.SymbolSize.Width
            };
            var fcb = gt.FillColorBlend;
            var lcb = gt.LineColorBlend;
            var tcb = gt.TextColorBlend;

            for (var i = 0; i < fcb.Positions.Length; i++)
            {
                var tmp = gt.Min + fcb.Positions[i] * (gt.Max - gt.Min);
                var sl  = new LegendItem {
                    Label      = tmp.ToString("N"),
                    LabelFont  = settings.ItemFont,
                    LabelBrush = tcb != null ? new SolidBrush(tcb.Colors[i]) : settings.ForeColor,
                    Symbol     = CreateSymbol(settings.SymbolSize, fcb.Colors[i], lcb != null ? lcb.Colors[i] : Color.Transparent),
                    Parent     = res, Item = i
                };
                res.SubItems.Add(sl);
            }
            return(res);
        }
Пример #22
0
        public static Map InitializeMap(float angle)
        {
            //Initialize a new map based on the simple map
            Map map = new Map();

            //Set up countries layer
            VectorLayer layCountries = new VectorLayer("Countries");

            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new ShapeFileEx("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       = Pens.Black;
            layCountries.Style.EnableOutline = true;
            layCountries.SRID = 4326;
            map.Layers.Add(layCountries);

            //set up cities layer
            VectorLayer layCities = new VectorLayer("Cities");

            //Set the datasource to a shapefile in the App_data folder
            layCities.DataSource        = new ShapeFileEx("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
            LabelLayer layLabel = new LabelLayer("Country labels");

            layLabel.DataSource                = layCountries.DataSource;
            layLabel.Enabled                   = true;
            layLabel.LabelColumn               = "Name";
            layLabel.Style                     = new LabelStyle();
            layLabel.Style.ForeColor           = Color.White;
            layLabel.Style.Font                = new Font(FontFamily.GenericSerif, 12);
            layLabel.Style.BackColor           = new SolidBrush(Color.FromArgb(128, 255, 0, 0));
            layLabel.MaxVisible                = 90;
            layLabel.MinVisible                = 30;
            layLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
            layLabel.SRID = 4326;
            layLabel.MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest;
            map.Layers.Add(layLabel);

            //Set up a city label layer
            LabelLayer layCityLabel = new LabelLayer("City labels");

            layCityLabel.DataSource                = layCities.DataSource;
            layCityLabel.Enabled                   = true;
            layCityLabel.LabelColumn               = "Name";
            layCityLabel.Style                     = new LabelStyle();
            layCityLabel.Style.ForeColor           = Color.Black;
            layCityLabel.Style.Font                = new Font(FontFamily.GenericSerif, 11);
            layCityLabel.MaxVisible                = layLabel.MinVisible;
            layCityLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;
            layCityLabel.Style.VerticalAlignment   = LabelStyle.VerticalAlignmentEnum.Bottom;
            layCityLabel.Style.Offset              = new PointF(3, 3);
            layCityLabel.Style.Halo                = new Pen(Color.Yellow, 2);
            layCityLabel.TextRenderingHint         = TextRenderingHint.AntiAlias;
            layCityLabel.SmoothingMode             = SmoothingMode.AntiAlias;
            layCityLabel.SRID        = 4326;
            layCityLabel.LabelFilter = 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 = 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 Point(0, 0);

            Matrix mat = new Matrix();

            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;

            return(map);
        }
Пример #23
0
        public static Map InitializeMap()
        {
            //Initialize a new map based on the simple map
            var map = new Map();

            //Layer osm = new Layer("OSM");
            //string url = "http://labs.metacarta.com/wms-c/tilecache.py?version=1.1.1&amp;request=GetCapabilities&amp;service=wms-c";
            //var tileSources = TileSourceWmsC.TileSourceBuilder(new Uri(url), null);
            //var tileSource = new List<ITileSource>(tileSources).Find(source => source.Schema.Name == "osm-map");
            //osm.DataSource = new TileProvider(tileSource, "OSM");
            //map.Layers.Add(osm);

            //Set up countries layer
            var countryLayer = new Layer("Countries");

            //Set the datasource to a shapefile in the App_data folder
            countryLayer.DataSource      = new ShapeFile("GeoData/World/countries.shp", true);
            countryLayer.DataSource.SRID = 4326;

            var style = new VectorStyle
            {
                Fill = new Brush {
                    Color = Color.Green
                },
                Outline = new Pen {
                    Color = Color.Black
                }
            };

            countryLayer.Styles.Add(style);
            map.Layers.Add(countryLayer);

            //set up cities layer
            var cityLayer = new Layer("Cities");

            //Set the datasource to a shapefile in the App_data folder
            cityLayer.DataSource      = new ShapeFile("GeoData/World/cities.shp", true);
            cityLayer.DataSource.SRID = 4326;
            cityLayer.MaxVisible      = 0.09;
            map.Layers.Add(cityLayer);

            //Set up a country label layer
            var countryLabelLayer = new LabelLayer("Country labels");

            countryLabelLayer.DataSource      = countryLayer.DataSource;
            countryLabelLayer.DataSource.SRID = 4326;
            countryLabelLayer.Enabled         = true;
            countryLabelLayer.MaxVisible      = 0.18;
            countryLabelLayer.MinVisible      = 0.054;
            countryLabelLayer.LabelColumn     = "NAME";
            var labelStyle = new LabelStyle();

            labelStyle.ForeColor = Color.Black;
            labelStyle.Font      = new Font {
                FontFamily = "GenericSerif", Size = 12
            };
            labelStyle.BackColor = new Brush {
                Color = new Color {
                    A = 128, R = 255, G = 255, B = 255
                }
            };
            labelStyle.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
            countryLabelLayer.MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest;
            countryLabelLayer.Styles.Add(labelStyle);
            map.Layers.Add(countryLabelLayer);

            //Set up a city label layer
            var cityLabelLayer = new LabelLayer("City labels");

            cityLabelLayer.DataSource      = cityLayer.DataSource;
            cityLabelLayer.DataSource.SRID = 4326;
            cityLabelLayer.Enabled         = true;
            cityLabelLayer.LabelColumn     = "NAME";
            cityLabelLayer.MaxVisible      = countryLabelLayer.MinVisible;
            cityLabelLayer.MinVisible      = 0;
            cityLabelLayer.LabelFilter     = LabelCollisionDetection.ThoroughCollisionDetection;
            var cityLabelStyle = new LabelStyle();

            cityLabelStyle.ForeColor = Color.Black;
            cityLabelStyle.Font      = new Font {
                FontFamily = "GenericSerif", Size = 11
            };
            cityLabelStyle.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;
            cityLabelStyle.VerticalAlignment   = LabelStyle.VerticalAlignmentEnum.Bottom;
            cityLabelStyle.Offset = new Offset {
                X = 3, Y = 3
            };
            cityLabelStyle.Halo = new Pen {
                Color = Color.Yellow, Width = 2
            };
            cityLabelStyle.CollisionDetection = true;
            cityLabelLayer.Styles.Add(cityLabelStyle);
            map.Layers.Add(cityLabelLayer);

            //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.
            IStyle min = new Style();
            IStyle max = new Style();
            //Create theme using a density from 0 (min) to 400 (max)
            var 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;
            countryLayer.Styles.Add(popdens);

            //Lets scale the labels so that big countries have larger texts as well
            var lblMin = new LabelStyle();
            var lblMax = new LabelStyle();

            lblMin.ForeColor = Color.Black;
            lblMin.Font      = new Font {
                FontFamily = "Sans Serif", Size = 6
            };
            lblMax.ForeColor = Color.Black;
            lblMax.BackColor = new Brush {
                Color = new Color {
                    A = 128, R = 255, G = 255, B = 255
                }
            };
            lblMin.BackColor = lblMax.BackColor;
            lblMax.Font      = new Font {
                FontFamily = "Sans Serif", Size = 9
            };
            countryLabelLayer.Styles.Add(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
            var          citymin  = new SymbolStyle();
            var          citymax  = new SymbolStyle();
            const 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 {
                Data = new FileStream(iconPath, FileMode.Open, FileAccess.Read)
            };
            citymin.SymbolScale = 0.5f;
            citymax.Symbol      = new Bitmap {
                Data = new FileStream(iconPath, FileMode.Open, FileAccess.Read)
            };
            citymax.SymbolScale = 1f;
            cityLayer.Styles.Add(new GradientTheme("Population", 1000000, 5000000, citymin, citymax));

            var geodanLayer = new Layer("Geodan");

            geodanLayer.DataSource = new MemoryProvider(new Point(4.9130567, 52.3422033));
            geodanLayer.Styles.Add(new SymbolStyle {
                Symbol = new Bitmap {
                    Data = new FileStream(iconPath, FileMode.Open, FileAccess.Read)
                }
            });
            map.Layers.Add(geodanLayer);

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

            return(map);
        }