[转] ArcGIS engine中气泡标注的添加、修改

小生 原文 ArcGIS engine中气泡标注的添加、修改!

  你微微地笑着,不同我说什么话。而我觉得,为了这个,我已等待得久了。              

                                                                                                   ——泰戈尔
  喜欢看你微微的笑着,哪怕你一句话都不说,看见你笑,仿佛四季如春……笑,蕴含着着一种信任,一种安全,一种爱护,一种宽容,一种心灵的感应……宝贝,朝我笑笑,好么?
  生活本已是一杯苦酒,我们何不笑着饮下?一颗感恩的心,一颗热爱生活的心,爱惜那些值得爱的人,一起欢乐,一起将各自生活的苦酒淡化,每天都让我们灿烂的笑……
     
  不要认为后面还有更好的,因为现在拥有的就是最好的。不要因为距离太远而放弃,爱情可以和你一起坐火车的。不要因为对方不富裕而放弃,只要不是无能的人,勤劳可以让你们富裕的。不要因为父母反对而放弃,你会发现因为这个原因而反放弃的爱情,将是你一生的悔恨。其实对于爱情,越单纯越幸福。一生只谈一次恋爱是最好的,经历的太多了,会麻木;分离多了,会习惯;换恋人多了,会比较;到最后,你不会再相信爱情;你会自暴自弃;你会行尸走肉;你会与你不爱的人结婚,就这样过一辈子。
 
 
 

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

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//  在Mapcontrol的mouseDown中添加下列内容,来添加气泡注释功能:callout.
 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
                    axMapControl1.CurrentTool = null;
 
                    IPoint pPoint ;
                    pPoint = new PointClass();
                    pPoint.PutCoords(e.mapX, e.mapY);
             
 
                    IFormattedTextSymbol pTextSymbol = new TextSymbolClass();
                    pTextSymbol.Background = CreateBalloonCallout(e.mapX, e.mapY) as ITextBackground;
                    pTextSymbol.Direction = esriTextDirection.esriTDAngle;
                    pTextSymbol.Angle = 15;
 
                    ITextElement pTextElement = new TextElementClass();
                    pTextElement.Symbol = pTextSymbol as ITextSymbol;
 
 
                    pTextElement.Text = "MaDeSheng";
                    IElement ptexte = pTextElement as IElement;
                    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 as IGraphicsContainer;
                    pGraphicsContainer.AddElement(pTextElement as IElement, 0);
                    this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, nullnull);
}

 

 红颜色的部分是产生气泡背景,具体程序如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public IBalloonCallout CreateBalloonCallout(double x, double y)
        {
 
            IRgbColor pRgbClr = new RgbColorClass();
            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 = new ESRI.ArcGIS.Geometry.PointClass();
            pPoint.X = x;
            pPoint.Y = y;
            pBllnCallout.AnchorPoint = pPoint;
            return pBllnCallout;
        }

 

 

那么添加了之后如何修改呢?
双击事件!
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
private void axMapControl1_OnDoubleClick(object sender, IMapControlEvents2_OnDoubleClickEvent e)
        {
            if(e.button ==1)
            {
                //标注的修改
                if (((axMapControl1.CurrentTool) as ICommand).Name == "ControlToolsGraphicElement_SelectTool")//这一句的判断很牛B,我当时考虑了半天才搞出来。难点呀!toolbarControl中要加载esriControls.ControlsSelectTool工具
                {
                    IPoint pPoint = new PointClass();
                    pPoint.PutCoords(e.mapX, e.mapY);
 
                    IMap pMap = axMapControl1.Map;
                    IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
                    IEnumElement pEnumElement = pGraphicsContainer.LocateElements(pPoint, 10);
                    if (pEnumElement != null)
                    {
                        IElement pElement = pEnumElement.Next();
                        if (pElement is ITextElement)
                        {
                             
                            ITextElement ptextElement = pElement as ITextElement;
 
                            labelEditCallout pLabelEditCallout = new labelEditCallout(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, nullnull);
                        }
                    }
 
 
                }
            }
 
 
        }

 labelEditCallout是我自己弄的一个修改样式,其实很简单的一个页面,截图如下:

[转] ArcGIS engine中气泡标注的添加、修改  [转] ArcGIS engine中气泡标注的添加、修改 

体,代码如下:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
namespace Edit
{
    public partial class labelEditCallout : Form
    {
        public string inputText = "";
        public ITextSymbol textSymbol;
        private bool ModifFillColor = false;
        public labelEditCallout(string s,ITextSymbol texSy)
        {
            inputText = s;
            textSymbol = texSy;
            InitializeComponent();
        }
 
        private void labelEditCallout_Load(object sender, EventArgs e)
        {
 
            textBox1.Text = inputText;
             comboBox1.Items.Add("矩形框");
             comboBox1.Items.Add("圆角矩形");
             //comboBox1.Items.Add("Oval");
             comboBox1.SelectedIndex = 1;
 
        }
        public IColor ConvertColorToIColor(Color color)
        {
 
            IColor pColor = new RgbColorClass();
 
            pColor.RGB = color.B * 65536 + color.G * 256 + color.R;
 
            return pColor;
 
        }
        private void button2_Click(object sender, EventArgs e)
        {
            IBalloonCallout textBack = (((IFormattedTextSymbol)textSymbol).Background) as IBalloonCallout;
            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;
 
 
            IFormattedTextSymbol pTextSymbol = new TextSymbolClass();
            pTextSymbol.Direction = esriTextDirection.esriTDAngle;
            pTextSymbol.Angle = 15;
            pTextSymbol.Background = pBllnCallout as ITextBackground;
             
            
 
            textSymbol = pTextSymbol as ITextSymbol;
 
            inputText = textBox1.Text;
            this.Close();
        }
 
        //获取颜色
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.colorDialog.ShowDialog() == DialogResult.OK)
            {
                this.button1.BackColor = this.colorDialog.Color;
                ModifFillColor = true;
            }
 
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        
    }
}

 

 

 

 

 
 

 

 
 
 
 
没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的*、好奇、充满创造力的想法被现实的框架所束缚,让创造力*成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。



    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/5903508.html,如需转载请自行联系原作者


上一篇:break和continue | Python从入门到精通:入门篇之十九


下一篇:Confluence 6 配置草稿保存的时间