/// <summary> /// 创建标注 /// </summary> /// <param name="feaName"></param> /// <param name="featureDataset"></param> /// <param name="feaworkspace"></param> /// <param name="fsEditAnno"></param> /// <param name="intScale"></param> public void createAnnoFeatureClass(string feaName, IFeatureDataset featureDataset, IFeatureWorkspace feaworkspace, IFieldsEdit fsEditAnno, int intScale) { //创建注记的特殊字段 try { //注记的workSpace IFeatureWorkspaceAnno pFWSAnno = feaworkspace as IFeatureWorkspaceAnno; //标注操作空间 IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass(); //图形比例接口 pGLS.Units = esriUnits.esriMeters; //图形比例设定 pGLS.ReferenceScale = Convert.ToDouble(intScale); //创建注记必须要设置比例尺 IFormattedTextSymbol myTextSymbol = new TextSymbolClass(); //文本格式接口 ISymbol pSymbol = (ISymbol)myTextSymbol; //标记 //Anno要素类必须有的缺省符号 ISymbolCollection2 pSymbolColl = new SymbolCollectionClass(); ISymbolIdentifier2 pSymID = new SymbolIdentifierClass(); pSymbolColl.AddSymbol(pSymbol, "Default", out pSymID); //Anno要素类的必要属性 IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass(); pAnnoProps.CreateUnplacedElements = true; pAnnoProps.CreateUnplacedElements = true; pAnnoProps.DisplayAnnotation = true; pAnnoProps.UseOutput = true; ILabelEngineLayerProperties pLELayerProps = (ILabelEngineLayerProperties)pAnnoProps; pLELayerProps.Symbol = pSymbol as ITextSymbol; pLELayerProps.SymbolID = 0; pLELayerProps.IsExpressionSimple = true; pLELayerProps.Offset = 0; pLELayerProps.SymbolID = 0; IAnnotationExpressionEngine aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass(); pLELayerProps.ExpressionParser = aAnnoVBScriptEngine; pLELayerProps.Expression = "[DESCRIPTION]"; IAnnotateLayerTransformationProperties pATP = (IAnnotateLayerTransformationProperties)pAnnoProps; pATP.ReferenceScale = pGLS.ReferenceScale; pATP.ScaleRatio = 1; IAnnotateLayerPropertiesCollection pAnnoPropsColl = new AnnotateLayerPropertiesCollectionClass(); pAnnoPropsColl.Add(pAnnoProps); IObjectClassDescription pOCDesc = new AnnotationFeatureClassDescription(); IFields fields = pOCDesc.RequiredFields; IFeatureClassDescription pFDesc = pOCDesc as IFeatureClassDescription; for (int j = 0; j < pOCDesc.RequiredFields.FieldCount; j++) { fsEditAnno.AddField(pOCDesc.RequiredFields.get_Field(j)); } fields = fsEditAnno as IFields; pFWSAnno.CreateAnnotationClass(feaName, fields, pOCDesc.InstanceCLSID, pOCDesc.ClassExtensionCLSID, pFDesc.ShapeFieldName, "", featureDataset, null, pAnnoPropsColl, pGLS, pSymbolColl, true); } catch { } }
private void method_3(IMap imap_1, ILayer ilayer_0, string string_0, double double_1, IWorkspace iworkspace_1, bool bool_0, bool bool_1, esriLabelWhichFeatures esriLabelWhichFeatures_1) { if ((iworkspace_1.Type != esriWorkspaceType.esriFileSystemWorkspace) && (ilayer_0 is IGeoFeatureLayer)) { int num; IAnnotateLayerProperties properties; IElementCollection elements; IElementCollection elements2; ILabelEngineLayerProperties2 properties2; IAnnotationLayer layer2; IGeoFeatureLayer layer = ilayer_0 as IGeoFeatureLayer; IFeatureClass featureClass = layer.FeatureClass; IAnnotationLayerFactory factory = new FDOGraphicsLayerFactoryClass(); ISymbolCollection2 lcs = new SymbolCollectionClass(); IAnnotateLayerPropertiesCollection propertiess = new AnnotateLayerPropertiesCollectionClass(); IAnnotateLayerPropertiesCollection annotationProperties = layer.AnnotationProperties; for (num = 0; num < annotationProperties.Count; num++) { annotationProperties.QueryItem(num, out properties, out elements, out elements2); if (properties != null) { ISymbolIdentifier2 identifier; propertiess.Add(properties); properties2 = properties as ILabelEngineLayerProperties2; IClone symbol = properties2.Symbol as IClone; lcs.AddSymbol(symbol.Clone() as ISymbol, properties.Class + " " + num.ToString(), out identifier); properties2.SymbolID = identifier.ID; } } properties = null; properties2 = null; IGraphicsLayerScale scale = new GraphicsLayerScaleClass { ReferenceScale = double_1, Units = imap_1.MapUnits }; IFeatureClassDescription description = new AnnotationFeatureClassDescriptionClass(); IObjectClassDescription description2 = description as IObjectClassDescription; IFields requiredFields = description2.RequiredFields; IGeometryDefEdit geometryDef = requiredFields.get_Field(requiredFields.FindField(description.ShapeFieldName)).GeometryDef as IGeometryDefEdit; IGeoDataset dataset = featureClass as IGeoDataset; geometryDef.SpatialReference_2 = dataset.SpatialReference; IMapOverposter overposter = imap_1 as IMapOverposter; IOverposterProperties overposterProperties = overposter.OverposterProperties; if (bool_1) { this.method_2(iworkspace_1 as IFeatureWorkspaceAnno, featureClass.FeatureDataset, featureClass, scale.ReferenceScale, scale.Units, propertiess, lcs as ISymbolCollection, string_0); layer2 = factory.OpenAnnotationLayer(iworkspace_1 as IFeatureWorkspace, featureClass.FeatureDataset, string_0); } else { this.method_2(iworkspace_1 as IFeatureWorkspaceAnno, featureClass.FeatureDataset, null, scale.ReferenceScale, scale.Units, propertiess, lcs as ISymbolCollection, string_0); layer2 = factory.OpenAnnotationLayer(iworkspace_1 as IFeatureWorkspace, featureClass.FeatureDataset, string_0); } IActiveView view = imap_1 as IActiveView; IScreenDisplay screenDisplay = view.ScreenDisplay; (layer2 as IGraphicsLayer).Activate(screenDisplay); for (num = 0; num < propertiess.Count; num++) { propertiess.QueryItem(num, out properties, out elements, out elements2); if (properties != null) { properties.FeatureLayer = layer; properties.GraphicsContainer = layer2 as IGraphicsContainer; properties.AddUnplacedToGraphicsContainer = bool_0; properties.CreateUnplacedElements = true; properties.DisplayAnnotation = true; properties.FeatureLinked = bool_1; properties.LabelWhichFeatures = esriLabelWhichFeatures_1; properties.UseOutput = true; properties2 = properties as ILabelEngineLayerProperties2; properties2.SymbolID = num; properties2.AnnotationClassID = num; IOverposterLayerProperties2 overposterLayerProperties = properties2.OverposterLayerProperties as IOverposterLayerProperties2; overposterLayerProperties.TagUnplaced = true; } } propertiess.Sort(); IAnnotateMapProperties annoMapCmdProps = new AnnotateMapPropertiesClass { AnnotateLayerPropertiesCollection = propertiess }; ITrackCancel trackCancel = new CancelTrackerClass(); (imap_1.AnnotationEngine as IAnnotateMap2).Label(overposterProperties, annoMapCmdProps, imap_1, trackCancel); for (num = 0; num < propertiess.Count; num++) { propertiess.QueryItem(num, out properties, out elements, out elements2); if (properties != null) { properties.FeatureLayer = null; } } imap_1.AddLayer(layer2 as ILayer); layer.DisplayAnnotation = false; view.Refresh(); } }