AE中创建文本要素和气泡式要素

时间:2013-5-7    作者:悬浮的青春    分类: gis二次开发


 


//********创建文本元素***********

        public void CreateTextElment(double x, double y)
        {
            ESRI.ArcGIS.Geometry.IPoint pPoint = new PointClass();

            IMap pMap = axMapControl1.Map;

            IActiveView pActiveView = pMap as IActiveView;

            IGraphicsContainer pGraphicsContainer;

            IElement pElement = new MarkerElementClass();

            IElement pTElement = new TextElementClass();

            pGraphicsContainer = (IGraphicsContainer)pActiveView;
            pGraphicsContainer.DeleteAllElements();
            pPoint.PutCoords(x, y);//创建点要素

            pElement.Geometry = pPoint;

            //pGraphicsContainer.AddElement(pElement, 1);

            IFormattedTextSymbol pTextSymbol = new TextSymbolClass();//文本符号

            IBalloonCallout pBalloonCallout = CreateBalloonCallout(x, y);//利用创建气泡的方法

            IRgbColor pColor = new RgbColorClass();

            pColor.Red = 200;

            pColor.Green = 0;

            pColor.Blue = 0;

            pTextSymbol.Color = pColor;

            ITextBackground pTextBackground;

            pTextBackground = (ITextBackground)pBalloonCallout;

            pTextSymbol.Background = pTextBackground;

            ((ITextElement)pTElement).Symbol = pTextSymbol;
            IFeatureLayer pFeatureLyr = new FeatureLayerClass();
            pFeatureLyr = (IFeatureLayer)pMap.get_Layer(0);//要查询的图层
            pFeatureLyr.DisplayField = "NAME";//要展示的字段
            //
            pFeatureLyr.ShowTips = true;
            //axMapControl1.ShowMapTips = true;

            ((ITextElement)pTElement).Text = pFeatureLyr.get_TipText(x, y, 0.0001);//文本的位置
            pPoint.X = x + 0.00001;

            pPoint.Y = y + 0.00001;

            pTElement.Geometry = pPoint;

            pGraphicsContainer.AddElement(pTElement, 1);//添加元素

            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);//刷新

        }

   //********CreateBalloonCallout**************//创建气泡的方法
        public IBalloonCallout CreateBalloonCallout(double x, double y)
        {
            IRgbColor pRgbClr = new RgbColorClass();
            pRgbClr.Red = 255;
            pRgbClr.Blue = 255;
            pRgbClr.Green = 255;
            ISimpleFillSymbol pSmplFill = new SimpleFillSymbolClass();//填充符号
            pSmplFill.Color = pRgbClr;
            pSmplFill.Style = esriSimpleFillStyle.esriSFSSolid;
            IBalloonCallout pBllnCallout = new BalloonCalloutClass();//气泡
            pBllnCallout.Style = esriBalloonCalloutStyle.esriBCSRectangle;
            pBllnCallout.Symbol = pSmplFill;
            pBllnCallout.LeaderTolerance = 1;//容差

            ESRI.ArcGIS.Geometry.IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass();

            pPoint.X = x;

            pPoint.Y = y;

            pBllnCallout.AnchorPoint = pPoint;//锚点位置

            return pBllnCallout;

        }


经过以上。就可以简单实现气泡标识展示要素内容了

标签: arcgis二次开发

WRITTEN BY

avatar

推荐阅读: