Ejemplo n.º 1
0
        /// <summary>
        /// 将地图上指定图层的标注转注记,存储在地图中
        /// (保存在地图上的注记是IGraphicsLayer->IGraphicsContainer->IElement)
        /// </summary>
        /// <param name="map">执行标注转注记的地图</param>
        /// <param name="geoFeatureLayer">需要将标注转注记的图层(注意这些图层必须是map中的图层)</param>
        /// <param name="whichFeatures">标示将哪些要素生成注记的枚举(所有要素/当前范围的要素/选择的要素)</param>
        public static void ConvertLabelsToMapAnnotation(this IMap map, IGeoFeatureLayer[] geoFeatureLayer,
                                                        esriLabelWhichFeatures whichFeatures = esriLabelWhichFeatures.esriVisibleFeatures)
        {
            IConvertLabelsToAnnotation convertLabelsToAnnotation = new ConvertLabelsToAnnotationClass();
            ITrackCancel trackCancel = new CancelTrackerClass();

            //设置标注转注记的参数:①地图、②注记存储位置(数据库注记/地图注记)、③哪些要素生成注记(所有要素/当前范围的要素/选择的要素)
            //④是否生成地位注记、⑥取消操作、⑦异常事件处理
            convertLabelsToAnnotation.Initialize(map, esriAnnotationStorageType.esriMapAnnotation,
                                                 whichFeatures, true, trackCancel, null);

            //添加要进行转换的图层
            for (int i = 0; i < geoFeatureLayer.Length; i++)
            {
                convertLabelsToAnnotation.AddFeatureLayer(geoFeatureLayer[i],
                                                          geoFeatureLayer[i].Name + "_Anno", null, null, false, false, false, false, true, "");
            }
            //执行转换,生成注记
            convertLabelsToAnnotation.ConvertLabels();

            //隐藏标注
            for (int i = 0; i < geoFeatureLayer.Length; i++)
            {
                geoFeatureLayer[i].DisplayAnnotation = false;
            }

            //刷新地图
            IActiveView activeView = map as IActiveView;

            activeView.Refresh();
        }
Ejemplo n.º 2
0
        private void ConvertLineAnnotation()
        {
            ILineLabelPosition pPosition = new LineLabelPositionClass();

            pPosition.Parallel = true;
            pPosition.Above    = checkedListBoxLineLabelPosition.Items[0].CheckState == CheckState.Checked;
            pPosition.InLine   = checkedListBoxLineLabelPosition.Items[1].CheckState == CheckState.Checked;
            pPosition.Below    = checkedListBoxLineLabelPosition.Items[2].CheckState == CheckState.Checked;

            IRgbColor rgbColor = new RgbColorClass();

            rgbColor.Red   = cmbSetAnnoLineColor.Color.R;
            rgbColor.Blue  = cmbSetAnnoLineColor.Color.B;
            rgbColor.Green = cmbSetAnnoLineColor.Color.G;

            esriBasicOverposterWeight labelWeight   = (esriBasicOverposterWeight)Enum.Parse(typeof(esriBasicOverposterWeight), radioGroupLineLabelWeight.EditValue.ToString());
            esriBasicOverposterWeight featureWeight = (esriBasicOverposterWeight)Enum.Parse(typeof(esriBasicOverposterWeight), radioGroupPointFeatureWeight.EditValue.ToString());
            esriLabelWhichFeatures    selectionType = (esriLabelWhichFeatures)Enum.Parse(typeof(esriLabelWhichFeatures), radioGroupSelectionType.EditValue.ToString());

            string expression = TxtLineExpression.Text;

            ConvertAnnotation(_context.FocusMap, _lineFeatureLayer, txtLineAno.Text, Convert.ToDouble(cboScale.Text), _workspace, pPosition, null,
                              labelWeight, featureWeight,
                              checkBoxLinePlaceOverlappingLabels.Checked == false, cmbSetAnnoLineFront.Text,
                              (double)numSetAnnoLineFrontSize.Value, rgbColor, expression, chbLineLinked.Checked, selectionType);
        }
Ejemplo n.º 3
0
        private void ConvertPointAnnotation()
        {
            IPointPlacementPriorities pointPlacementPriorities = new PointPlacementPrioritiesClass();

            pointPlacementPriorities.AboveLeft   = (int)numAboveLeft.Value;
            pointPlacementPriorities.AboveCenter = (int)numAboveCenter.Value;
            pointPlacementPriorities.AboveRight  = (int)numAboveRight.Value;
            pointPlacementPriorities.CenterRight = (int)numCenterRight.Value;
            pointPlacementPriorities.BelowRight  = (int)numBelowRight.Value;
            pointPlacementPriorities.BelowCenter = (int)numBelowCenter.Value;
            pointPlacementPriorities.BelowLeft   = (int)numBelowLeft.Value;
            pointPlacementPriorities.CenterLeft  = (int)numCenterLeft.Value;

            IRgbColor rgbColor = new RgbColorClass();

            rgbColor.Red   = cmbSetAnnoPointColor.Color.R;
            rgbColor.Blue  = cmbSetAnnoPointColor.Color.B;
            rgbColor.Green = cmbSetAnnoPointColor.Color.G;
            esriBasicOverposterWeight labelWeight   = (esriBasicOverposterWeight)Enum.Parse(typeof(esriBasicOverposterWeight), radioGroupPointLabelWeight.EditValue.ToString());
            esriBasicOverposterWeight featureWeight = (esriBasicOverposterWeight)Enum.Parse(typeof(esriBasicOverposterWeight), radioGroupPointFeatureWeight.EditValue.ToString());
            esriLabelWhichFeatures    selectionType = (esriLabelWhichFeatures)Enum.Parse(typeof(esriLabelWhichFeatures), radioGroupSelectionType.EditValue.ToString());

            string expression = TxtPointExpression.Text;

            ConvertAnnotation(_context.FocusMap, _pointFeatureLayer, txtPointAno.Text, Convert.ToDouble(cboScale.Text), _workspace, null,
                              pointPlacementPriorities, labelWeight, featureWeight,
                              checkBoxPointPlaceOverlappingLabels.Checked == false, cmbSetAnnoPointFront.Text,
                              (double)numSetAnnoPointFrontSize.Value, rgbColor, expression, chbPointLinked.Checked, selectionType);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  将地图上的标注转注记,生成注记图层存储在数据库中
        ///  (保存在数据库的注记图层是IFeatureClass/IFeatureLayer/IAnnotationLayer->IFeature as IAnnotationFeature.Annotation->IElement)
        /// </summary>
        /// <param name="map">执行标注转注记的地图</param>
        /// <param name="featureLinked">是否关联要素(关联要素的注记必须与其所关联的要素类存储在同一地理数据库中)</param>
        /// <param name="whichFeatures">标示哪些要素生成注记的枚举(所有要素/当前范围的要素/选择的要素)</param>
        /// <param name="outWorkspace">保存注记的工作空间</param>
        /// <param name="suffix">注记图层名称后缀</param>
        public static void ConvertLabelsToGdbAnnotationLayers(this IMap map, bool featureLinked    = false,
                                                              esriLabelWhichFeatures whichFeatures = esriLabelWhichFeatures.esriVisibleFeatures, IWorkspace outWorkspace = null, string suffix = "_Anno")
        {
            IConvertLabelsToAnnotation convertLabelsToAnnotation = new ConvertLabelsToAnnotationClass();
            ITrackCancel pTrackCancel = new CancelTrackerClass();

            //设置标注转注记的参数:①地图、②注记存储位置(数据库注记/地图注记)、③哪些要素生成注记(所有要素/当前范围的要素/选择的要素)
            //④是否生成地位注记、⑥取消操作、⑦异常事件处理
            convertLabelsToAnnotation.Initialize(map, esriAnnotationStorageType.esriDatabaseAnnotation,
                                                 whichFeatures, true, pTrackCancel, null);

            //添加要进行转换的图层
            IGeoFeatureLayer geoFeatureLayer;

            for (int i = 0; i < map.LayerCount; i++)
            {
                geoFeatureLayer = map.get_Layer(i) as IGeoFeatureLayer;
                if (geoFeatureLayer != null)
                {
                    IFeatureClass featureClass = geoFeatureLayer.FeatureClass;
                    IDataset      dataset      = featureClass as IDataset;

                    IFeatureWorkspace outFeatureWorkspace;
                    IFeatureDataset   featureDataset;
                    if (featureLinked)//关联要素时,生成的注记必须存储在原地理数据库数据集中
                    {
                        outFeatureWorkspace = dataset.Workspace as IFeatureWorkspace;
                        featureDataset      = featureClass.FeatureDataset;
                    }
                    else
                    {
                        outFeatureWorkspace = outWorkspace as IFeatureWorkspace;
                        featureDataset      = null;
                    }

                    convertLabelsToAnnotation.AddFeatureLayer(geoFeatureLayer, geoFeatureLayer.Name + suffix,
                                                              outFeatureWorkspace, featureDataset, featureLinked, false, false, true, true, "");
                }
            }

            //执行转换,生成注记
            convertLabelsToAnnotation.ConvertLabels();
            IEnumLayer enumLayer = convertLabelsToAnnotation.AnnoLayers;

            //隐藏标注
            for (int i = 0; i < map.LayerCount; i++)
            {
                geoFeatureLayer = map.get_Layer(i) as IGeoFeatureLayer;
                geoFeatureLayer.DisplayAnnotation = false;
            }

            //添加注记图层到地图中
            map.AddLayers(enumLayer, true);

            //刷新地图
            IActiveView pActiveView = map as IActiveView;

            pActiveView.Refresh();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 将地图上指定图层的标注转注记,存储在地图中
        /// (保存在地图上的注记是IGraphicsLayer->IGraphicsContainer->IElement)
        /// </summary>
        /// <param name="map">执行标注转注记的地图</param>
        /// <param name="layerIndexs">需要将标注转注记的图层索引(注意这些图层必须是map中的图层,索引不能超出范围)</param>
        /// <param name="whichFeatures">标示将哪些要素生成注记的枚举(所有要素/当前范围的要素/选择的要素)</param>
        public static void ConvertLabelsToMapAnnotation(this IMap map, int[] layerIndexs,
                                                        esriLabelWhichFeatures whichFeatures = esriLabelWhichFeatures.esriVisibleFeatures)
        {
            var geoFeatureLayers = new List <IGeoFeatureLayer>();

            for (int i = 0; i < layerIndexs.Length; i++)
            {
                if (map.get_Layer(i) is IGeoFeatureLayer geoFeatureLayer)
                {
                    geoFeatureLayers.Add(geoFeatureLayer);
                }
            }
            ConvertLabelsToMapAnnotation(map, geoFeatureLayers.ToArray(), whichFeatures);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 将地图上指定图层的标注转注记,存储在地图中
        /// (保存在地图上的注记是IGraphicsLayer->IGraphicsContainer->IElement)
        /// </summary>
        /// <param name="map">执行标注转注记的地图</param>
        /// <param name="layerNames">需要将标注转注记的图层名称</param>
        /// <param name="whichFeatures">标示将哪些要素生成注记的枚举(所有要素/当前范围的要素/选择的要素)</param>
        public static void ConvertLabelsToMapAnnotation(this IMap map, string[] layerNames,
                                                        esriLabelWhichFeatures whichFeatures = esriLabelWhichFeatures.esriVisibleFeatures)
        {
            var geoFeatureLayers = new List <IGeoFeatureLayer>();

            for (int i = 0; i < map.LayerCount; i++)
            {
                if (map.get_Layer(i) is IGeoFeatureLayer geoFeatureLayer && layerNames.Contains(geoFeatureLayer.Name))
                {
                    geoFeatureLayers.Add(geoFeatureLayer);
                }
            }
            ConvertLabelsToMapAnnotation(map, geoFeatureLayers.ToArray(), whichFeatures);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///  将指定图层的标注转注记,生成注记图层存储在数据库中
        ///  (保存在数据库的注记图层是IFeatureClass/IFeatureLayer/IAnnotationLayer->IFeature as IAnnotationFeature.Annotation->IElement)
        /// </summary>
        /// <param name="map">执行标注转注记的地图</param>
        /// <param name="layer">执行标注转注记的图层</param>
        /// <param name="featureLinked">是否关联要素(关联要素的注记必须与其所关联的要素类存储在同一地理数据库中)</param>
        /// <param name="whichFeatures"></param>
        /// <parparam name="whichFeatures">标示哪些要素生成注记的枚举(所有要素/当前范围的要素/选择的要素)</parparam>
        public static void ConvertLabelsToGdbAnnotationSingleLayer(this IMap map, ILayer layer, bool featureLinked = false,
                                                                   esriLabelWhichFeatures whichFeatures            = esriLabelWhichFeatures.esriVisibleFeatures)
        {
            IConvertLabelsToAnnotation convertLabelsToAnnotation = new ConvertLabelsToAnnotationClass();
            ITrackCancel pTrackCancel = new CancelTrackerClass();

            //设置标注转注记的参数:①地图、②注记存储位置(数据库注记/地图注记)、③哪些要素生成注记(所有要素/当前范围的要素/选择的要素)
            //④是否生成地位注记、⑥取消操作、⑦异常事件处理
            convertLabelsToAnnotation.Initialize(map, esriAnnotationStorageType.esriDatabaseAnnotation,
                                                 whichFeatures, true, pTrackCancel, null);

            IGeoFeatureLayer geoFeatureLayer = layer as IGeoFeatureLayer;

            if (geoFeatureLayer != null)
            {
                IFeatureClass     featureClass     = geoFeatureLayer.FeatureClass;
                IDataset          dataset          = featureClass as IDataset;
                IFeatureWorkspace featureWorkspace = dataset.Workspace as IFeatureWorkspace;
                try
                {
                    convertLabelsToAnnotation.AddFeatureLayer(geoFeatureLayer, geoFeatureLayer.Name + "_Anno",
                                                              featureWorkspace, featureClass.FeatureDataset, featureLinked, false, false, true, true, "");
                }
                catch (Exception ex) { throw new Exception("标注转注记操作出错:" + ex.ToString()); }

                //执行转换,生成注记
                convertLabelsToAnnotation.ConvertLabels();
                IEnumLayer enumLayer = convertLabelsToAnnotation.AnnoLayers;

                //隐藏标注
                geoFeatureLayer.DisplayAnnotation = false;

                //添加注记图层到地图中
                map.AddLayers(enumLayer, true);

                //刷新地图
                IActiveView pActiveView = map as IActiveView;
                pActiveView.Refresh();
            }
        }
Ejemplo n.º 8
0
        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();
            }
        }
Ejemplo n.º 9
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();
     }
 }
Ejemplo n.º 10
0
        private void ConvertAnnotation(IMap map, ILayer featureLayer, string annotationFeatureClassName, double scale,
                                       IWorkspace workspace, ILineLabelPosition lineLabelPosition,
                                       IPointPlacementPriorities pointPlacementPriorities,
                                       esriBasicOverposterWeight labelWeight, esriBasicOverposterWeight featureWeight, bool tagUnplaced,
                                       string fontName, double fontSize, IRgbColor rgbColor, string expression, bool featureLinked,
                                       esriLabelWhichFeatures labelWhichFeatures)
        {
            if (workspace.Type != esriWorkspaceType.esriFileSystemWorkspace && featureLayer is IGeoFeatureLayer)
            {
                IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;
                IAnnotateLayerPropertiesCollection annotateLayerPropertiesCollectionClass =
                    geoFeatureLayer.AnnotationProperties;
                annotateLayerPropertiesCollectionClass.Clear();
                ILabelEngineLayerProperties     labelEngineLayerProperties     = new LabelEngineLayerPropertiesClass();
                IBasicOverposterLayerProperties basicOverposterLayerProperties =
                    new BasicOverposterLayerPropertiesClass();
                if (lineLabelPosition != null)
                {
                    basicOverposterLayerProperties.LineLabelPosition = lineLabelPosition;
                }
                else if (pointPlacementPriorities != null)
                {
                    basicOverposterLayerProperties.PointPlacementPriorities = pointPlacementPriorities;
                }
                basicOverposterLayerProperties.LabelWeight   = labelWeight;
                basicOverposterLayerProperties.FeatureWeight = featureWeight;

                IOverposterLayerProperties2 overposterLayerProperties2 =
                    basicOverposterLayerProperties as IOverposterLayerProperties2;
                overposterLayerProperties2.TagUnplaced = tagUnplaced;

                labelEngineLayerProperties.BasicOverposterLayerProperties = basicOverposterLayerProperties;
                stdole.IFontDisp pFont = new stdole.StdFontClass() as stdole.IFontDisp;
                pFont.Name = fontName;
                ITextSymbol pTextSymbol = new TextSymbolClass();
                pTextSymbol.Size  = fontSize;
                pTextSymbol.Font  = pFont;
                pTextSymbol.Color = rgbColor;
                labelEngineLayerProperties.Symbol     = pTextSymbol;
                labelEngineLayerProperties.Expression = expression;

                IAnnotateLayerProperties annotateLayerProperties =
                    labelEngineLayerProperties as IAnnotateLayerProperties;
                annotateLayerProperties.DisplayAnnotation = true;

                IAnnotationLayer annotationLayer =
                    CommonHelper.GetLayerByFeatureClassName(_context.FocusMap, annotationFeatureClassName) as
                    IAnnotationLayer;
                CommonHelper.SetReferenceScale(annotationLayer, scale);
                annotateLayerProperties.FeatureLayer      = geoFeatureLayer;
                annotateLayerProperties.GraphicsContainer = annotationLayer as IGraphicsContainer;
                annotateLayerProperties.AddUnplacedToGraphicsContainer = true;
                annotateLayerProperties.CreateUnplacedElements         = true;
                annotateLayerProperties.DisplayAnnotation  = true;
                annotateLayerProperties.FeatureLinked      = featureLinked;
                annotateLayerProperties.LabelWhichFeatures = labelWhichFeatures;
                annotateLayerProperties.UseOutput          = true;
                annotateLayerPropertiesCollectionClass.Add(annotateLayerProperties);

                annotateLayerPropertiesCollectionClass.Sort();
                IAnnotateMapProperties annotateMapPropertiesClass = new AnnotateMapPropertiesClass()
                {
                    AnnotateLayerPropertiesCollection = annotateLayerPropertiesCollectionClass
                };
                ITrackCancel          cancelTrackerClass   = new CancelTrackerClass();
                IAnnotateMap2         annotateMap2         = map.AnnotationEngine as IAnnotateMap2;
                IOverposterProperties overposterProperties = (map as IMapOverposter).OverposterProperties;
                annotateMap2.Label(overposterProperties, annotateMapPropertiesClass, map, cancelTrackerClass);
                map.AddLayer(annotationLayer as ILayer);
                geoFeatureLayer.DisplayAnnotation = false;
                map.ReferenceScale = scale;
                map.MapScale       = scale;
                IActiveView activeView = map as IActiveView;
                activeView.Refresh();
            }
        }