小生 原文 ArcGIS engine中气泡标注的添加、修改!
你微微地笑着,不同我说什么话。而我觉得,为了这个,我已等待得久了。
——泰戈尔
喜欢看你微微的笑着,哪怕你一句话都不说,看见你笑,仿佛四季如春……笑,蕴含着着一种信任,一种安全,一种爱护,一种宽容,一种心灵的感应……宝贝,朝我笑笑,好么?
生活本已是一杯苦酒,我们何不笑着饮下?一颗感恩的心,一颗热爱生活的心,爱惜那些值得爱的人,一起欢乐,一起将各自生活的苦酒淡化,每天都让我们灿烂的笑……
不要认为后面还有更好的,因为现在拥有的就是最好的。不要因为距离太远而放弃,爱情可以和你一起坐火车的。不要因为对方不富裕而放弃,只要不是无能的人,勤劳可以让你们富裕的。不要因为父母反对而放弃,你会发现因为这个原因而反放弃的爱情,将是你一生的悔恨。其实对于爱情,越单纯越幸福。一生只谈一次恋爱是最好的,经历的太多了,会麻木;分离多了,会习惯;换恋人多了,会比较;到最后,你不会再相信爱情;你会自暴自弃;你会行尸走肉;你会与你不爱的人结婚,就这样过一辈子。
ArcGIS engine中气泡标注 ,是我们在编辑图形中一个重要的工具,能提供注释功能,下面的介绍怎么来编程实现callout的添加,以及怎么去修改它们!
// 在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, null, null); }
红颜色的部分是产生气泡背景,具体程序如下:
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; }
那么添加了之后如何修改呢?
双击事件!
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, null, null); } } } } }
labelEditCallout是我自己弄的一个修改样式,其实很简单的一个页面,截图如下:
具体,代码如下:
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(); } } }