Esempio n. 1
0
        /// <summary>
        /// 用maplex渲染图层注释
        /// </summary>
        /// <param name="pGeoFeatLyr"></param>
        /// <param name="annoField"></param>
        public static void annotateLayerMaplexPro(IGeoFeatureLayer pGeoFeatLyr, string annoField)
        {
            //如果Map没有用Maplex引擎,要先设置Map使用这个引擎
            //IAnnotateMap pAnnotateMap;
            //pAnnotateMap = new MaplexAnnotateMapClass();
            //pMap.AnnotationEngine = pAnnotateMap;

            IGeoFeatureLayer pGeoFeatLayer;

            pGeoFeatLayer = pGeoFeatLyr;
            IAnnotateLayerPropertiesCollection pAnnoProps;

            pAnnoProps = pGeoFeatLyr.AnnotationProperties;
            pAnnoProps.Clear();
            ILabelEngineLayerProperties2 pLabelEngine2 = new MaplexLabelEngineLayerPropertiesClass();

            pLabelEngine2.Expression = "[" + annoField + "]";

            IMaplexOverposterLayerProperties pMaplexPro = new MaplexOverposterLayerPropertiesClass();

            pMaplexPro.FeatureType                 = esriBasicOverposterFeatureType.esriOverposterPolygon;
            pMaplexPro.PolygonPlacementMethod      = esriMaplexPolygonPlacementMethod.esriMaplexHorizontalInPolygon;
            pMaplexPro.CanPlaceLabelOutsidePolygon = false;
            pMaplexPro.CanRemoveOverlappingLabel   = true;
            pMaplexPro.RepeatLabel                 = false;
            pMaplexPro.CanStackLabel               = true;


            pLabelEngine2.OverposterLayerProperties = pMaplexPro as IOverposterLayerProperties;
            //IMapOverposter pMapPos = axMapControl1.Map as IMapOverposter;
            //IOverposterProperties pOP = pMapPos.OverposterProperties;
            //IMaplexOverposterProperties pMaplexOP = pOP as IMaplexOverposterProperties;
            //pMaplexOP.LabelLargestPolygon = false;
            pAnnoProps.Add(pLabelEngine2 as IAnnotateLayerProperties);
            pGeoFeatLyr.DisplayAnnotation = true;
        }
Esempio n. 2
0
        /// <summary>
        /// //标注
        /// </summary>
        /// <param name="pGeoFeatLyr"></param>
        /// <param name="pMap"></param>
        /// <param name="annoField">字段名称</param>
        public static void Annotation(IGeoFeatureLayer pGeoFeatLyr, IMap pMap, string annoField,AxMapControl axMapControl1)
        {
            IAnnotateMap pAnnoMap=new AnnotateMapClass();
             //pAnnoMap = new MaplexAnnotateMapClass();
             pMap.AnnotationEngine = pAnnoMap;
             IGeoFeatureLayer pGeoFeatLayer;
             pGeoFeatLayer = pGeoFeatLyr;
             IAnnotateLayerPropertiesCollection pAnnoProps;
             pAnnoProps = pGeoFeatLyr.AnnotationProperties;
             pAnnoProps.Clear();
             ILabelEngineLayerProperties2 pLabelEngine2 = new MaplexLabelEngineLayerPropertiesClass();
             pLabelEngine2.Expression = "[" + annoField + "]";

             IMaplexOverposterLayerProperties pMaplexPro = new MaplexOverposterLayerPropertiesClass();
             pMaplexPro.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
             pMaplexPro.PolygonPlacementMethod = esriMaplexPolygonPlacementMethod.esriMaplexHorizontalInPolygon;
             pMaplexPro.CanPlaceLabelOutsidePolygon = false;
             pMaplexPro.CanRemoveOverlappingLabel = false;
             pMaplexPro.RepeatLabel = false;
             pLabelEngine2.OverposterLayerProperties = pMaplexPro as IOverposterLayerProperties;
             IMapOverposter pMapPos = axMapControl1.Map as IMapOverposter;
             IOverposterProperties pOP = pMapPos.OverposterProperties;
             IMaplexOverposterProperties pMaplexOP = pOP as IMaplexOverposterProperties;
             pMaplexOP.LabelLargestPolygon = false;
             pAnnoProps.Add(pLabelEngine2 as IAnnotateLayerProperties);
             pGeoFeatLyr.DisplayAnnotation = true;
        }
Esempio n. 3
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;
        }