Пример #1
0
        /// <summary>
        /// 创建几何图形对应的用于高亮显示的元素
        /// </summary>
        /// <param name="geometry"></param>
        /// <returns></returns>
        private static IElement CreateHightLightElement(IGeometry geometry)
        {
            IElement element   = null;
            IColor   redcolor  = ColorCreate.GetIColor(255, 0, 0, 50);
            IColor   bluecolor = ColorCreate.GetIColor(0, 0, 255);

            switch (geometry.GeometryType)
            {
            case esriGeometryType.esriGeometryLine:
            case esriGeometryType.esriGeometryPolyline:
                element          = new LineElementClass();
                element.Geometry = geometry;
                ((ILineElement)element).Symbol = SymbolCreate.GetSimpleLineSymbol(redcolor);
                break;

            case esriGeometryType.esriGeometryPolygon:
                element          = new PolygonElementClass();
                element.Geometry = geometry;
                ((PolygonElementClass)element).Symbol = SymbolCreate.GetSimpleFillSymbol(redcolor, bluecolor);
                break;

            case esriGeometryType.esriGeometryPoint:
                element          = new MarkerElementClass();
                element.Geometry = geometry;
                IMarkerSymbol pisymbol = new SimpleMarkerSymbolClass();
                pisymbol.Color = (IColor)redcolor;
                pisymbol.Size  = 6;
                ((MarkerElementClass)element).Symbol = pisymbol;
                break;
            }
            return(element);
        }
Пример #2
0
        /// <summary>
        /// 显示指定图层指定字段的标注
        /// </summary>
        /// <param name="geoLayer">要设置注标注的图层(IFeatureLayer as IGeoFeatureLayer)</param>
        /// <param name="fieldName">显示标注的字段</param>
        /// <param name="fontName">标注的字体</param>
        /// <param name="size">标注的大小</param>
        public static void ShowLabel(this IGeoFeatureLayer geoLayer, string fieldName, string fontName = "宋体", int size = 12)
        {
            //标注属性集
            IAnnotateLayerPropertiesCollection annotateLyrProColl = geoLayer.AnnotationProperties;

            annotateLyrProColl.Clear();

            //普通标准属性(另一个是Maplex标准属性)
            ILabelEngineLayerProperties labelEngine = new LabelEngineLayerPropertiesClass();

            labelEngine.Expression = $"[{fieldName}]";

            //字体
            IFontDisp fontDisp = new StdFont()
            {
                Name = fontName, Bold = false
            } as IFontDisp;

            //标注符号
            ITextSymbol textSymbol = new TextSymbolClass();

            textSymbol.Color   = ColorCreate.GetIColor(0, 0, 0);
            textSymbol.Font    = fontDisp;
            textSymbol.Size    = size;
            labelEngine.Symbol = textSymbol;

            //设置同名标注:默认为移除同名标注,应设为每个要素放置一个标注
            IBasicOverposterLayerProperties basicOverpLyrPro = labelEngine.BasicOverposterLayerProperties as IBasicOverposterLayerProperties;

            basicOverpLyrPro.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape;//每个要素放置一个标注

            annotateLyrProColl.Add(labelEngine as IAnnotateLayerProperties);
            geoLayer.DisplayAnnotation = true;
        }