Arc Engine 中添加气泡提示框

一、在ArcMap中的定位操作

已知若干点的经纬度坐标,要求在地图中进行定位:

1.通过Tool 》Add X Y data 定位点,注意选择地理坐标系下的wgs 1984坐标系;

2.定位后的点不能执行查询、分析等操作,需要重新export data;

3.导出的数据最好转换成投影坐标,以便于计算。可首先把已知投影坐标的图层加载到地图中,然后加入第二步产生的点图层,然后将点图层export data,注意坐标系统选择“the data frame”

 

二、在ArcObject开发时定位的代码示例

2.1 代码参考1

 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
       
            if (i >= 3)//测试目的
                return;
            i++;

            ITextElement te = createTextElement(e.mapX,e.mapY,"魁x");
            axMapControl1.ActiveView.GraphicsContainer.AddElement(te as IElement, 1);
            axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);

    
        }
        int i;

        public IBalloonCallout createBalloonCallout(double x, double y)
        {
            IRgbColor rgb = new RgbColorClass();
            {
                rgb.Red = 255;
                rgb.Green = 255;
                rgb.Blue = 200;

            }
            ISimpleFillSymbol sfs = new SimpleFillSymbolClass();
            {
                sfs.Color = rgb;
                sfs.Style = esriSimpleFillStyle.esriSFSSolid;
            }

            IPoint p = new PointClass();
            {
                p.PutCoords(x, y);
            }

            IBalloonCallout bc = new BalloonCalloutClass();
            {
                bc.Style = esriBalloonCalloutStyle.esriBCSRoundedRectangle;
                //
                bc.Symbol = sfs;
                //
                bc.LeaderTolerance = 10;
                //1

                bc.AnchorPoint = p;
            }

            return bc;
        }

        public ITextElement createTextElement(double x, double y, string text)
        {
            IBalloonCallout bc = createBalloonCallout(x, y);
           
            IRgbColor rgb = new RgbColorClass();
            {
                //rgb.Red = 255;
                rgb.Green = 255;
            }
            ITextSymbol ts = new TextSymbolClass();
            {
                ts.Color = rgb;
            }

            IFormattedTextSymbol fts = ts as IFormattedTextSymbol;
            {
                fts.Background = bc as ITextBackground;
            }
            //fts.Size = 8;
            ts.Size = 8;

            IPoint point = new PointClass();
            {
                double width = axMapControl1.Extent.Width / 13;
                double height = axMapControl1.Extent.Height / 20;
                point.PutCoords(x + width, y + height);
            }

            ITextElement te = new TextElementClass();
            //IMarkerElement me = new MarkerElementClass();
            {
                te.Symbol = ts;
                //ts.Text = text;
                te.Text = text;
            }

            IElement e = te as IElement;
            {
                e.Geometry = point;
            }
            return te;

        }
    }
View Code

2.2 地图中添加label以标注地图

有多种方法:

1.使用TextElement

2.使用Label属性或与lyr文件或mxd文件结合进行标注

3.使用AnnotateLayerPropertiesCollection对象进行复杂标注

其中,第二种方法的代码为:

    private void AddLabel2Map(string strField)  
           {  
               IGeoFeatureLayer pGeoFeatureLayer;  
               ILineLabelPosition pLineLabelPosition;  
               ILabelEngineLayerProperties pLabelEngineLayerProperties;  
               IAnnotateLayerProperties pAnnotateLayerProperties;  
      
               pGeoFeatureLayer = (IGeoFeatureLayer)pMapControl.get_Layer(0);  
               pGeoFeatureLayer.AnnotationProperties.Clear();  
      
               pLineLabelPosition = new LineLabelPositionClass();  
               pLineLabelPosition.Above = false;  
               pLineLabelPosition.AtEnd = false;  
               pLineLabelPosition.Below = false;  
               pLineLabelPosition.Horizontal = false;  
               pLineLabelPosition.InLine = true;  
               pLineLabelPosition.OnTop = true;  
               pLineLabelPosition.Parallel = true;  
               pLineLabelPosition.ProduceCurvedLabels = true;  
      
               pLabelEngineLayerProperties = new LabelEngineLayerPropertiesClass();  
               pLabelEngineLayerProperties.Symbol = new TextSymbolClass();  
               pLabelEngineLayerProperties.IsExpressionSimple = true;  
               pLabelEngineLayerProperties.Expression = "[" + strField + "]";//需要中括号  
               pLabelEngineLayerProperties.BasicOverposterLayerProperties.LineLabelPosition = pLineLabelPosition;  
      
               pAnnotateLayerProperties = (IAnnotateLayerProperties)pLabelEngineLayerProperties;  
               pAnnotateLayerProperties.DisplayAnnotation = true;  
               pAnnotateLayerProperties.FeatureLayer = pGeoFeatureLayer;  
      
               pAnnotateLayerProperties.LabelWhichFeatures = esriLabelWhichFeatures.esriAllFeatures;  
               pAnnotateLayerProperties.WhereClause = "";  
      
               pGeoFeatureLayer.AnnotationProperties.Add(pAnnotateLayerProperties);  
               pGeoFeatureLayer.DisplayAnnotation = true;  
               pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);  
           }  
View Code

这种方法的一个简化是,在ArcMap中事先设定好图层标记的属性,保存为mxd或lyr文件,程序中只使用

pGeoFeatureLayer.DisplayAnnotation和pGeoFeatureLayer.DisplayField设定显示的字段以及是否显示。

在ArcMap中设定的一些细节为:

1.设定标记是否重复、是否每个图元一个标记、或每个图元的每一部分都有一个标记,如图:

2.如何设定label只保留两位小数,如图:

还可以设置其他更为丰富的格式。

参考文章

1. 风过 无痕.arcEngine经典代码-添加气泡提示框(标注,文本,). 2008-8.

2. 丛晓男. 在地图中添加label以标注地图. 2010-6.

原文地址:https://www.cnblogs.com/arxive/p/5882869.html