ArcGIS engine中气泡标注的添加、修改!


ArcGIS engine中气泡标注,是我们在编辑图形中一个重要的工具,能提供注释功能,下面的介绍怎么来编程实现callout的添加,以及怎么去修改它们!

// 在Mapcontrol的mouseDown中添加下列内容,来添加气泡注释功能:callout.
 privatevoid axMapControl1_OnMouseDown(object sender,IMapControlEvents2_OnMouseDownEvent e)
        {
                    axMapControl1.CurrentTool = null;

                    IPoint pPoint ;
                    pPoint = new PointClass();
                    pPoint.PutCoords(e.mapX, e.mapY);
             

                    IFormattedTextSymbol pTextSymbol = newTextSymbolClass();
                 pTextSymbol.Background = CreateBalloonCallout(e.mapX, e.mapY) asITextBackground;
                    pTextSymbol.Direction =esriTextDirection.esriTDAngle;
                    pTextSymbol.Angle = 15;

                    ITextElement pTextElement = newTextElementClass();
                    pTextElement.Symbol = pTextSymbol asITextSymbol;


                    pTextElement.Text = "MaDeSheng";
                    IElement ptexte = pTextElement asIElement;
                    pPoint = new PointClass();
                    pPoint.PutCoords(e.mapX * 0.90, e.mapY*1.1);
                    ptexte.Geometry = pPoint as IGeometry;

                    IMap pMap = axMapControl1.Map;
                    IGraphicsContainer pGraphicsContainer = pMap asIGraphicsContainer;
                    pGraphicsContainer.AddElement(pTextElement asIElement, 0);
                    this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null, null);
}
红颜色的部分是产生气泡背景,具体程序如下:
public IBalloonCalloutCreateBalloonCallout(double x, double y)
      {

          IRgbColor pRgbClr = newRgbColorClass();
          pRgbClr.Red =225;
          pRgbClr.Blue =225;
          pRgbClr.Green =225;
          ISimpleFillSymbol pSmplFill =new SimpleFillSymbolClass();
          pSmplFill.Color =pRgbClr;
          pSmplFill.Style =esriSimpleFillStyle.esriSFSSolid;
          IBalloonCallout pBllnCallout= new BalloonCalloutClass();
          //pBllnCallout.Style =esriBalloonCalloutStyle.esriBCSRectangle;
          pBllnCallout.Style =esriBalloonCalloutStyle.esriBCSRoundedRectangle;
          pBllnCallout.Symbol =pSmplFill;
         
          pBllnCallout.LeaderTolerance= 5;
          IPoint pPoint = newESRI.ArcGIS.Geometry.PointClass();
          pPoint.X =x;
          pPoint.Y =y;
          pBllnCallout.AnchorPoint =pPoint;
          returnpBllnCallout;
      }

那么添加了之后如何修改呢?
双击事件!
  private void axMapControl1_OnDoubleClick(objectsender, IMapControlEvents2_OnDoubleClickEvent e)
        {
            if(e.button ==1)
            {
                //标注的修改
                if(((axMapControl1.CurrentTool) as ICommand).Name =="ControlToolsGraphicEleme nt_SelectTool")//这一句的判断很牛B,我当时考虑了半天才搞出来。难点呀!toolbarControl中要加载esriControls.ControlsSelectTool工具
                {
                    IPoint pPoint = new PointClass();
                    pPoint.PutCoords(e.mapX, e.mapY);

                    IMap pMap = axMapControl1.Map;
                    IGraphicsContainer pGraphicsContainer = pMap asIGraphicsContainer;
                    IEnumElement pEnumElement =pGraphicsContainer.LocateElements(pPoint, 10);
                    if (pEnumElement != null)
                    {
                        IElementpElement = pEnumElement.Next();
                        if(pElement is ITextElement)
                        {
                             
                            ITextElement ptextElement =pElement as ITextElement;

                        labelEditCallout pLabelEditCallout = newlabelEditCallout(ptextElement.Text,ptextElement.Symbol);
                            pLabelEditCallout.ShowDialog();

                            ptextElement.Text =pLabelEditCallout.inputText;
                            ptextElement.Symbol =pLabelEditCallout.textSymbol;
                             
                       pGraphicsContainer.DeleteElement(pElement);
                       pGraphicsContainer.AddElement(pElement,0);
                     //这两句可以用 pGraphicsContainer.UpdataElement(pElement);来代替
                            this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null, null);
                        }
                    }


                }
            }


        }

 labelEditCallout是我自己弄的一个修改样式,其实很简单的一个页面,截图如下:
ArcGIS <wbr>engine中气泡标注的添加、修改!

ArcGIS <wbr>engine中气泡标注的添加、修改!

具体,代码如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingESRI.ArcGIS.Display;
usingESRI.ArcGIS.Geometry;
namespaceEdit
{
   public partial class labelEditCallout :Form
   {
       publicstring inputText = "";
       publicITextSymbol textSymbol;
       privatebool ModifFillColor = false;
       publiclabelEditCallout(string s,ITextSymbol texSy)
      {
          inputText =s;
          textSymbol =texSy;
         InitializeComponent();
      }

       privatevoid labelEditCallout_Load(object sender, EventArgse)
      {

          textBox1.Text =inputText;
          comboBox1.Items.Add("矩形框");
          comboBox1.Items.Add("圆角矩形");
          //comboBox1.Items.Add("Oval");
          comboBox1.SelectedIndex = 1;

      }
       publicIColor ConvertColorToIColor(Color color)
      {

          IColor pColor = newRgbColorClass();

          pColor.RGB = color.B * 65536+ color.G * 256 + color.R;

          returnpColor;

      }
       privatevoid button2_Click(object sender, EventArgs e)
      {
          IBalloonCallout textBack =(((IFormattedTextSymbol)textSymbol).Background) asIBalloonCallout;
          IFillSymbol pOldFill =textBack.Symbol;
          IPoint pPoint =textBack.AnchorPoint;
         
          ISimpleFillSymbol pSmplFill =new SimpleFillSymbolClass();
          pSmplFill.Style =esriSimpleFillStyle.esriSFSSolid;
          if(ModifFillColor)
          {
             pSmplFill.Color =ConvertColorToIColor(this.button1.BackColor);
          }
          else
             pSmplFill.Color =pOldFill.Color;

         


          IBalloonCallout pBllnCallout= new BalloonCalloutClass();
          switch(comboBox1.Text)
          {
             case"矩形框":
                pBllnCallout.Style =esriBalloonCalloutStyle.esriBCSRectangle;
                break;
             case"圆角矩形":
                pBllnCallout.Style =esriBalloonCalloutStyle.esriBCSRoundedRectangle;
                break;
             //case"Oval":
             //   pBllnCallout.Style =esriBalloonCalloutStyle.esriBCSOval;
             //   break;
          }
         
          pBllnCallout.Symbol =pSmplFill;
          pBllnCallout.LeaderTolerance= 5;
          pBllnCallout.AnchorPoint =pPoint;


          IFormattedTextSymbolpTextSymbol = new TextSymbolClass();
          pTextSymbol.Direction =esriTextDirection.esriTDAngle;
          pTextSymbol.Angle =15;
          pTextSymbol.Background =pBllnCallout as ITextBackground;
         
         

          textSymbol = pTextSymbol asITextSymbol;

          inputText =textBox1.Text;
         this.Close();
      }

      //获取颜色
       privatevoid button1_Click(object sender, EventArgs e)
      {
          if(this.colorDialog.ShowDialog() ==DialogResult.OK)
          {
             this.button1.BackColor =this.colorDialog.Color;
             ModifFillColor = true;
          }

      }

       privatevoid button3_Click(object sender, EventArgs e)
      {
         this.Close();
      }

     
   }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值