/// <summary>
/// 锚点方式文本标注
/// </summary>
/// <param name="axMapControl1"></param>
/// <param name="str"></param>
/// <param name="bcx"></param>
/// <param name="bcy"></param>
/// <param name="bcColor"></param>
/// <param name="txtx"></param>
/// <param name="txty"></param>
/// <param name="txtColor"></param>
public static void CreateTextElment(AxMapControl axMapControl1, string str, double bcx, double bcy, IRgbColor bcColor, double txtx, double txty, IRgbColor txtColor)
{
IPoint pPoint = new PointClass();
IMap pMap = axMapControl1.Map;
IActiveView pActiveView = pMap as IActiveView;
IGraphicsContainer pGraphicsContainer;
IElement pTElement = new TextElementClass();
pGraphicsContainer = (IGraphicsContainer)pActiveView;
IFormattedTextSymbol pTextSymbol = new TextSymbol();
IBalloonCallout pBalloonCallout = CreateBalloonCallout(bcx, bcy, bcColor);
pTextSymbol.Color = txtColor;
ITextBackground pTextBackground;
pTextBackground = (ITextBackground)pBalloonCallout;
pTextSymbol.Background = pTextBackground;
((ITextElement)pTElement).Symbol = pTextSymbol;
((ITextElement)pTElement).Text = str;
pPoint.X = txtx ;
pPoint.Y = txty ;
pTElement.Geometry = pPoint;
pGraphicsContainer.AddElement(pTElement, 1);
IEnvelope m_Envelope = new EnvelopeClass();
pTElement.QueryBounds(axMapControl1.ActiveView.ScreenDisplay as IDisplay, m_Envelope);//获得pTelement的包络线
#region 控制气泡牵引线
if (pPoint.X > axMapControl1.ActiveView.Extent.XMax - m_Envelope.Width - m_Envelope.Width / 8)//右边越界
{
if (pPoint.Y < axMapControl1.ActiveView.Extent.YMin + m_Envelope.Height)
{
//气泡方向正左
pPoint.X = txtx - (m_Envelope.XMax - txtx) - m_Envelope.Width / 8;
pPoint.Y = txty + txty - m_Envelope.YMin ;
}
else if (pPoint.Y > axMapControl1.ActiveView.Extent.YMax -m_Envelope.Height)
{
//气泡方向正左
pPoint.X = txtx - (m_Envelope.XMax - txtx) - m_Envelope.Width / 8;
pPoint.Y = txty - (m_Envelope.YMax - txty);
}
else
{
//气泡方向正左
pPoint.X = txtx - (m_Envelope.XMax - txtx) - m_Envelope.Width / 8;
pPoint.Y = txty - (m_Envelope.YMax - txty);
}
}
else if (pPoint.X<axMapControl1.ActiveView.Extent.XMin+(txtx-m_Envelope.XMin))//左边越界
{
if (pPoint.Y < axMapControl1.ActiveView.Extent.YMin + m_Envelope.Height)
{
//气泡方向正右
pPoint.X = txtx + (txtx - m_Envelope.XMin) + m_Envelope.Width / 8;
pPoint.Y = txty + txty - m_Envelope.YMin;
}
else if (pPoint.Y > axMapControl1.ActiveView.Extent.YMax - m_Envelope.Height)
{
//气泡方向正右
pPoint.X = txtx + (txtx - m_Envelope.XMin) + m_Envelope.Width / 8;
pPoint.Y = txty - (m_Envelope.YMax - txty);
}
else
{
//气泡方向正右
pPoint.X = txtx + (txtx - m_Envelope.XMin) + m_Envelope.Width / 8;
pPoint.Y = txty - (m_Envelope.YMax - txty);
}
}
else
{
if(pPoint.Y < axMapControl1.ActiveView.Extent.YMin + m_Envelope.Height)
{
//气泡方向正右
pPoint.X = txtx + (txtx - m_Envelope.XMin) + m_Envelope.Width / 8;
pPoint.Y = txty + txty - m_Envelope.YMin;
}
else if (pPoint.Y > axMapControl1.ActiveView.Extent.YMax - m_Envelope.Height)
{
//气泡方向正右
pPoint.X = txtx + (txtx - m_Envelope.XMin) + m_Envelope.Width / 8;
pPoint.Y = txty - (m_Envelope.YMax - txty);
}
else
{
//气泡方向正右
pPoint.X = txtx + (txtx - m_Envelope.XMin) + m_Envelope.Width / 8;
pPoint.Y = txty - (m_Envelope.YMax - txty);
}
}
pTElement.Geometry = pPoint;
#endregion
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}