/// <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; } } } }
private void UpdateFieldColors() { List <ColorBlend> schemes = icbColors.ColorSchemes.List; if (schemes != null && icbColors.SelectedIndex >= 0) { ColorBlend blend = (ColorBlend)schemes[icbColors.SelectedIndex]; MapWinGIS.ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend); if (scheme != null) { for (int i = 0; i < _charts.NumFields; i++) { MapWinGIS.ChartField field = _charts.get_Field(i); double value = (double)(i) / (double)(_charts.NumFields - 1); field.Color = scheme.get_GraduatedColor(value); } } } }
/// <summary> /// Converts color blend to MapWinGis color scheme /// </summary> public static MapWinGIS.ColorScheme ColorBlend2ColorScheme(ColorBlend blend) { if (blend == null) { return(null); } if (blend.Positions.Length == 0 || (blend.Positions.Length != blend.Colors.Length)) { return(null); } MapWinGIS.ColorScheme scheme = new MapWinGIS.ColorScheme(); for (int i = 0; i < blend.Positions.Length; i++) { scheme.AddBreak((double)blend.Positions[i], Colors.ColorToUInteger(blend.Colors[i])); } return(scheme); }
/// <summary> /// Converts MapWinGis color scheme to color blend /// </summary> public static ColorBlend ColorScheme2ColorBlend(MapWinGIS.ColorScheme scheme) { if (scheme == null) { return(null); } if (scheme.NumBreaks == 0) { return(null); } ColorBlend blend = new ColorBlend(scheme.NumBreaks); for (int i = 0; i < scheme.NumBreaks; i++) { blend.Positions[i] = (float)scheme.get_BreakValue(i); uint color = scheme.get_BreakColor(i); blend.Colors[i] = Colors.UintToColor(color); } return(blend); }
/// <summary> /// Fills the image list with icons according to the selected colors /// </summary> public void RefreshImageList() { if (m_style == ImageComboStyle.Common) { return; } m_list.Images.Clear(); int width; if (m_style == ImageComboStyle.PointShape) { width = 20; } else if (m_style == ImageComboStyle.ColorSchemeGraduated || m_style == ImageComboStyle.ColorSchemeRandom) { width = this.Width - 24; } else { width = 64; } Size sz = new Size(width, 16); m_list.ImageSize = sz; int _imgHeight = m_list.ImageSize.Height; int _imgWidth = m_list.ImageSize.Width; Rectangle rect = new Rectangle(m_paddX, m_paddY, _imgWidth - 1 - m_paddX * 2, _imgHeight - 1 - m_paddY * 2); Color foreColor = this.Enabled ? Color.Black : Color.Gray; for (int i = 0; i < _itemCount; i++) { Bitmap img = new Bitmap(_imgWidth, _imgHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(img); switch (m_style) { // frame type combo case ImageComboStyle.FrameType: { if (i == 0) { g.FillRectangle(new SolidBrush(_color1), rect); g.DrawRectangle(new Pen(foreColor), rect); } else if (i == 1) { g.FillEllipse(new SolidBrush(_color1), rect); g.DrawEllipse(new Pen(foreColor), rect); } else if (i == 2) { float left = rect.X; float right = rect.X + rect.Width; float top = rect.Y; float bottom = rect.Y + rect.Height; GraphicsPath path = new GraphicsPath(); path.StartFigure(); path.AddLine(left + (rect.Height / 4), top, right - (rect.Height / 4), top); path.AddLine(right - (rect.Height / 4), top, right, (top + bottom) / 2); path.AddLine(right, (top + bottom) / 2, right - (rect.Height / 4), bottom); path.AddLine(right - (rect.Height / 4), bottom, left + (rect.Height / 4), bottom); path.AddLine(left + (rect.Height / 4), bottom, left, (top + bottom) / 2); path.AddLine(left, (top + bottom) / 2, left + (rect.Height / 4), top); path.CloseFigure(); g.FillPath(new SolidBrush(_color1), path); g.DrawPath(new Pen(foreColor), path); path.Dispose(); break; } break; } // linear gradient combo case ImageComboStyle.LinearGradient: { if ((tkLinearGradientMode)i == tkLinearGradientMode.gmNone) { g.FillRectangle(new SolidBrush(_color1), rect); g.DrawRectangle(new Pen(_outlineColor), rect); } else { LinearGradientBrush lgb = new LinearGradientBrush(rect, _color1, _color2, (LinearGradientMode)i); g.FillRectangle(lgb, rect); g.DrawRectangle(new Pen(_outlineColor), rect); lgb.Dispose(); } break; } // line style combo case ImageComboStyle.LineStyle: { Pen pen = new Pen(_outlineColor); pen.DashStyle = (DashStyle)i; pen.Width = 2; g.DrawLine(pen, new System.Drawing.Point(rect.Left, rect.Top + rect.Height / 2), new System.Drawing.Point(rect.Right, rect.Top + rect.Height / 2)); break; } // line width combo case ImageComboStyle.LineWidth: { Pen pen = new Pen(_outlineColor); pen.Width = i + 1; g.DrawLine(pen, new System.Drawing.Point(rect.Left, rect.Top + rect.Height / 2), new System.Drawing.Point(rect.Right, rect.Top + rect.Height / 2)); break; } case ImageComboStyle.PointShape: { ShapeDrawingOptions sdo = new ShapeDrawingOptions(); sdo.FillColor = Colors.ColorToUInteger(this._color1); sdo.LineColor = Colors.ColorToUInteger(this._outlineColor); sdo.PointShape = (tkPointShapeType)i; sdo.PointType = tkPointSymbolType.ptSymbolStandard; sdo.PointSize = 12; if (sdo.PointShape == tkPointShapeType.ptShapeStar) { sdo.PointSidesCount = 5; sdo.PointRotation = 17; sdo.PointSize = 14; } else if (sdo.PointShape == tkPointShapeType.ptShapeArrow) { sdo.PointSize = 14; sdo.PointRotation = 0; } else { sdo.PointSidesCount = 4; sdo.PointRotation = 0; sdo.PointSize = 12; } IntPtr ptr = g.GetHdc(); sdo.DrawPoint(ptr, 0.0f, 0.0f, _imgWidth, _imgHeight, Colors.ColorToUInteger(this.BackColor)); g.ReleaseHdc(ptr); break; } case ImageComboStyle.HatchStyle: { HatchBrush br = new HatchBrush((HatchStyle)i, _color1, Color.Transparent); g.FillRectangle(br, rect); g.DrawRectangle(new Pen(_outlineColor), rect); br.Dispose(); break; } case ImageComboStyle.HatchStyleWithNone: { if (i == 0) { g.FillRectangle(new SolidBrush(_color1), rect); g.DrawRectangle(new Pen(_outlineColor), rect); } else { HatchBrush br = new HatchBrush((HatchStyle)(i - 1), _color1, Color.Transparent); g.FillRectangle(br, rect); g.DrawRectangle(new Pen(_outlineColor), rect); br.Dispose(); } break; } case ImageComboStyle.ColorSchemeGraduated: { if (_colorSchemes != null) { ColorBlend blend = (_colorSchemes.List[i] as ColorBlend); if (blend != null) { LinearGradientBrush lgb = new LinearGradientBrush(rect, Color.White, Color.White, 0.0f); lgb.InterpolationColors = blend; g.FillRectangle(lgb, rect); g.DrawRectangle(new Pen(_outlineColor), rect); lgb.Dispose(); break; } } break; } case ImageComboStyle.ColorSchemeRandom: { if (_colorSchemes != null) { ColorBlend blend = (_colorSchemes.List[i] as ColorBlend); if (blend != null) { MapWinGIS.ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend); if (scheme != null) { int n = 0; Random rnd = new Random(); while (n < _imgWidth) { Color clr = Colors.UintToColor(scheme.get_RandomColor(rnd.NextDouble())); SolidBrush brush = new SolidBrush(clr); Rectangle rectTemp = new Rectangle(rect.X + n, rect.Y, 8, rect.Height); g.FillRectangle(brush, rectTemp); g.DrawRectangle(new Pen(_outlineColor), rectTemp); brush.Dispose(); n += 8; } } } } break; } default: return; } // adding an image m_list.Images.Add(img); } }
/// <summary> /// Generation of labels categories /// </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 = 0; if (!Int32.TryParse(cboCategoriesCount.Text, out count)) { Globals.MessageBoxInformation("The entered categories count isn't a number"); this.DialogResult = DialogResult.None; return; } string fieldName = cboField.SelectedItem.ToString(); int index = -1; for (int i = 0; i < m_shapefile.NumFields; i++) { if (m_shapefile.get_Field(i).Name == fieldName) { index = i; break; } } if (index == -1) { return; } m_shapefile.Labels.GenerateCategories(index, (MapWinGIS.tkClassificationType)cboClassificationType.SelectedIndex, count); if (chkUseVariableSize.Checked) { int numCategories = m_shapefile.Labels.NumCategories; double step = (double)(udMaxSize.Value - udMinSize.Value) / ((double)numCategories - 1); for (int i = 0; i < numCategories; i++) { m_shapefile.Labels.get_Category(i).FontSize = (int)udMinSize.Value + Convert.ToInt32(i * step); } } if (chkGraduatedFrame.Checked) { ColorBlend blend = (ColorBlend)icbFrame.ColorSchemes.List[icbFrame.SelectedIndex]; MapWinGIS.ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend); tkColorSchemeType type = chkRandomColors.Checked ? tkColorSchemeType.ctSchemeRandom : tkColorSchemeType.ctSchemeGraduated; m_shapefile.Labels.ApplyColorScheme2(type, scheme, tkLabelElements.leFrameBackground); } for (int i = 0; i < m_shapefile.Labels.NumCategories; i++) { m_shapefile.Labels.get_Category(i).FrameVisible = chkGraduatedFrame.Checked; } m_shapefile.Labels.ApplyCategories(); SaveSettings(); }
/// <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(); }