#region 生成点的三种方法
/// <summary>
/// 1.直接在mapcontrol视窗中画点,不能常驻
/// </summary>
private void DrawPoint()
{
//获得当前活动范围
IActiveView pActiveView = axMapControl1.ActiveView;
//开始画笔
pActiveView.ScreenDisplay.StartDrawing(pActiveView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
IPoint pPoint;
//定义简单marker元素的标志
ISimpleMarkerSymbol pSymbol = new SimpleMarkerSymbolClass();
//设置颜色
IRgbColor pRGBcolor = new RgbColorClass();
pRGBcolor.Red = 255;
pRGBcolor.Green = 255;
pRGBcolor.Blue = 0;
pSymbol.Color = pRGBcolor;
//形状为圆形
pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
pSymbol.Size = 15;
pSymbol.Angle = 270;
//最后实现的时候要用ISymbol来实现,所以还是要做个转换
ISymbol pPointSymbol = pSymbol as ISymbol;
//该点是用来设置坐标的
pPoint = new PointClass();
pPoint.PutCoords(300, 300);
pActiveView.ScreenDisplay.SetSymbol((ISymbol)pPointSymbol);
pActiveView.ScreenDisplay.DrawPoint(pPoint);
//结束画笔
pActiveView.ScreenDisplay.UpdateWindow();
pActiveView.ScreenDisplay.FinishDrawing();
}
/// <summary>
/// 2.用element画点
/// </summary>
private void DrawPointElement(TopologyElement.Point p)
{
//首先要实现容器接口
IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
pGraphicsContainer.DeleteAllElements();//清空容器里面所有的元素
//设置点的坐标
IPoint pPoint = new PointClass();
//pPoint.PutCoords(310, 310);
//pPoint.PutCoords(310, 310);
//pPoint.PutCoords(440475, 4655187);
pPoint.X = p.X;
pPoint.Y = p.Y;
pPoint.X = 122.280739;
pPoint.Y = 42.0464883;
int forx = 0;
int fory = 0;
ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = axMapControl1.ActiveView.ScreenDisplay;
ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;
displayTransformation.FromMapPoint(pPoint, out forx, out fory);//输出的forx,fory为屏幕坐标
//pPoint = this.axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(440475, 4655187);
//pPoint.PutCoords(pPoint.X,pPoint.Y);
//pPoint.PutCoords(122.280739, 42.0464883);
//int x, y;
//axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(pPoint, out x, out y);
//axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(440475, 4655187);
//IMarkerElement用来获得symbol属性
IMarkerElement pMarkerElement = new MarkerElementClass();
//用ISimpleMarkerSymbol来设置点的属性
ISimpleMarkerSymbol pSymbol = new SimpleMarkerSymbolClass();
IRgbColor pRGBcolor = new RgbColorClass();
//设置颜色的时候使用计算机RGB
//红色
//pRGBcolor.Red = 255;
//pRGBcolor.Green = 0;
//pRGBcolor.Blue = 0;
//黑色
pRGBcolor.Red = 0;
pRGBcolor.Green = 0;
pRGBcolor.Blue = 0;
//pRGBcolor.NullColor = true;
pSymbol.Color = pRGBcolor;//红色
//pSymbol.Color = pRGBcolor;//红色
pMarkerElement.Symbol = pSymbol;
//IElement用来获得Geometry属性
IElement pElement = pMarkerElement as IElement;
//把IPoint转换为为IGeoMetry也能实现
//IGeometry pGeometry = pPoint as IGeometry;
//pElement.Geometry = pGeometry;
pElement.Geometry = pPoint;
//在容器里添加元素
pGraphicsContainer.AddElement(pElement, 0);
pElement.Activate(axMapControl1.ActiveView.ScreenDisplay);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null);
}