Exemplo n.º 1
0
        /// <summary>
        /// 应用所选的颜色方案
        /// </summary>
        private void ApplyColorScheme2Categories()
        {
            if (_shapefile.Categories.Count > 0)
            {
                MapWinGIS.ColorScheme scheme = null;
                if (icbCategories.SelectedIndex >= 0)
                {
                    ColorBlend blend = (ColorBlend)icbCategories.ColorSchemes.List[icbCategories.SelectedIndex];
                    scheme = ColorSchemes.ColorBlend2ColorScheme(blend);

                    // saving the settings
                    //MWLite.Symbology.Layer layer = Globals.Legend.Layers.ItemByHandle(_layerHandle);
                    //_settings.CategoriesColorScheme = blend;
                }
                else
                {
                    return;
                }

                if (chkRandomColors.Checked)
                {
                    _shapefile.Categories.ApplyColorScheme(MapWinGIS.tkColorSchemeType.ctSchemeRandom, scheme);
                }
                else
                {
                    _shapefile.Categories.ApplyColorScheme(MapWinGIS.tkColorSchemeType.ctSchemeGraduated, scheme);
                }

                MapWinGIS.ShapefileCategories categories = _shapefile.Categories;
                //绘制catagorise选项
                if (chkSetGradient.Checked)
                {
                    for (int i = 0; i < categories.Count; i++)
                    {
                        ShapeDrawingOptions options = categories.get_Item(i).DrawingOptions;
                        options.SetGradientFill(options.FillColor, 75);
                        options.FillType = tkFillType.ftGradient;
                    }
                }
                else
                {
                    for (int i = 0; i < categories.Count; i++)
                    {
                        ShapeDrawingOptions options = categories.get_Item(i).DrawingOptions;
                        options.FillColor2 = options.FillColor;
                        options.FillType   = tkFillType.ftStandard;
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 为点类别设置具有可变大小的符号
 /// </summary>
 private void ApplyVariablePointSize()
 {
     if (chkUseVariableSize.Checked && (udMinSize.Value != udMaxSize.Value))
     {
         MapWinGIS.ShapefileCategories categories = _shapefile.Categories;
         if (_shapefile.ShapefileType == ShpfileType.SHP_POINT || _shapefile.ShapefileType == ShpfileType.SHP_MULTIPOINT)
         {
             double step = (double)(udMaxSize.Value - udMinSize.Value) / ((double)categories.Count - 1);
             for (int i = 0; i < categories.Count; i++)
             {
                 categories.get_Item(i).DrawingOptions.PointSize = (int)udMinSize.Value + Convert.ToInt32(i * step);
             }
         }
         else if (_shapefile.ShapefileType == ShpfileType.SHP_POLYLINE)
         {
             double step = (double)(udMaxSize.Value + udMinSize.Value) / (double)categories.Count;
             for (int i = 0; i < categories.Count; i++)
             {
                 categories.get_Item(i).DrawingOptions.LineWidth = (int)udMinSize.Value + Convert.ToInt32(i * step);
             }
         }
     }
 }
        /// <summary>
        /// Generates shapefile categories according to specified options
        /// </summary>
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (cboField.SelectedIndex < 0)
            {
                Globals.MessageBoxInformation("No field for generation was selected.");
                this.DialogResult = DialogResult.None;
                return;
            }

            int count;

            if (!Int32.TryParse(cboCategoriesCount.Text, out count))
            {
                Globals.MessageBoxError("Number of categories isn't a valid interger.");
                return;
            }

            MapWinGIS.ShapefileCategories categories = _shapefile.Categories;
            int index = ((ComboItem)cboField.SelectedItem).RealIndex;

            categories.Generate(index, (MapWinGIS.tkClassificationType)cboClassificationType.SelectedIndex, count);

            categories.Caption = "Categories: " + _shapefile.get_Field(index).Name;

            if (chkUseVariableSize.Checked)
            {
                if (_shapefile.ShapefileType == ShpfileType.SHP_POINT || _shapefile.ShapefileType == ShpfileType.SHP_MULTIPOINT)
                {
                    double step = (double)(udMaxSize.Value - udMinSize.Value) / ((double)categories.Count - 1);
                    for (int i = 0; i < categories.Count; i++)
                    {
                        categories.get_Item(i).DrawingOptions.PointSize = (int)udMinSize.Value + Convert.ToInt32(i * step);
                    }
                }
                else if (_shapefile.ShapefileType == ShpfileType.SHP_POLYLINE)
                {
                    double step = (double)(udMaxSize.Value + udMinSize.Value) / (double)categories.Count;
                    for (int i = 0; i < categories.Count; i++)
                    {
                        categories.get_Item(i).DrawingOptions.LineWidth = (int)udMinSize.Value + Convert.ToInt32(i * step);
                    }
                }
            }

            MapWinGIS.ColorScheme scheme = null;
            if (icbColorScheme.SelectedIndex >= 0)
            {
                ColorBlend blend = (ColorBlend)icbColorScheme.ColorSchemes.List[icbColorScheme.SelectedIndex];
                scheme = ColorSchemes.ColorBlend2ColorScheme(blend);
            }

            tkColorSchemeType type = chkRandomColors.Checked ? tkColorSchemeType.ctSchemeRandom : tkColorSchemeType.ctSchemeGraduated;

            _shapefile.Categories.ApplyColorScheme(type, scheme);

            if (chkSetGradient.Checked)
            {
                for (int i = 0; i < categories.Count; i++)
                {
                    ShapeDrawingOptions options = categories.get_Item(i).DrawingOptions;
                    options.SetGradientFill(options.FillColor, 75);
                    options.FillType = tkFillType.ftGradient;
                }
            }

            _shapefile.Categories.ApplyExpressions();

            SaveSettings();
        }
Exemplo n.º 4
0
        private void btnCategoryGenerate_Click(object sender, EventArgs e)
        {
            int count = Convert.ToInt32(udNumCategories.Value);

            MapWinGIS.ShapefileCategories categories = _shapefile.Categories;

            if (lstFields1.SelectedItem == null)
            {
                return;
            }
            string name = lstFields1.SelectedItem.ToString().ToLower().Trim();

            int index = -1;

            for (int i = 0; i < _shapefile.NumFields; i++)
            {
                if (_shapefile.get_Field(i).Name.ToLower() == name)
                {
                    index = i;
                    break;
                }
            }

            if (index == -1)
            {
                return;
            }

            MapWinGIS.tkClassificationType classification = chkUniqueValues.Checked ? tkClassificationType.ctUniqueValues : tkClassificationType.ctNaturalBreaks;

            bool showWaiting = false;

            if (classification == tkClassificationType.ctUniqueValues)
            {
                HashSet <object> set = new HashSet <object>();
                for (int i = 0; i < _shapefile.NumShapes; i++)
                {
                    object val = _shapefile.get_CellValue(index, i);
                    set.Add(val);
                }

                if (set.Count > 300)
                {
                    showWaiting = true;
                    string s = string.Format("字段 = {1}.\n唯一值数量 = {0}.\n" +
                                             "需要加载较长时间.\n是否继续?", set.Count, "[" + name.ToUpper() + "]");
                    if (MessageBox.Show(s, "MapWinGisDemo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                }
                set.Clear();
            }

            if (showWaiting)
            {
                this.Enabled = false;
                this.Cursor  = Cursors.WaitCursor;
            }
            else
            {
                btnCategoryGenerate.Enabled = false;
            }

            // 生成目录
            categories.Generate(index, classification, count);
            categories.Caption = "Categories: " + _shapefile.get_Field(index).Name;
            ApplyColorScheme2Categories();

            if (chkUseVariableSize.Checked)
            {
                ApplyVariablePointSize();
            }

            _shapefile.Categories.ApplyExpressions();



            RefreshCategoriesList();
            RedrawMap();

            // 保存设置

            _settings.CategoriesClassification = classification;
            _settings.CategoriesFieldName      = name;
            _settings.CategoriesSizeRange      = (int)(udMaxSize.Value - udMinSize.Value);
            _settings.CategoriesCount          = (int)udNumCategories.Value;
            _settings.CategoriesRandomColors   = chkRandomColors.Checked;
            _settings.CategoriesUseGradient    = chkSetGradient.Checked;
            _settings.CategoriesVariableSize   = chkUseVariableSize.Checked;


            if (showWaiting)
            {
                this.Enabled = true;
                this.Cursor  = Cursors.Default;
            }
            else
            {
                btnCategoryGenerate.Enabled = true;
            }

            RefreshControlsState(null, null);
            MarkStateChanged();
        }
Exemplo n.º 5
0
        protected internal int CalcHeight(bool UseExpandedHeight)
        {
            // to affect drawing of the expansion box externally
            if (m_Expanded && ExpansionBoxCustomHeightFunction != null)
            {
                int  ht      = Constants.ITEM_HEIGHT;
                bool Handled = false;
                ExpansionBoxCustomHeightFunction(m_Handle, m_Legend.Width, ref ht, ref Handled);
                if (Handled)
                {
                    return(ht + Constants.ITEM_HEIGHT + Constants.EXPAND_BOX_TOP_PAD * 2);
                }
                else
                {
                    return(Constants.ITEM_HEIGHT);
                }
            }

            int ret = 0;

            if (this.Type == eLayerType.Grid || this.Type == eLayerType.Image)
            {
                if (UseExpandedHeight == false && (m_Expanded == false || ColorLegend.Count == 0)) //|| (this.Type == eLayerType.Image))
                {
                    ret = Constants.ITEM_HEIGHT;
                }
                else
                {
                    ret = Constants.ITEM_HEIGHT + (ColorLegend.Count * Constants.CS_ITEM_HEIGHT) + 2;
                }


                if (UseExpandedHeight || m_Expanded)
                {
                    ret += (ColorSchemeFieldCaption.Trim() != "" ? Constants.CS_ITEM_HEIGHT : 0) + (StippleSchemeFieldCaption.Trim() != "" ? Constants.CS_ITEM_HEIGHT : 0);
                }
            }
            else
            {
                var sf = m_Legend.m_Map.get_Shapefile(this.Handle);

                if ((UseExpandedHeight || m_Expanded) && sf != null)
                {
                    ret = Constants.ITEM_HEIGHT + 2;                            // 图层名


                    int val1, val2;
                    val1 = (GetCategoryHeight(sf.DefaultDrawingOptions) + 2);  // 默认图例

                    if (sf.Labels.Count == 0 || sf.Labels.Visible == false || true)
                    {
                        ret += val1;
                    }
                    else
                    {
                        LabelStyle            style = new LabelStyle(sf.Labels.Options);
                        System.Drawing.Bitmap img   = new System.Drawing.Bitmap(500, 200);
                        Graphics g    = Graphics.FromImage(img);
                        Size     size = style.MeasureString(g, "String", 30);
                        val2 = size.Height + 2;
                        ret += val1 > val2 ? val1 : val2;
                    }

                    if (sf.Categories.Count > 0)
                    {
                        ret += Constants.CS_ITEM_HEIGHT + 2;   // 标题

                        MapWinGIS.ShapefileCategories categories = sf.Categories;
                        if (this.Type == eLayerType.LineShapefile || this.Type == eLayerType.PolygonShapefile)
                        {
                            ret += sf.Categories.Count * (Constants.CS_ITEM_HEIGHT + 2);
                        }
                        else
                        {
                            for (int i = 0; i < sf.Categories.Count; i++)
                            {
                                ret += GetCategoryHeight(categories.get_Item(i).DrawingOptions);
                            }
                        }
                        ret += 2;
                    }

                    if (sf.Charts.Count > 0 && sf.Charts.NumFields > 0 && sf.Charts.Visible)
                    {
                        ret += (Constants.CS_ITEM_HEIGHT + 2);   // 标题
                        ret += sf.Charts.IconHeight;
                        ret += 2;

                        ret += (sf.Charts.NumFields * (Constants.CS_ITEM_HEIGHT + 2));
                    }
                }
                else
                {
                    ret = Constants.ITEM_HEIGHT;
                }

                // TODO: 标题宽度
                //if (UseExpandedHeight || m_Expanded)
                //    ret += (ColorSchemeFieldCaption.Trim() != "" ? Constants.CS_ITEM_HEIGHT : 0) + (StippleSchemeFieldCaption.Trim() != "" ? Constants.CS_ITEM_HEIGHT : 0);
            }

            m_height = ret;

            return(ret);
        }