public static void ConvertLabels2StandardAnno(IMap imap_0, ILayer ilayer_0, string string_0, double double_0, IWorkspace iworkspace_0, bool bool_0, bool bool_1, esriLabelWhichFeatures esriLabelWhichFeatures_0) { int i; IAnnotateLayerProperties bool0; IElementCollection elementCollection; IElementCollection elementCollection1; ILabelEngineLayerProperties2 d; ISymbolIdentifier2 symbolIdentifier2; IAnnotationLayer annotationLayer; if (iworkspace_0.Type != esriWorkspaceType.esriFileSystemWorkspace && ilayer_0 is IGeoFeatureLayer) { IGeoFeatureLayer ilayer0 = ilayer_0 as IGeoFeatureLayer; IFeatureClass featureClass = ilayer0.FeatureClass; IAnnotationLayerFactory fDOGraphicsLayerFactoryClass = new FDOGraphicsLayerFactory() as IAnnotationLayerFactory; ISymbolCollection2 symbolCollectionClass = new SymbolCollection() as ISymbolCollection2; IAnnotateLayerPropertiesCollection annotateLayerPropertiesCollectionClass = new AnnotateLayerPropertiesCollection(); IAnnotateLayerPropertiesCollection annotationProperties = ilayer0.AnnotationProperties; for (i = 0; i < annotationProperties.Count; i++) { annotationProperties.QueryItem(i, out bool0, out elementCollection, out elementCollection1); if (bool0 != null) { annotateLayerPropertiesCollectionClass.Add(bool0); d = bool0 as ILabelEngineLayerProperties2; IClone symbol = d.Symbol as IClone; symbolCollectionClass.AddSymbol(symbol.Clone() as ISymbol, string.Concat(bool0.Class, " ", i.ToString()), out symbolIdentifier2); d.SymbolID = symbolIdentifier2.ID; } } bool0 = null; d = null; IGraphicsLayerScale graphicsLayerScaleClass = new GraphicsLayerScale() { ReferenceScale = double_0, Units = imap_0.MapUnits }; IFeatureClassDescription annotationFeatureClassDescriptionClass = new AnnotationFeatureClassDescription() as IFeatureClassDescription; IFields requiredFields = (annotationFeatureClassDescriptionClass as IObjectClassDescription).RequiredFields; IField field = requiredFields.Field[requiredFields.FindField(annotationFeatureClassDescriptionClass.ShapeFieldName) ]; (field.GeometryDef as IGeometryDefEdit).SpatialReference_2 = (featureClass as IGeoDataset).SpatialReference; IOverposterProperties overposterProperties = (imap_0 as IMapOverposter).OverposterProperties; if (!bool_1) { LayerOp.CreateAnnoFeatureClass(iworkspace_0 as IFeatureWorkspaceAnno, featureClass.FeatureDataset, null, graphicsLayerScaleClass.ReferenceScale, graphicsLayerScaleClass.Units, annotateLayerPropertiesCollectionClass, symbolCollectionClass as ISymbolCollection, string_0); annotationLayer = fDOGraphicsLayerFactoryClass.OpenAnnotationLayer( iworkspace_0 as IFeatureWorkspace, featureClass.FeatureDataset, string_0); } else { LayerOp.CreateAnnoFeatureClass(iworkspace_0 as IFeatureWorkspaceAnno, featureClass.FeatureDataset, featureClass, graphicsLayerScaleClass.ReferenceScale, graphicsLayerScaleClass.Units, annotateLayerPropertiesCollectionClass, symbolCollectionClass as ISymbolCollection, string_0); annotationLayer = fDOGraphicsLayerFactoryClass.OpenAnnotationLayer( iworkspace_0 as IFeatureWorkspace, featureClass.FeatureDataset, string_0); } IActiveView imap0 = imap_0 as IActiveView; (annotationLayer as IGraphicsLayer).Activate(imap0.ScreenDisplay); for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++) { annotateLayerPropertiesCollectionClass.QueryItem(i, out bool0, out elementCollection, out elementCollection1); if (bool0 != null) { bool0.FeatureLayer = ilayer0; bool0.GraphicsContainer = annotationLayer as IGraphicsContainer; bool0.AddUnplacedToGraphicsContainer = bool_0; bool0.CreateUnplacedElements = true; bool0.DisplayAnnotation = true; bool0.FeatureLinked = bool_1; bool0.LabelWhichFeatures = esriLabelWhichFeatures_0; bool0.UseOutput = true; d = bool0 as ILabelEngineLayerProperties2; d.SymbolID = i; d.AnnotationClassID = i; (d.OverposterLayerProperties as IOverposterLayerProperties2).TagUnplaced = true; } } annotateLayerPropertiesCollectionClass.Sort(); IAnnotateMapProperties annotateMapPropertiesClass = new AnnotateMapProperties() { AnnotateLayerPropertiesCollection = annotateLayerPropertiesCollectionClass }; ITrackCancel cancelTrackerClass = new CancelTracker(); (imap_0.AnnotationEngine as IAnnotateMap2).Label(overposterProperties, annotateMapPropertiesClass, imap_0, cancelTrackerClass); for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++) { annotateLayerPropertiesCollectionClass.QueryItem(i, out bool0, out elementCollection, out elementCollection1); if (bool0 != null) { bool0.FeatureLayer = null; } } imap_0.AddLayer(annotationLayer as ILayer); ilayer0.DisplayAnnotation = false; imap0.Refresh(); } }
public static void ConvertLabels2Anno(IMap imap_0, IGeoFeatureLayer igeoFeatureLayer_0, string string_0, double double_0) { int i; IAnnotateLayerProperties igeoFeatureLayer0; IElementCollection elementCollection; IElementCollection elementCollection1; IElementCollection elementCollection2; IElement element; int num; IActiveView imap0 = imap_0 as IActiveView; int j = 0; int count = 0; IAnnotateLayerPropertiesCollection annotateLayerPropertiesCollectionClass = new AnnotateLayerPropertiesCollection(); IAnnotateLayerPropertiesCollection annotationProperties = igeoFeatureLayer_0.AnnotationProperties; for (i = 0; i < annotationProperties.Count; i++) { annotationProperties.QueryItem(i, out igeoFeatureLayer0, out elementCollection, out elementCollection1); if (igeoFeatureLayer0 != null) { annotateLayerPropertiesCollectionClass.Add( (igeoFeatureLayer0 as IClone).Clone() as IAnnotateLayerProperties); } } igeoFeatureLayer0 = null; IOverposterProperties overposterProperties = (imap_0 as IMapOverposter).OverposterProperties; IGraphicsLayer double0 = (imap_0.BasicGraphicsLayer as ICompositeGraphicsLayer).AddLayer(string_0, igeoFeatureLayer_0); (double0 as IGraphicsLayerScale).ReferenceScale = double_0; double0.Activate(imap0.ScreenDisplay); for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++) { annotateLayerPropertiesCollectionClass.QueryItem(i, out igeoFeatureLayer0, out elementCollection, out elementCollection1); if (igeoFeatureLayer0 != null) { igeoFeatureLayer0.FeatureLayer = igeoFeatureLayer_0; igeoFeatureLayer0.GraphicsContainer = double0 as IGraphicsContainer; igeoFeatureLayer0.AddUnplacedToGraphicsContainer = false; igeoFeatureLayer0.CreateUnplacedElements = true; igeoFeatureLayer0.DisplayAnnotation = true; igeoFeatureLayer0.FeatureLinked = false; igeoFeatureLayer0.LabelWhichFeatures = esriLabelWhichFeatures.esriAllFeatures; igeoFeatureLayer0.UseOutput = true; ((igeoFeatureLayer0 as ILabelEngineLayerProperties2).OverposterLayerProperties as IOverposterLayerProperties2).TagUnplaced = true; } } annotateLayerPropertiesCollectionClass.Sort(); IAnnotateMapProperties annotateMapPropertiesClass = new AnnotateMapProperties() { AnnotateLayerPropertiesCollection = annotateLayerPropertiesCollectionClass }; ITrackCancel cancelTrackerClass = new CancelTracker(); (imap_0.AnnotationEngine as IAnnotateMap2).Label(overposterProperties, annotateMapPropertiesClass, imap_0, cancelTrackerClass); for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++) { annotateLayerPropertiesCollectionClass.QueryItem(i, out igeoFeatureLayer0, out elementCollection, out elementCollection2); if (igeoFeatureLayer0 != null) { count = count + elementCollection2.Count; if (elementCollection2.Count > 0) { IOverflowGraphicsContainer overflowGraphicsContainer = double0 as IOverflowGraphicsContainer; for (j = 0; j < elementCollection2.Count; j++) { elementCollection2.QueryItem(j, out element, out num); overflowGraphicsContainer.AddOverflowElement(element); } } igeoFeatureLayer0.FeatureLayer = null; } } igeoFeatureLayer_0.DisplayAnnotation = false; imap0.ContentsChanged(); imap0.Refresh(); }
public static void ConvertLabels2StandardAnno(IMap imap_0, ILayer ilayer_0, string string_0) { int i; IAnnotateLayerProperties annotateLayerProperty; IElementCollection elementCollection; IElementCollection elementCollection1; ILabelEngineLayerProperties2 d; ISymbolIdentifier2 symbolIdentifier2; IActiveView imap0 = imap_0 as IActiveView; if (ilayer_0 is IGeoFeatureLayer) { IGeoFeatureLayer ilayer0 = ilayer_0 as IGeoFeatureLayer; IWorkspace workspace = (ilayer0 as IDataset).Workspace; if (workspace.Type != esriWorkspaceType.esriFileSystemWorkspace) { IFeatureClass featureClass = ilayer0.FeatureClass; IGeoDataset geoDataset = featureClass as IGeoDataset; IAnnotationLayerFactory fDOGraphicsLayerFactoryClass = new FDOGraphicsLayerFactory() as IAnnotationLayerFactory; ISymbolCollection2 symbolCollectionClass = new SymbolCollection() as ISymbolCollection2; IAnnotateLayerPropertiesCollection annotateLayerPropertiesCollectionClass = new AnnotateLayerPropertiesCollection(); IAnnotateLayerPropertiesCollection annotationProperties = ilayer0.AnnotationProperties; for (i = 0; i < annotationProperties.Count; i++) { annotationProperties.QueryItem(i, out annotateLayerProperty, out elementCollection, out elementCollection1); if (annotateLayerProperty != null) { annotateLayerPropertiesCollectionClass.Add(annotateLayerProperty); d = annotateLayerProperty as ILabelEngineLayerProperties2; IClone symbol = d.Symbol as IClone; symbolCollectionClass.AddSymbol(symbol.Clone() as ISymbol, string.Concat(annotateLayerProperty.Class, " ", i.ToString()), out symbolIdentifier2); d.SymbolID = symbolIdentifier2.ID; } } annotateLayerProperty = null; d = null; IGraphicsLayerScale graphicsLayerScaleClass = new GraphicsLayerScale(); if (imap_0.ReferenceScale != 0) { graphicsLayerScaleClass.ReferenceScale = imap_0.ReferenceScale; } else { try { graphicsLayerScaleClass.ReferenceScale = imap_0.MapScale; } catch (Exception exception) { Logger.Current.Error("", exception, null); } } graphicsLayerScaleClass.Units = imap_0.MapUnits; IFeatureClassDescription annotationFeatureClassDescriptionClass = new AnnotationFeatureClassDescription() as IFeatureClassDescription; IFields requiredFields = (annotationFeatureClassDescriptionClass as IObjectClassDescription).RequiredFields; IField field = requiredFields.Field[ requiredFields.FindField(annotationFeatureClassDescriptionClass.ShapeFieldName)]; IGeometryDefEdit geometryDef = field.GeometryDef as IGeometryDefEdit; geometryDef.SpatialReference_2 = geoDataset.SpatialReference; IOverposterProperties overposterProperties = (imap_0 as IMapOverposter).OverposterProperties; IAnnotationLayer annotationLayer = fDOGraphicsLayerFactoryClass.CreateAnnotationLayer(workspace as IFeatureWorkspace, featureClass.FeatureDataset, string_0, geometryDef, null, annotateLayerPropertiesCollectionClass, graphicsLayerScaleClass, symbolCollectionClass as ISymbolCollection, true, true, false, true, overposterProperties, ""); (annotationLayer as IGraphicsLayer).Activate(imap0.ScreenDisplay); for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++) { annotateLayerPropertiesCollectionClass.QueryItem(i, out annotateLayerProperty, out elementCollection, out elementCollection1); if (annotateLayerProperty != null) { annotateLayerProperty.FeatureLayer = ilayer0; annotateLayerProperty.GraphicsContainer = annotationLayer as IGraphicsContainer; annotateLayerProperty.AddUnplacedToGraphicsContainer = true; annotateLayerProperty.CreateUnplacedElements = true; annotateLayerProperty.DisplayAnnotation = true; annotateLayerProperty.FeatureLinked = true; annotateLayerProperty.LabelWhichFeatures = esriLabelWhichFeatures.esriAllFeatures; annotateLayerProperty.UseOutput = true; d = annotateLayerProperty as ILabelEngineLayerProperties2; d.SymbolID = i; d.AnnotationClassID = i; (d.OverposterLayerProperties as IOverposterLayerProperties2).TagUnplaced = true; } } annotateLayerPropertiesCollectionClass.Sort(); IAnnotateMapProperties annotateMapPropertiesClass = new AnnotateMapProperties() { AnnotateLayerPropertiesCollection = annotateLayerPropertiesCollectionClass }; ITrackCancel cancelTrackerClass = new CancelTracker(); (imap_0.AnnotationEngine as IAnnotateMap2).Label(overposterProperties, annotateMapPropertiesClass, imap_0, cancelTrackerClass); for (i = 0; i < annotateLayerPropertiesCollectionClass.Count; i++) { annotateLayerPropertiesCollectionClass.QueryItem(i, out annotateLayerProperty, out elementCollection, out elementCollection1); if (annotateLayerProperty != null) { annotateLayerProperty.FeatureLayer = null; } } imap_0.AddLayer(annotationLayer as ILayer); ilayer0.DisplayAnnotation = false; imap0.Refresh(); } } }