private void CreateLabels() { if (Layer is IGeoFeatureLayer geoFeatureLayer) { const double TextSizePt = 9.0; const double GoodLookingScale = 500.0; double referenceScale = ArcmapUtils.GetReferenceScale(GoodLookingScale); string tableName = ArcobjWorkspaceUtils.UnqualifyTableName(ArcobjWorkspaceUtils.GetTableName(geoFeatureLayer.FeatureClass as IDataset)); string oidFieldName = geoFeatureLayer.FeatureClass.OIDFieldName; string globalIdFieldName = ArcobjWorkspaceUtils.GetGlobalIdFieldName(geoFeatureLayer.FeatureClass as ITable); string expression = FormatLabelExpression(tableName, oidFieldName, globalIdFieldName); ITextSymbol textSymbol = new TextSymbolClass(); textSymbol.Color = ArcmapLayerUtils.DetectLayerMainColor(geoFeatureLayer); textSymbol.Size = TextSizePt / referenceScale * GoodLookingScale; // Remove existing annotations geoFeatureLayer.DisplayAnnotation = false; geoFeatureLayer.AnnotationProperties.Clear(); IAnnotateLayerProperties annotateLayerProperties = new LabelEngineLayerPropertiesClass(); annotateLayerProperties.UseOutput = true; annotateLayerProperties.LabelWhichFeatures = esriLabelWhichFeatures.esriVisibleFeatures; annotateLayerProperties.CreateUnplacedElements = true; ILabelEngineLayerProperties2 labelEngineProperties = (ILabelEngineLayerProperties2)annotateLayerProperties; labelEngineProperties.ExpressionParser = new AnnotationVBScriptEngineClass(); labelEngineProperties.Expression = expression; labelEngineProperties.Symbol = textSymbol; IBasicOverposterLayerProperties overposterProperties = labelEngineProperties.BasicOverposterLayerProperties; overposterProperties.GenerateUnplacedLabels = true; overposterProperties.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape; overposterProperties.PointPlacementOnTop = true; overposterProperties.PointPlacementMethod = esriOverposterPointPlacementMethod.esriSpecifiedAngles; overposterProperties.PointPlacementAngles = new[] { 30.0 }; overposterProperties.LineLabelPosition = CreateLineLabelPosition(); if (labelEngineProperties.OverposterLayerProperties is IOverposterLayerProperties2 overposterProperties2) { overposterProperties2.TagUnplaced = false; // The "place overlapping labels" option } // Show new annotation in map geoFeatureLayer.AnnotationProperties.Add(annotateLayerProperties); geoFeatureLayer.DisplayAnnotation = true; ArcmapUtils.InvalidateMap(ArcmapUtils.GetFocusMap()); } }
public void processFeatureLayer(ILayer lyr) { type = "Vektor"; fillLayerProps(lyr); fillDatalayerProps(lyr); IFeatureLayer flyr = lyr as IFeatureLayer; fillDefQueryProps(flyr); processJoins(flyr); processRelates(flyr); IGeoFeatureLayer gflyr = flyr as IGeoFeatureLayer; if (gflyr.DisplayAnnotation == true) { IAnnotateLayerPropertiesCollection labelPropsColl = gflyr.AnnotationProperties; for (int collIndex = 0; collIndex < labelPropsColl.Count; collIndex++) { IAnnotateLayerProperties annoLayerProps; IElementCollection elCol1; IElementCollection elCol2; labelPropsColl.QueryItem(collIndex, out annoLayerProps, out elCol1, out elCol2); string sql = annoLayerProps.WhereClause; ILabelEngineLayerProperties2 labelEngineProps = (ILabelEngineLayerProperties2)annoLayerProps; string expr = labelEngineProps.Expression; this.label = this.label + sql + "?" + expr + "/"; } } this.label = this.label.TrimEnd('/'); IFeatureRenderer rend = gflyr.Renderer; if (rend is IUniqueValueRenderer) { string felder = ""; IUniqueValueRenderer u = rend as IUniqueValueRenderer; for (int i = 0; i < u.FieldCount; i++) { felder = felder + u.get_Field(i) + "/"; } symbfields = felder.TrimEnd('/') + " (UniqueValueRenderer)"; } else if (rend is IProportionalSymbolRenderer) { IProportionalSymbolRenderer prop = rend as IProportionalSymbolRenderer; symbfields = prop.Field + " (ProportionalSymbolRenderer)"; } else if (rend is IClassBreaksRenderer) { IClassBreaksRenderer cl = rend as IClassBreaksRenderer; symbfields = cl.Field + " (ClassBreaksRenderer)";; } else if (rend is ISimpleRenderer) { symbfields = "kein Feld (SimpleRenderer)"; } else { symbfields = "unbekannter Renderer"; } }
private void getLayerLabel_Maplex(IGeoFeatureLayer pGeoFeatLayer) { Boolean bIsLabel = pGeoFeatLayer.DisplayAnnotation; if (bIsLabel) { this.chkIsLabel.Checked = true; } else { this.chkIsLabel.Checked = false;//changed by chulili 20110712修改bug true->false } //added by chulili 20110804按照图层的标注设置初始化界面 //this.chkIsLabel.Checked = pGeoFeatureLayer.DisplayAnnotation; IAnnotateLayerPropertiesCollection pAnnotateLayerPropertiesCollection = pGeoFeatLayer.AnnotationProperties; if (pAnnotateLayerPropertiesCollection == null) { return; } //定义IAnnotateLayerPropertiesCollection.QueryItem方法中调用的对象 IAnnotateLayerProperties pAnnoLayerProperties = null; IElementCollection pElementCollection = null; IElementCollection pElementCollection1 = null; //获取标注渲染对象 pAnnotateLayerPropertiesCollection.QueryItem(0, out pAnnoLayerProperties, out pElementCollection, out pElementCollection1); if (pAnnoLayerProperties == null) { return; } ILabelEngineLayerProperties2 pLabelEngineLayerPro = pAnnoLayerProperties as ILabelEngineLayerProperties2; if (pLabelEngineLayerPro == null) { return; } ITextSymbol pTextSymbol = pLabelEngineLayerPro.Symbol; IMaplexOverposterLayerProperties pmaplexoverposterlayerprop = pLabelEngineLayerPro.OverposterLayerProperties as IMaplexOverposterLayerProperties; IBasicOverposterLayerProperties pBasicOverposterLayerProp = pLabelEngineLayerPro.OverposterLayerProperties as IBasicOverposterLayerProperties; if (pBasicOverposterLayerProp != null) { switch (pBasicOverposterLayerProp.NumLabelsOption) { case esriBasicNumLabelsOption.esriOneLabelPerName: this.rdbPerName.Checked = true; break; case esriBasicNumLabelsOption.esriOneLabelPerPart: this.rdbPerPart.Checked = true; break; case esriBasicNumLabelsOption.esriOneLabelPerShape: this.rdbPerShape.Checked = true; break; default: this.rdbPerName.Checked = true; break; } } ///////////////////////////// string strMaxScale = pAnnoLayerProperties.AnnotationMaximumScale.ToString(); string strMinScale = pAnnoLayerProperties.AnnotationMinimumScale.ToString(); //////////////////////////// this.txtMaxLabelScale.Text = strMaxScale; this.txtMinLabelScale.Text = strMinScale; this.btnBold.Checked = pTextSymbol.Font.Bold; this.btnItalic.Checked = pTextSymbol.Font.Italic; this.btnUnderLine.Checked = pTextSymbol.Font.Underline; this.FontColorPicker.SelectedColor = ColorTranslator.FromOle(pTextSymbol.Color.RGB); newSize = (float)Convert.ToDouble(pTextSymbol.Font.Size); newFamily = new FontFamily(pTextSymbol.Font.Name); newFont = FontStyle.Regular;//CmbFields string strField = pLabelEngineLayerPro.Expression; //获取字段名称 if (strField.StartsWith("[")) { strField = strField.Substring(1); } if (strField.EndsWith("]")) { strField = strField.Substring(0, strField.Length - 1); } //设置界面上字段名称 for (int i = 0; i < CmbFields.Items.Count; i++) { if (CmbFields.Items[i].ToString() == strField) { CmbFields.SelectedIndex = i; break; } } //设置界面上字体名称 for (int i = 0; i < CmbFontName.Items.Count; i++) { if (CmbFontName.Items[i].ToString() == pTextSymbol.Font.Name) { CmbFontName.SelectedIndex = i; break; } } //设置界面上字体大小 decimal dSize = decimal.Round(pTextSymbol.Font.Size, 0, MidpointRounding.AwayFromZero); string strLabelSize = Convert.ToInt32(dSize).ToString(); for (int i = 0; i < CmbFontSize.Items.Count; i++) { if (CmbFontSize.Items[i].ToString() == strLabelSize) { CmbFontSize.SelectedIndex = i; break; } } if (pTextSymbol.Font.Underline) { newFont = newFont ^ FontStyle.Underline; } if (pTextSymbol.Font.Bold) { newFont = newFont ^ FontStyle.Bold; } if (pTextSymbol.Font.Italic) { newFont = newFont ^ FontStyle.Italic; } //设置界面上字体格式 setFont(); //设置界面上字体颜色 LabelText.ForeColor = ColorTranslator.FromOle(pTextSymbol.Color.RGB); }