Quantcast
Channel: Forums - ArcObjects SDKs
Viewing all articles
Browse latest Browse all 1374

add AnnotationLayer to map

$
0
0
I have a FileGeoDatabase with a AnnotationFeatureClass (within 3 AnnotationClasses) that I programmatically want to load to my map. First I load the FeatureClass in order to get some Informations and then while creating the AnnotationLayer an error occurs. I've used some code from the Esri-help, but what could be wrong?
Code:

Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                        IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                        ws = workspaceFactory.OpenFromFile(pGdbSource.Dir + "\\" + pGdbSource.File, 0);
               
                if (ws != null)
                {
                        IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)ws;
                        IFeatureLayer featureLayer = new FeatureLayerClass();
                        string FCName = (pGdbSource.BrowseName != "") ? pGdbSource.BrowseName : pGdbSource.ItemName;
                        featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(FCName);
                        ILayer layer = (ILayer)featureLayer;
                        if ((featureLayer.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) &&
                            (featureLayer is FeatureLayerClass))
                        {
                            // Get the GeometryDef from the feature class's shape field.
                            String shapeFieldName = featureLayer.FeatureClass.ShapeFieldName;
                            int shapeFieldIndex = featureLayer.FeatureClass.FindField(shapeFieldName);
                            IFields fields = featureLayer.FeatureClass.Fields;
                            IField shapeField = fields.get_Field(shapeFieldIndex);
                            IGeometryDef geometryDef = shapeField.GeometryDef;

                            IAnnotateLayerPropertiesCollection annotateLayerPropsCollection = (featureLayer as FeatureLayerClass).AnnotationProperties;

                            // Create a graphics layer scale object.
                            IGraphicsLayerScale graphicsLayerScale = new GraphicsLayerScaleClass();
                            try
                            {
                                graphicsLayerScale.ReferenceScale = mxDocument.ActiveView.FocusMap.MapScale;
                            }
                            catch (Exception ex) { graphicsLayerScale.ReferenceScale = 0.0; }
                            graphicsLayerScale.Units = mxDocument.ActiveView.FocusMap.MapUnits;

                            // Create the overposter properties for the standard label engine.
                            IOverposterProperties overposterProperties = new BasicOverposterPropertiesClass();

                            ISymbolCollection symbolCollection = new SymbolCollectionClass();
                            ISymbolCollection2 symbolCollection2 = (ISymbolCollection2)symbolCollection;

                            // Create the annotation layer factory.
                            IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass();

                            IDataset pDataset = (featureLayer as FeatureLayerClass) as IDataset;

                            // Create the annotation feature class and an annotation layer for it.
                            IAnnotationLayer annotationLayer = annotationLayerFactory.CreateAnnotationLayer
                                (featureWorkspace, pDataset as IFeatureDataset, FCName,
                                geometryDef, null,
                                annotateLayerPropsCollection, graphicsLayerScale, symbolCollection, false,
                                false, false, true, overposterProperties, "configKeyword");

                            // Get the feature class from the feature layer.
                            featureLayer = (IFeatureLayer)annotationLayer;

Thanks for any suggestions!

Viewing all articles
Browse latest Browse all 1374

Latest Images

Trending Articles



Latest Images