private void B_NewLegend_Click(object sender, EventArgs e)
        {
            m_Interval        = Convert.ToDouble(TB_Interval.Text);
            m_MinContourValue = Convert.ToDouble(TB_SValue.Text);
            m_MaxContourValue = Convert.ToDouble(TB_EValue.Text);
            //if (m_MinContourValue < _legendScheme.MinValue ||
            //    m_MaxContourValue > _legendScheme.MaxValue)
            //{
            //    MessageBox.Show("Please reset the data!", "Error");
            //    return;
            //}
            if ((int)((m_MaxContourValue - m_MinContourValue) / m_Interval) < 2)
            {
                MessageBox.Show("Please reset the data!", "Error");
                return;
            }

            double[] cValues;
            cValues = LegendManage.CreateContourValuesInterval(m_MinContourValue, m_MaxContourValue,
                                                               m_Interval);

            Color[] colors = CreateColors(cValues.Length + 1);

            LegendScheme aLS;

            if (_isUniqueValue)
            {
                aLS = LegendManage.CreateUniqValueLegendScheme(cValues, colors, _legendScheme.ShapeType,
                                                               _legendScheme.MinValue, _legendScheme.MaxValue, _legendScheme.HasNoData, _legendScheme.MissingValue);
            }
            else
            {
                aLS = LegendManage.CreateGraduatedLegendScheme(cValues, colors, _legendScheme.ShapeType,
                                                               _legendScheme.MinValue, _legendScheme.MaxValue, _legendScheme.HasNoData,
                                                               _legendScheme.MissingValue);
            }
            aLS.FieldName = _legendScheme.FieldName;
            SetLegendScheme(aLS);

            if (_parent.GetType() == typeof(frmLegendSet))
            {
                ((frmLegendSet)_parent).SetLegendScheme(aLS);
                ((frmLegendSet)_parent).legendView1.Update(aLS);
            }
            else if (_parent.GetType() == typeof(LegendSchemeControl))
            {
                ((LegendSchemeControl)_parent).SetLegendScheme(aLS);
                ((LegendSchemeControl)_parent).legendView1.Update(aLS);
            }
        }
        private Color[] CreateColors(int colorNum)
        {
            Color[] colors;

            if (RB_RainbowColors.Checked)
            {
                colors = LegendManage.CreateRainBowColors(colorNum);
            }
            else
            {
                colors = LegendManage.CreateColors(Lab_StartColor.BackColor, Lab_EndColor.BackColor,
                                                   colorNum);
            }

            return(colors);
        }
Ejemplo n.º 3
0
        private void CreateLegendScheme(LegendType aLT, string fieldName)
        {
            if (_ifCreateLegendScheme)
            {
                double     min, max;
                ShapeTypes aST = _legendScheme.ShapeType;

                min = _legendScheme.MinValue;
                max = _legendScheme.MaxValue;
                switch (aLT)
                {
                case LegendType.SingleSymbol:
                    Color aColor = Color.Black;
                    switch (aST)
                    {
                    case ShapeTypes.Point:
                        aColor = Color.Black;
                        break;

                    case ShapeTypes.Polyline:
                    case ShapeTypes.PolylineZ:
                        aColor = Color.Black;
                        break;

                    case ShapeTypes.Polygon:
                    case ShapeTypes.Image:
                        aColor = Color.FromArgb(255, 251, 195);
                        break;
                    }
                    Single size = 0.1F;
                    if (_legendScheme.ShapeType == ShapeTypes.Point)
                    {
                        size = 5;
                    }
                    _legendScheme = LegendManage.CreateSingleSymbolLegendScheme(_legendScheme.ShapeType, aColor,
                                                                                size);

                    TSB_Add.Enabled        = false;
                    TSB_Del.Enabled        = false;
                    TSB_DelAll.Enabled     = false;
                    TSB_Down.Enabled       = false;
                    TSB_Up.Enabled         = false;
                    TSB_MakeBreaks.Enabled = false;
                    TSB_Reverse.Enabled    = false;
                    break;

                case LegendType.UniqueValue:
                    Color[]       colors;
                    List <string> valueList = new List <string>();

                    VectorLayer aLayer      = (VectorLayer)_mapLayer;
                    bool        isDateField = false;
                    Type        colType     = aLayer.AttributeTable.Table.Columns[fieldName].DataType;
                    if (colType == typeof(DateTime))
                    {
                        isDateField = true;
                    }

                    List <string> captions = new List <string>();

                    for (int i = 0; i < aLayer.AttributeTable.Table.Rows.Count; i++)
                    {
                        if (!valueList.Contains(aLayer.AttributeTable.Table.Rows[i][fieldName].ToString()))
                        {
                            valueList.Add(aLayer.AttributeTable.Table.Rows[i][fieldName].ToString());
                            if (isDateField)
                            {
                                captions.Add(((DateTime)aLayer.AttributeTable.Table.Rows[i][fieldName]).ToString("yyyy/M/d"));
                            }
                        }
                    }

                    if (valueList.Count == 1)
                    {
                        MessageBox.Show("The values of all shapes are same!", "Alarm");
                        break;
                    }

                    if (valueList.Count <= 13)
                    {
                        colors = LegendManage.CreateRainBowColors(valueList.Count);
                    }
                    else
                    {
                        colors = LegendManage.CreateRandomColors(valueList.Count);
                    }
                    List <Color> CList = new List <Color>(colors);
                    CList.Insert(0, Color.White);
                    colors = CList.ToArray();

                    if (isDateField)
                    {
                        _legendScheme = LegendManage.CreateUniqValueLegendScheme(valueList, captions, colors, aST, min,
                                                                                 max, _legendScheme.HasNoData, _legendScheme.MissingValue);
                    }
                    else
                    {
                        _legendScheme = LegendManage.CreateUniqValueLegendScheme(valueList, colors,
                                                                                 aST, min, max, _legendScheme.HasNoData, _legendScheme.MissingValue);
                    }

                    _legendScheme.FieldName = fieldName;

                    TSB_Add.Enabled        = true;
                    TSB_Del.Enabled        = true;
                    TSB_DelAll.Enabled     = true;
                    TSB_Down.Enabled       = true;
                    TSB_Up.Enabled         = true;
                    TSB_MakeBreaks.Enabled = true;
                    TSB_Reverse.Enabled    = true;
                    break;

                case LegendType.GraduatedColor:
                    aLayer = (VectorLayer)_mapLayer;
                    double[] S = new double[aLayer.AttributeTable.Table.Rows.Count];
                    for (int i = 0; i < S.Length; i++)
                    {
                        S[i] = double.Parse(aLayer.AttributeTable.Table.Rows[i][fieldName].ToString());
                    }
                    MIMath.GetMaxMinValue(S, _legendScheme.MissingValue, ref min, ref max);


                    if (min == max)
                    {
                        MessageBox.Show("The values of all shapes are same!", "Alarm");
                        break;
                    }

                    double[] CValues;
                    CValues = LegendManage.CreateContourValues(min, max);
                    colors  = LegendManage.CreateRainBowColors(CValues.Length + 1);

                    _legendScheme = LegendManage.CreateGraduatedLegendScheme(CValues, colors,
                                                                             aST, min, max, _legendScheme.HasNoData, _legendScheme.MissingValue);
                    _legendScheme.FieldName = fieldName;

                    TSB_Add.Enabled        = true;
                    TSB_Del.Enabled        = true;
                    TSB_DelAll.Enabled     = true;
                    TSB_Down.Enabled       = true;
                    TSB_Up.Enabled         = true;
                    TSB_MakeBreaks.Enabled = true;
                    TSB_Reverse.Enabled    = true;
                    break;
                }

                //ShowLegendScheme(_legendScheme);
                //DataGridView1.Refresh();
                legendView1.LegendScheme = _legendScheme;
                legendView1.Invalidate();
            }
        }