Beispiel #1
0
        /// <summary>
        /// Static constructor for Globals class
        /// </summary>
        static Globals()
        {
            LayerColors = new ColorSchemes(ColorSchemeType.Layer);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(Properties.Resources.colorschemes);
            LayerColors.LoadXML(doc);
        }
        /// <summary>
        /// Generate label categories for the given set of shapefile categories
        /// </summary>
        /// <param name="mapWin">The reference to MapWindow</param>
        /// <param name="layerHandle">The handle of the layer</param>
        internal static void GenerateCategories(LegendControl.Legend legend, int layerHandle)
        {
            Layer     lyr = legend.GetLayer(layerHandle);
            Shapefile sf  = lyr.GetObject() as MapWinGIS.Shapefile;
            Labels    lb  = sf.Labels;

            sf.Labels.ClearCategories();
            for (int i = 0; i < sf.Categories.Count; i++)
            {
                ShapefileCategory cat      = sf.Categories.get_Item(i);
                LabelCategory     labelCat = lb.AddCategory(cat.Name);
                labelCat.Expression = cat.Expression;
            }

            SymbologySettings settings = Globals.get_LayerSettings(layerHandle);
            ColorBlend        blend    = (ColorBlend)settings.LabelsScheme;

            if (blend != null)
            {
                ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend);
                if (settings.LabelsRandomColors)
                {
                    lb.ApplyColorScheme(tkColorSchemeType.ctSchemeRandom, scheme);
                }
                else
                {
                    lb.ApplyColorScheme(tkColorSchemeType.ctSchemeGraduated, scheme);
                }
            }

            if (settings.LabelsVariableSize)
            {
                for (int i = 0; i < lb.NumCategories; i++)
                {
                    lb.get_Category(i).FontSize = (int)((double)sf.Labels.FontSize +
                                                        (double)settings.LabelsSizeRange / ((double)lb.NumCategories - 1) * (double)i);
                }
            }

            // Expressions aren't supported by labels yet, therefore we need to copy indices from the symbology
            for (int i = 0; i < lb.Count; i++)
            {
                MapWinGIS.Label label = lb.get_Label(i, 0);
                label.Category = sf.get_ShapeCategory(i);
            }
        }
        /// <summary>
        /// Reads the list of color schemes
        /// </summary>
        public void ReadFromXML()
        {
            this.List.Clear();

            XmlDocument xmlDoc   = new XmlDocument();
            string      filename = this.GetFilename();

            // reading from the file
            if (System.IO.File.Exists(filename))
            {
                xmlDoc.Load(filename);
                this.LoadXML(xmlDoc);
            }

            // creating default ones
            if (this.List.Count == 0)
            {
                ColorBlend blend = null;
                if (_type == ColorSchemeType.Layer)
                {
                    // dummy single color blend must be always the first for shapefile
                    blend           = new ColorBlend(2);
                    blend.Colors[0] = Color.White; blend.Positions[0] = 0.0f;
                    blend.Colors[1] = Color.White; blend.Positions[1] = 1.0f;
                    this.List.Add(blend);

                    blend           = new ColorBlend(2);
                    blend.Colors[0] = Color.LightBlue; blend.Positions[0] = 0.0f;
                    blend.Colors[1] = Color.Orange; blend.Positions[1] = 1.0f;
                    this.List.Add(blend);

                    blend           = new ColorBlend(2);
                    blend.Colors[0] = Color.Yellow; blend.Positions[0] = 0.0f;
                    blend.Colors[1] = Color.Orange; blend.Positions[1] = 1.0f;
                    this.List.Add(blend);

                    for (int i = 0; i < 2; i++)
                    {
                        MapWinGIS.ColorScheme sch = new ColorScheme();
                        if (i == 0)
                        {
                            sch.SetColors4(PredefinedColorScheme.FallLeaves);
                        }
                        if (i == 1)
                        {
                            sch.SetColors4(PredefinedColorScheme.DeadSea);
                        }
                        blend = ColorSchemes.ColorScheme2ColorBlend(sch);
                        this.List.Add(blend);
                    }

                    // adding to 2 color schemes, as there can be none in the list
                    blend           = new ColorBlend(7);
                    blend.Colors[0] = Color.Red; blend.Positions[0] = 0.0f;
                    blend.Colors[1] = Color.Orange; blend.Positions[1] = 1.0f / 6.0f;
                    blend.Colors[2] = Color.Yellow; blend.Positions[2] = 2.0f / 6.0f;
                    blend.Colors[3] = Color.LightGreen; blend.Positions[3] = 3.0f / 6.0f;
                    blend.Colors[4] = Color.LightBlue; blend.Positions[4] = 4.0f / 6.0f;
                    blend.Colors[5] = Color.Blue; blend.Positions[5] = 5.0f / 6.0f;
                    blend.Colors[6] = Color.BlueViolet; blend.Positions[6] = 1.0f;
                    this.List.Add(blend);

                    blend           = new ColorBlend(2);
                    blend.Colors[0] = Color.LightGray; blend.Positions[0] = 0.0f;
                    blend.Colors[1] = Color.Gray; blend.Positions[1] = 1.0f;
                    this.List.Add(blend);

                    blend           = new ColorBlend(2);
                    blend.Colors[0] = Color.Pink; blend.Positions[0] = 0.0f;
                    blend.Colors[1] = Color.LightYellow; blend.Positions[1] = 1.0f;
                    this.List.Add(blend);
                }
                else if (_type == ColorSchemeType.Charts)
                {
                    blend           = new ColorBlend(2);
                    blend.Colors[0] = Color.Yellow; blend.Positions[0] = 0.0f;
                    blend.Colors[1] = Color.Orange; blend.Positions[1] = 1.0f;
                    this.List.Add(blend);

                    blend           = new ColorBlend(2);
                    blend.Colors[0] = Color.LightBlue; blend.Positions[0] = 0.0f;
                    blend.Colors[1] = Color.Pink; blend.Positions[1] = 1.0f;
                    this.List.Add(blend);

                    blend           = new ColorBlend(2);
                    blend.Colors[0] = Color.LightGreen; blend.Positions[0] = 0.0f;
                    blend.Colors[1] = Color.Yellow; blend.Positions[1] = 1.0f;
                    this.List.Add(blend);
                }
            }
        }