Пример #1
0
        /// <summary>
        /// Adds the layer lable.
        /// </summary>
        /// <param name="pMap">The p map.</param>
        /// <param name="layer">The layer.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="pTextSymbol">The p text symbol.</param>
        /// <param name="dRefScale">The d reference scale.</param>
        public static void AddLayerLable(IMap pMap, ILayer layer, string fieldName, ITextSymbol pTextSymbol, double dRefScale)
        {
            IGeoFeatureLayer geoFeatureLayer = layer as IGeoFeatureLayer;
            IAnnotateLayerPropertiesCollection annotationProperties = geoFeatureLayer.AnnotationProperties;

            annotationProperties.Clear();
            ILineLabelPosition lineLabelPosition = new LineLabelPositionClass
            {
                Parallel      = false,
                Perpendicular = false,
                InLine        = true,
                OnTop         = true,
                Above         = false,
                Horizontal    = true
            };
            LineLabelPlacementPrioritiesClass lineLabelPlacementPrioritiesClass = new LineLabelPlacementPrioritiesClass();

            lineLabelPlacementPrioritiesClass.AboveStart = 5;
            lineLabelPlacementPrioritiesClass.BelowAfter = 4;
            IBasicOverposterLayerProperties basicOverposterLayerProperties = new BasicOverposterLayerPropertiesClass
            {
                LineLabelPosition = lineLabelPosition
            };
            ILabelEngineLayerProperties labelEngineLayerProperties;

            if (pMap.AnnotationEngine.Name.Equals("Esri Maplex Label Engine", System.StringComparison.CurrentCultureIgnoreCase))
            {
                labelEngineLayerProperties = new MaplexLabelEngineLayerPropertiesClass();
                IMaplexOverposterLayerProperties maplexOverposterLayerProperties = new MaplexOverposterLayerPropertiesClass();
                IFeatureLayer featureLayer = layer as IFeatureLayer;
                switch (featureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    maplexOverposterLayerProperties.FeatureType          = esriBasicOverposterFeatureType.esriOverposterPoint;
                    maplexOverposterLayerProperties.PointPlacementMethod = esriMaplexPointPlacementMethod.esriMaplexAroundPoint;
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    maplexOverposterLayerProperties.FeatureType         = esriBasicOverposterFeatureType.esriOverposterPolyline;
                    maplexOverposterLayerProperties.LinePlacementMethod = esriMaplexLinePlacementMethod.esriMaplexCenteredStraightOnLine;
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    maplexOverposterLayerProperties.FeatureType            = esriBasicOverposterFeatureType.esriOverposterPolygon;
                    maplexOverposterLayerProperties.PolygonPlacementMethod = esriMaplexPolygonPlacementMethod.esriMaplexHorizontalInPolygon;
                    break;
                }
                maplexOverposterLayerProperties.CanRemoveOverlappingLabel = false;
                maplexOverposterLayerProperties.RepeatLabel = false;
                (labelEngineLayerProperties as ILabelEngineLayerProperties2).OverposterLayerProperties = (maplexOverposterLayerProperties as IOverposterLayerProperties);
                IMapOverposter              mapOverposter              = pMap as IMapOverposter;
                IOverposterProperties       overposterProperties       = mapOverposter.OverposterProperties;
                IMaplexOverposterProperties maplexOverposterProperties = overposterProperties as IMaplexOverposterProperties;
                maplexOverposterProperties.LabelLargestPolygon = false;
            }
            else
            {
                labelEngineLayerProperties = new LabelEngineLayerPropertiesClass();
                labelEngineLayerProperties.BasicOverposterLayerProperties = basicOverposterLayerProperties;
            }
            labelEngineLayerProperties.Symbol             = pTextSymbol;
            labelEngineLayerProperties.IsExpressionSimple = true;
            labelEngineLayerProperties.Expression         = "[" + fieldName + "]";
            IAnnotateLayerProperties item = labelEngineLayerProperties as IAnnotateLayerProperties;

            if (dRefScale != -1.0)
            {
                IAnnotateLayerTransformationProperties annotateLayerTransformationProperties = labelEngineLayerProperties as IAnnotateLayerTransformationProperties;
                annotateLayerTransformationProperties.ReferenceScale = dRefScale;
            }
            annotationProperties.Add(item);
            geoFeatureLayer.DisplayAnnotation = true;
        }
Пример #2
0
 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();
     }
 }