public void NotNullProps_WhenCtor() { var target = new LabelCategory(); Assert.IsNotNull(target.SelectionSymbolizer); Assert.IsNotNull(target.Symbolizer); Assert.IsNotNull(target.ToString()); }
public void SetLabel(LabelCategory label) { composePage.Optionbtn.Click(); composePage.LabelOption.Click(); composePage.LabelSearchtb.WaitForElement(Enum.WaitForElement.Avg); Thread.Sleep(2000); switch (label) { case LabelCategory.Social: composePage.LabelSearchtb.SetText(LabelCategory.Social.ToString()); composePage.LabelSocialCombobox.Click(); break; case LabelCategory.Forums: composePage.LabelSearchtb.SetText(LabelCategory.Forums.ToString()); composePage.LabelForumsCombobox.Click(); break; case LabelCategory.Promotions: composePage.LabelSearchtb.SetText(LabelCategory.Promotions.ToString()); composePage.LabelPromotionsCombobox.Click(); break; case LabelCategory.Updates: composePage.LabelSearchtb.SetText(LabelCategory.Updates.ToString()); composePage.LabelUpdatesCombobox.Click(); break; default: break; } //SendKeys.SendWait(@"{Enter}"); Thread.Sleep(500); }
/// <summary> /// This activates the labels for the specified feature layer that will be the specified expression /// where field names are in square brackets like "[Name]: [Value]". This will label all the features, /// and remove any previous labeling. /// </summary> /// <param name="featureLayer">The FeatureLayer to apply the labels to.</param> /// <param name="expression">The string label expression to use where field names are in square brackets like /// [Name].</param> /// <param name="font">The font to use for these labels.</param> /// <param name="fontColor">The color for the labels.</param> /// <exception cref="ArgumentNullException"><paramref name="featureLayer"/> must be not null.</exception> public static void AddLabels(this IFeatureLayer featureLayer, string expression, Font font, Color fontColor) { if (featureLayer == null) { throw new ArgumentNullException(nameof(featureLayer)); } featureLayer.ShowLabels = true; var ll = new MapLabelLayer(); ll.Symbology.Categories.Clear(); var lc = new LabelCategory { Expression = expression }; ll.Symbology.Categories.Add(lc); var ls = ll.Symbolizer; ls.Orientation = ContentAlignment.MiddleCenter; ls.FontColor = fontColor; ls.FontFamily = font.FontFamily.ToString(); ls.FontSize = font.Size; ls.FontStyle = font.Style; ls.PartsLabelingMethod = PartLabelingMethod.LabelLargestPart; featureLayer.LabelLayer = ll; }
internal LabelStyle(LabelCategory category) { _category = category; if (category == null) { throw new NullReferenceException("Internal reference is null"); } }
//LabelCategoryClass继承自LabelCategory、ILabelCategory public LabelStyle(LabelCategory cat) { PropertyInfo[] props = cat.GetType().GetProperties(); //类型+ 名称 foreach (PropertyInfo prop in props) { PropertyInfo propDest = this.GetType().GetProperty(prop.Name); propDest.SetValue(this, prop.GetValue(cat, null), null); } }
private void axMap1_MouseMoveEvent(object sender, _DMapEvents_MouseMoveEvent e) { #region 原版添加标签 if (sfMouseMove != null) { foreach (Shapefile sf in sfMouseMove.Values) { labels = sf.Labels; labels.FontSize = 15; labels.FontBold = true; labels.FrameVisible = true; labels.FrameType = tkLabelFrameType.lfRectangle; labels.AutoOffset = false; labels.OffsetX = 40; LabelCategory cat = labels.AddCategory("Red"); cat.FontColor = 255; double projX = 0.0; double projY = 0.0; Map.PixelToProj(e.x, e.y, ref projX, ref projY); object result = null; var ext = new Extents(); ext.SetBounds(projX, projY, 0.0, projX, projY, 0.0); if (sf.SelectShapes(ext, 0.00007, SelectMode.INTERSECTION, ref result)) { if (labelFlag_MouseMove == 0) { mouseMoveOperate(result, sf, labels, projX, projY); Map.Redraw(); movemoveenter++; string tStr = "aaa:" + movemoveenter; int str = labels.Count; Debug.Print("labels:" + str); labelFlag_MouseMove = 1; } } else { if (labelFlag_MouseMove == 1) { sf.Labels.Clear(); labelFlag_MouseMove = 0; Map.Redraw(); movemoveenter++; string tStr = "bbb:" + movemoveenter; int str = labels.Count; Debug.Print("labels:" + str); } } } } #endregion }
/// <summary> /// Draws preview based on the specified expression string /// </summary> internal static void DrawPreview(LabelCategory category, MapWinGIS.Shapefile sf, System.Windows.Forms.PictureBox canvas, string expression, bool forceDrawing) { // retrieving text string s = get_LabelText(sf, expression); if (s.Trim() == string.Empty) { s = ""; } Bitmap img = new Bitmap(canvas.ClientRectangle.Width, canvas.ClientRectangle.Height); Graphics g = Graphics.FromImage(img); //const int count = 50; //Pen gridPen = new Pen(Color.LightGray); //float step = (float)img.Height/count; //for (int i = 0; i < count; i++) //{ // g.DrawLine(gridPen, 0.0f, step * (float)i, (float)img.Width, step * (float)i); //} //step = (float)img.Width / count; //for (int j = 0; j < count; j++) //{ // g.DrawLine(gridPen, step * (float)j, 0.0f, step * (float)j, (float)img.Height); //} System.Drawing.Point pntOrigin = new System.Drawing.Point((canvas.ClientRectangle.Right + canvas.ClientRectangle.Left) / 2, (canvas.ClientRectangle.Bottom + canvas.ClientRectangle.Top) / 2); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; // drawing the label LabelStyle style = new LabelStyle(category); if (sf.Labels.Count > 0 || forceDrawing) { // drawing base point Pen pen = new Pen(Color.Black, 2); Rectangle rect = new Rectangle((int)pntOrigin.X, (int)pntOrigin.Y, 2, 2); //g.DrawEllipse(pen, rect); pen.Dispose(); style.Draw(g, pntOrigin, s, true, 0); } if (canvas.Image != null) { canvas.Image.Dispose(); } canvas.Image = img; }
void ReleaseDesignerOutlets() { if (LabelCategory != null) { LabelCategory.Dispose(); LabelCategory = null; } if (LabelName != null) { LabelName.Dispose(); LabelName = null; } }
// <summary> // Adds randomly positioned labels to the image layer. // </summary> public void ImageLabels(AxMap axMap1) { axMap1.Projection = tkMapProjection.PROJECTION_NONE; axMap1.GrabProjectionFromData = true; Image img = new Image(); OpenFileDialog dlg = new OpenFileDialog { Filter = img.CdlgFilter }; if (dlg.ShowDialog() == DialogResult.OK) { img.Open(dlg.FileName, ImageType.USE_FILE_EXTENSION, false, null); axMap1.AddLayer(img, true); Labels lbl = img.Labels; lbl.FontSize = 12; lbl.FontBold = true; lbl.FontOutlineVisible = true; lbl.FontOutlineColor = (255 << 16) + (255 << 8) + 255; //white lbl.FontOutlineWidth = 4; LabelCategory cat = lbl.AddCategory("Red"); cat.FontColor = 255; cat = lbl.AddCategory("Blue"); cat.FontColor = 255 << 16; cat = lbl.AddCategory("Yellow"); cat.FontColor = 255 + 255 << 8; Extents ext = img.Extents; double xRange = ext.xMax - ext.xMin; double yRange = ext.yMax - ext.yMin; Random rnd = new Random(); for (int i = 0; i < 100; i++) { double x = xRange * rnd.NextDouble(); double y = yRange * rnd.NextDouble(); int categoryIndex = i % 3; lbl.AddLabel("label" + Convert.ToString(i), ext.xMin + x, ext.yMin + y, i * 3.6, categoryIndex); } axMap1.Redraw(); } }
void MapMouseMoveEvent(object sender, _DMapEvents_MouseMoveEvent e) { #region 单重显示 Shapefile sf = App.Map.get_Shapefile(1); if (sf != null) { Labels labels = sf.Labels; labels.FontSize = 15; labels.FontBold = true; labels.FrameVisible = true; labels.FrameType = tkLabelFrameType.lfRectangle; labels.AutoOffset = false; labels.OffsetX = 40; LabelCategory cat = labels.AddCategory("Red"); cat.FontColor = 255; double projX = 0.0; double projY = 0.0; App.Map.PixelToProj(e.x, e.y, ref projX, ref projY); object result = null; var ext = new Extents(); ext.SetBounds(projX, projY, 0.0, projX, projY, 0.0); if (sf.SelectShapes(ext, 0.00005, SelectMode.INTERSECTION, ref result) && (p == 0)) { //string temp = GisPoint.readOneData(projX, projY); //string tempx = temp + "℃"; //if(Convert.ToDouble(temp)>=50) //{ // labels.AddLabel(tempx, projX, projY, 0.0, 0); //} //else //{ // labels.AddLabel(tempx, projX, projY, 0.0, -1); //} //p = 1; } else { sf.Labels.Clear(); p = 0; } App.Map.Redraw(); } #endregion }
private void axMap1_MouseDownEvent(object sender, _DMapEvents_MouseDownEvent e) { if (sfMouseDown != null) { foreach (Shapefile sf in sfMouseDown.Values) { if (sf != null) { Labels labels = sf.Labels; labels.FontSize = 15; labels.FontBold = true; labels.FrameVisible = true; labels.FrameType = tkLabelFrameType.lfRectangle; labels.AutoOffset = false; labels.OffsetX = 40; LabelCategory cat = labels.AddCategory("Red"); cat.FontColor = 255; double projX = 0.0; double projY = 0.0; Map.PixelToProj(e.x, e.y, ref projX, ref projY); object result = null; var ext = new Extents(); ext.SetBounds(projX - 0.0004, projY - 0.0004, 0.0, projX + 0.0004, projY + 0.0004, 0.0); if (sf.SelectShapes(ext, 0.0001, SelectMode.INTERSECTION, ref result)) { if (labelFlag_MouseDown == 0) { mouseDownOperate(result, sf, labels, projX, projY); Map.Redraw(); labelFlag_MouseDown = 1; } } else { if (labelFlag_MouseDown == 1) { sf.Labels.Clear(); Map.Redraw(); labelFlag_MouseDown = 0; } } } } } }
/// <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> /// This will add a new label category that will only apply to the specified filter expression. /// This will not remove any existing categories. /// </summary> /// <param name="featureLayer">The feature layer that the labels should be applied to</param> /// <param name="expression">The string expression where field names are in square brackets</param> /// <param name="filterExpression">The string filter expression that controls which features are labeled. /// Field names are in square brackets, strings in single quotes.</param> /// <param name="symbolizer">The label symbolizer that controls the basic appearance of the labels in this /// category.</param> /// <param name="name">The name of the category.</param> public static void AddLabels(this IFeatureLayer featureLayer, string expression, string filterExpression, ILabelSymbolizer symbolizer, string name) { if (featureLayer.LabelLayer == null) { featureLayer.LabelLayer = new MapLabelLayer(); } featureLayer.ShowLabels = true; ILabelCategory lc = new LabelCategory { Expression = expression, FilterExpression = filterExpression, Symbolizer = symbolizer, Name = name, }; featureLayer.LabelLayer.Symbology.Categories.Add(lc); featureLayer.LabelLayer.CreateLabels(); }
/// <summary> /// Initializes a new instance of the LabelStyle class /// </summary> /// <param name="cat">Label category to take the options from</param> public LabelStyle(LabelCategory cat) { this.Alignment = cat.Alignment; this.Enabled = cat.Enabled; this.Expression = cat.Expression; this.FontBold = cat.FontBold; this.FontColor = cat.FontColor; this.FontColor2 = cat.FontColor2; this.FontGradientMode = cat.FontGradientMode; this.FontItalic = cat.FontItalic; this.FontName = cat.FontName; this.FontOutlineVisible = cat.FontOutlineVisible; this.FontSize = cat.FontSize; this.FontStrikeOut = cat.FontStrikeOut; this.FontTransparency = cat.FontTransparency; this.FontUnderline = cat.FontUnderline; this.FrameBackColor = cat.FrameBackColor; this.FrameBackColor2 = cat.FrameBackColor2; this.FrameGradientMode = cat.FrameGradientMode; this.FrameOutlineColor = cat.FrameOutlineColor; this.FrameOutlineWidth = cat.FrameOutlineWidth; this.FramePaddingX = cat.FramePaddingX; this.FramePaddingY = cat.FramePaddingY; this.FrameTransparency = cat.FrameTransparency; this.FrameType = cat.FrameType; this.FrameVisible = cat.FrameVisible; this.HaloColor = cat.HaloColor; this.HaloSize = cat.HaloSize; this.HaloVisible = cat.HaloVisible; this.InboxAlignment = cat.InboxAlignment; this.LineOrientation = cat.LineOrientation; this.MaxValue = cat.MaxValue; this.MinValue = cat.MinValue; this.Name = cat.Name; this.OffsetX = cat.OffsetX; this.OffsetY = cat.OffsetY; this.Priority = cat.Priority; this.ShadowColor = cat.ShadowColor; this.ShadowOffsetX = cat.ShadowOffsetX; this.ShadowOffsetY = cat.ShadowOffsetY; this.Visible = cat.Visible; }
public void AddText(double x, double y) { Labels labels = sf.Labels; labels.FontSize = 15; labels.FontBold = true; labels.FrameVisible = false; labels.FrameType = tkLabelFrameType.lfRectangle; labels.AutoOffset = false; labels.OffsetX = 40; LabelCategory cat = labels.AddCategory("wenzi"); cat.FontColor = 255; string aisLabel = "文字部分"; labels.AddLabel(aisLabel, x, y, 0.0, -1); }
/// <summary> /// This will add a new label category that will only apply to the specified filter expression. This will /// not remove any existing categories. /// </summary> /// <param name="featureLayer">The feature layer that the labels should be applied to</param> /// <param name="expression">The string expression where field names are in square brackets</param> /// <param name="filterExpression">The string filter expression that controls which features are labeled. /// Field names are in square brackets, strings in single quotes.</param> /// <param name="symbolizer">The label symbolizer that controls the basic appearance of the labels in this /// category.</param> /// <param name="width">A geographic width, so that if the map is zoomed to a geographic width smaller than /// this value, labels should appear.</param> public static void AddLabels(this IFeatureLayer featureLayer, string expression, string filterExpression, ILabelSymbolizer symbolizer, double width) { if (featureLayer.LabelLayer == null) { featureLayer.LabelLayer = new MapLabelLayer(); } featureLayer.ShowLabels = true; ILabelCategory lc = new LabelCategory { Expression = expression, FilterExpression = filterExpression, Symbolizer = symbolizer }; featureLayer.LabelLayer.UseDynamicVisibility = true; featureLayer.LabelLayer.DynamicVisibilityWidth = width; featureLayer.LabelLayer.Symbology.Categories.Add(lc); featureLayer.LabelLayer.CreateLabels(); }
public string FormatLabelCategory(LabelCategory category) { switch (category) { case LabelCategory.Feature: return("Features/Enhancements"); case LabelCategory.BugFix: return("Fixes"); case LabelCategory.Housekeeping: return("Housekeeping"); case LabelCategory.DocumentationUpdate: return("Documentation Updates"); case LabelCategory.Unknown: default: return("Other"); } }
// <summary> // Build a list of unique values of the given field and imlement zooming to them from the context menu // </summary> public void LabelSelection(AxMap axMap1, string dataPath) { axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR; string filename = dataPath + "buildings.shp"; if (!File.Exists(filename)) { System.Windows.Forms.MessageBox.Show("Couldn't file the file: " + filename); return; } Shapefile sf = new Shapefile(); sf.Open(filename, null); m_layerHandle = axMap1.AddLayer(sf, true); sf = axMap1.get_Shapefile(m_layerHandle); // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding // let's add labels consisting of Name and type of building on a separate lines sf.Labels.Generate("[Type]", tkLabelPositioning.lpCenter, false); sf.Labels.FrameVisible = true; sf.Labels.FrameType = tkLabelFrameType.lfRectangle; // now let's add categories Utils utils = new Utils(); // to specify colors LabelCategory ct = sf.Labels.AddCategory("Selected"); ct.FrameBackColor = utils.ColorByName(tkMapColor.Yellow); ct = sf.Labels.AddCategory("Hidden"); ct.Visible = false; axMap1.SendSelectBoxFinal = true; axMap1.SendMouseDown = true; axMap1.CursorMode = tkCursorMode.cmSelection; MapEvents.SelectBoxFinal += AxMap1SelectBoxFinal2; }
public MapTextGraticuleHelper(GeoProjection projection, Graticule graticule) { _graticule = graticule; TitleSize = 13; NoteSize = 10; TextBold = false; TitleText = "Map title"; NoteText = "Map note"; TitleVisible = false; NoteVisible = false; TitleAlignment = tkLabelAlignment.laCenter; NoteAlignment = tkLabelAlignment.laCenterLeft; MapTextType = fadMapTextType.mapTextTypeNone; _textShapefile = new Shapefile(); if (_textShapefile.CreateNewWithShapeID("", ShpfileType.SHP_POINT)) { _textShapefile.GeoProjection = projection; _ifldTextType = _textShapefile.EditAddField("TextType", FieldType.STRING_FIELD, 1, 5); _ifldText = _textShapefile.EditAddField("Text", FieldType.STRING_FIELD, 1, 100); _categoryTitle = _textShapefile.Labels.AddCategory("Text"); _categoryNote = _textShapefile.Labels.AddCategory("Note"); } }
/// <summary> /// Saves the options from the GUI to labels style class /// </summary> private void Gui2LabelStyle(object sender, EventArgs e) { if (m_NoEvents) { return; } LabelCategory lb = m_category; lb.Visible = chkVisible.Checked; // alignment lb.FramePaddingX = (int)udFramePaddingX.Value; lb.FramePaddingY = (int)udFramePaddingY.Value; // font lb.FontBold = chkFontBold.Checked; lb.FontItalic = chkFontItalic.Checked; lb.FontUnderline = chkFontUnderline.Checked; lb.FontStrikeOut = chkFontStrikeout.Checked; lb.FontName = cboFontName.Text; lb.FontColor = Colors.ColorToUInteger(clpFont1.Color); lb.FontSize = (int)udFontSize.Value; // outline lb.HaloVisible = chkHaloVisible.Checked; lb.ShadowVisible = chkShadowVisible.Checked; lb.HaloColor = Colors.ColorToUInteger(clpHalo.Color); lb.ShadowColor = Colors.ColorToUInteger(clpShadow.Color); lb.HaloSize = (int)udHaloSize.Value; lb.ShadowOffsetX = (int)udShadowOffsetX.Value; lb.ShadowOffsetY = (int)udShadowOffsetY.Value; // frame fill lb.FrameBackColor = Colors.ColorToUInteger(clpFrame1.Color); if (tabControl1.SelectedTab.Name == "tabFrameFill") { lb.FrameVisible = chkUseFrame.Checked; lb.FrameType = (MapWinGIS.tkLabelFrameType)icbFrameType.SelectedIndex; } // frame outline lb.FrameOutlineColor = Colors.ColorToUInteger(clpFrameBorder.Color); if (icbLineType.SelectedIndex >= 0) { lb.FrameOutlineStyle = (tkDashStyle)icbLineType.SelectedIndex; } lb.FrameOutlineWidth = (int)icbLineWidth.SelectedIndex + 1; lb.FrameTransparency = transparencyControl1.Value; lb.FontTransparency = transparencyControl1.Value; // passed from the main form m_shapefile.Labels.RemoveDuplicates = chkLabelsRemoveDuplicates.Checked; m_shapefile.Labels.AvoidCollisions = chkAviodCollisions.Checked; m_shapefile.Labels.ScaleLabels = chkScaleLabels.Checked; double val; m_shapefile.Labels.BasicScale = (double.TryParse(cboBasicScale.Text, out val)) ? val : 0.0; m_shapefile.Labels.VerticalPosition = (MapWinGIS.tkVerticalPosition)cboLabelsVerticalPosition.SelectedIndex; lb.OffsetX = (double)udLabelOffsetX.Value; lb.OffsetY = (double)udLabelOffsetY.Value; m_shapefile.Labels.CollisionBuffer = (int)udLabelsBuffer.Value; // alignment if (optAlignBottomCenter.Checked) { lb.Alignment = tkLabelAlignment.laBottomCenter; } if (optAlignBottomLeft.Checked) { lb.Alignment = tkLabelAlignment.laBottomLeft; } if (optAlignBottomRight.Checked) { lb.Alignment = tkLabelAlignment.laBottomRight; } if (optAlignCenter.Checked) { lb.Alignment = tkLabelAlignment.laCenter; } if (optAlignCenterLeft.Checked) { lb.Alignment = tkLabelAlignment.laCenterLeft; } if (optAlignCenterRight.Checked) { lb.Alignment = tkLabelAlignment.laCenterRight; } if (optAlignTopCenter.Checked) { lb.Alignment = tkLabelAlignment.laTopCenter; } if (optAlignTopLeft.Checked) { lb.Alignment = tkLabelAlignment.laTopLeft; } if (optAlignTopRight.Checked) { lb.Alignment = tkLabelAlignment.laTopRight; } // categories will have the same alignment if (!m_categoryEdited) { for (int i = 0; i < m_shapefile.Labels.NumCategories; i++) { var cat = m_shapefile.Labels.Category[i]; cat.Alignment = lb.Alignment; cat.OffsetX = lb.OffsetX; cat.OffsetY = lb.OffsetY; } } if (double.TryParse(cboMinScale.Text, out val)) { m_shapefile.Labels.MinVisibleScale = val; } if (double.TryParse(cboMaxScale.Text, out val)) { m_shapefile.Labels.MaxVisibleScale = val; } m_shapefile.Labels.DynamicVisibility = chkDynamicVisibility.Checked; btnApply.Enabled = true; m_shapefile.Labels.TextRenderingHint = (tkTextRenderingHint)cboTextRenderingHint.SelectedIndex; string format = m_shapefile.Labels.FloatNumberFormat; string newFormat = GetFloatFormat(); m_shapefile.Labels.FloatNumberFormat = newFormat; if (newFormat != format) { m_shapefile.Labels.ForceRecalculateExpression(); } DrawPreview(null, null); return; }
/// <summary> /// Loads label options to the GUI controls /// </summary> private bool LabelStyle2Gui(LabelCategory lb) { if (lb == null) { return(false); } chkVisible.Checked = m_category.Visible; string fontName = lb.FontName; int j = 0; foreach (FontFamily family in FontFamily.Families) { if (family.Name == fontName) { cboFontName.SelectedIndex = j; } j++; } if (cboFontName.SelectedIndex == -1) { cboFontName.SelectedItem = "Arial"; } // font style chkFontBold.Checked = lb.FontBold; chkFontItalic.Checked = lb.FontItalic; chkFontUnderline.Checked = lb.FontUnderline; chkFontStrikeout.Checked = lb.FontStrikeOut; udFontSize.Value = lb.FontSize; clpFont1.Color = Colors.UintToColor(lb.FontColor); udFramePaddingX.SetValue(lb.FramePaddingX); udFramePaddingY.SetValue(lb.FramePaddingY); // font outlines chkHaloVisible.Checked = lb.HaloVisible; chkShadowVisible.Checked = lb.ShadowVisible; clpShadow.Color = Colors.UintToColor(lb.ShadowColor); clpHalo.Color = Colors.UintToColor(lb.HaloColor); udHaloSize.SetValue(lb.HaloSize); udShadowOffsetX.SetValue(lb.ShadowOffsetX); udShadowOffsetY.SetValue(lb.ShadowOffsetY); // frame options chkUseFrame.Checked = lb.FrameVisible; icbFrameType.SelectedIndex = (int)lb.FrameType; icbLineType.SelectedIndex = (int)lb.FrameOutlineStyle; clpFrame1.Color = Colors.UintToColor(lb.FrameBackColor); clpFrameBorder.Color = Colors.UintToColor(lb.FrameOutlineColor); udFramePaddingX.SetValue(lb.FramePaddingX); udFramePaddingY.SetValue(lb.FramePaddingY); if (lb.FrameOutlineWidth < 1) { lb.FrameOutlineWidth = 1; } if (lb.FrameOutlineWidth > icbLineWidth.Items.Count) { lb.FrameOutlineWidth = icbLineWidth.Items.Count; } icbLineWidth.SelectedIndex = (int)lb.FrameOutlineWidth - 1; transparencyControl1.Value = (byte)lb.FrameTransparency; cboMinScale.Text = m_shapefile.Labels.MinVisibleScale.ToString(); cboMaxScale.Text = m_shapefile.Labels.MaxVisibleScale.ToString(); chkDynamicVisibility.Checked = m_shapefile.Labels.DynamicVisibility; return(true); }
/// <summary> /// Initializes controls of the form /// </summary> private void Initialize(LabelCategory lb) { m_category = lb; m_NoEvents = true; cboFontName.Items.Clear(); foreach (FontFamily family in FontFamily.Families) { cboFontName.Items.Add(family.Name); } cboDecimalPlaces.Items.Add("Auto"); for (int i = 1; i <= 6; i++) { cboDecimalPlaces.Items.Add(i.ToString()); } cboDecimalPlaces.SelectedIndex = 0; icbLineType.ComboStyle = ImageComboStyle.LineStyle; icbLineWidth.ComboStyle = ImageComboStyle.LineWidth; icbFrameType.Color1 = Color.Transparent; icbFrameType.ComboStyle = ImageComboStyle.FrameType; icbFrameType.SelectedIndex = 0; if (!m_categoryEdited) { for (int i = 0; i < m_shapefile.NumFields; i++) { string name = m_shapefile.Field[i].Name; if (name.ToLower() != "mwshapeid") { listBox1.Items.Add(name); } } } string[] scales = { "1", "10", "100", "1000", "5000", "10000", "25000", "50000", "100000", "250000", "500000", "1000000", "10000000" }; cboMinScale.Items.Clear(); cboMaxScale.Items.Clear(); cboBasicScale.Items.Clear(); foreach (string t in scales) { cboMinScale.Items.Add(t); cboMaxScale.Items.Add(t); cboBasicScale.Items.Add(t); } // displaying options in the GUI LabelStyle2Gui(m_category); btnTest_Click(null, null); txtLabelExpression.Text = m_shapefile.Labels.VisibilityExpression; // serialization if (m_categoryEdited) { m_initState = m_category.Serialize(); } else { tkSavingMode mode = m_shapefile.Labels.SavingMode; m_shapefile.Labels.SavingMode = tkSavingMode.modeNone; m_initState = m_shapefile.Labels.Serialize(); m_shapefile.Labels.SavingMode = mode; } cboLabelsVerticalPosition.Items.Clear(); cboLabelsVerticalPosition.Items.Add("Above layer"); cboLabelsVerticalPosition.Items.Add("Above all layers"); var labels = m_shapefile.Labels; cboLabelsVerticalPosition.SelectedIndex = (int)labels.VerticalPosition; chkLabelsRemoveDuplicates.Checked = labels.RemoveDuplicates; chkAviodCollisions.Checked = labels.AvoidCollisions; chkScaleLabels.Checked = labels.ScaleLabels; cboBasicScale.Text = labels.BasicScale.ToString(); udLabelOffsetX.SetValue(labels.OffsetX); udLabelOffsetY.SetValue(labels.OffsetY); udLabelsBuffer.SetValue(labels.CollisionBuffer); // alignment optAlignBottomCenter.Checked = (labels.Alignment == tkLabelAlignment.laBottomCenter); optAlignBottomLeft.Checked = (labels.Alignment == tkLabelAlignment.laBottomLeft); optAlignBottomRight.Checked = (labels.Alignment == tkLabelAlignment.laBottomRight); optAlignCenter.Checked = (labels.Alignment == tkLabelAlignment.laCenter); optAlignCenterLeft.Checked = (labels.Alignment == tkLabelAlignment.laCenterLeft); optAlignCenterRight.Checked = (labels.Alignment == tkLabelAlignment.laCenterRight); optAlignTopCenter.Checked = (labels.Alignment == tkLabelAlignment.laTopCenter); optAlignTopLeft.Checked = (labels.Alignment == tkLabelAlignment.laTopLeft); optAlignTopRight.Checked = (labels.Alignment == tkLabelAlignment.laTopRight); ShpfileType shpType = Globals.ShapefileType2D(m_shapefile.ShapefileType); optAlignCenter.Enabled = (shpType != ShpfileType.SHP_POINT && shpType != ShpfileType.SHP_MULTIPOINT); btnApply.Enabled = (m_shapefile.Labels.Expression != "" && m_shapefile.Labels.Count == 0); string[] list = new string[] { "Default", "SingleBitPerPixelGridFit", "SingleBitPerPixel", "AntiAliasGridFit", "HintAntiAlias", "ClearType" }; cboTextRenderingHint.DataSource = list; SetSelectedIndex(cboTextRenderingHint, (int)m_shapefile.Labels.TextRenderingHint); cboTextRenderingHint.SelectedIndexChanged += Gui2LabelStyle; m_NoEvents = false; // initial drawing this.DrawPreview(null, null); }
/// <summary> /// Translates the given style as point style and adds it to the given point scheme. /// </summary> /// <param name="scheme">The scheme the style gets added to.</param> /// <param name="labelScheme">The scheme the label definitions gets added to.</param> /// <param name="style">The style that gets translated.</param> private static void TranslatePointStyle(PointScheme scheme, ILabelScheme labelScheme, string style) { if (string.IsNullOrWhiteSpace(style)) { return; } var myStyle = style; int index = myStyle.IndexOf("(", StringComparison.Ordinal); if (index < 1) { return; } var toolname = myStyle.Substring(0, index); myStyle = myStyle.Substring(index + 1); switch (toolname) { case "PEN": { var color = GetColor(ref myStyle, Parameters.Color); var width = GetWidth(ref myStyle); var cat = new PointCategory(color, Symbology.PointShape.Rectangle, width) { FilterExpression = $"[style] = '{style}'", LegendText = style, Symbolizer = { ScaleMode = ScaleMode.Simple, Smoothing = false } }; scheme.AddCategory(cat); break; } case "LABEL": { var fontSize = GetFontSize(ref myStyle); var fontColor = GetColor(ref myStyle, Parameters.Color); var boxColor = GetColor(ref myStyle, Parameters.BoxColor); var haloColor = GetColor(ref myStyle, Parameters.HaloColor); var shadowColor = GetColor(ref myStyle, Parameters.ShadowColor); var angle = GetAngle(ref myStyle); var font = GetFontName(ref myStyle); var orientation = GetOrientation(ref myStyle); // create a transparent point category because the point is only used to position the label var cat = new PointCategory(Color.Transparent, Symbology.PointShape.Rectangle, 1) { FilterExpression = $"[style] = '{style}'", LegendText = style, Symbolizer = { ScaleMode = ScaleMode.Simple, Smoothing = false } }; scheme.AddCategory(cat); // create the label category only if the text column exists, otherwise we don't know where to take the text from if (hasTextField) { var lcat = new LabelCategory { Name = style, Expression = "[Text]", FilterExpression = $"[style] = '{style}'", Symbolizer = { ScaleMode = ScaleMode.Simple, Alignment = StringAlignment.Center, FontColor = fontColor, FontSize = (float)fontSize, Orientation = orientation } }; if (!string.IsNullOrWhiteSpace(font)) { lcat.Symbolizer.FontFamily = font; } if (angle != 0) { lcat.Symbolizer.Angle = angle; lcat.Symbolizer.UseAngle = true; } if (haloColor != Color.Empty) { lcat.Symbolizer.HaloColor = haloColor; lcat.Symbolizer.HaloEnabled = true; } if (boxColor != Color.Empty) { lcat.Symbolizer.BackColor = boxColor; lcat.Symbolizer.BackColorEnabled = true; } if (shadowColor != Color.Empty) { lcat.Symbolizer.DropShadowColor = shadowColor; lcat.Symbolizer.DropShadowEnabled = true; } labelScheme.Categories.Add(lcat); } break; } default: throw new NotImplementedException($"The translation of the point tool {toolname} is not yet implemented."); } }
/// <summary> /// Draws preview based on the category options and expression stored in the Labels class /// </summary> internal static void DrawPreview(LabelCategory category, MapWinGIS.Shapefile sf, System.Windows.Forms.PictureBox canvas, bool forceDrawing) { string expression = (sf.Labels.Expression == "" && sf.Labels.Count != 0) ? "<no expression>" : sf.Labels.Expression; DrawPreview(category, sf, canvas, expression, forceDrawing); }