目录
完整项目下载:https://download.csdn.net/download/qq_40323256/10865950
画点:
IPoint pt = axMapControl1.ToMapPoint(e.x, e.y);
IMap pMap = axMapControl1.Map;
IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
IActiveView pActiveView = axMapControl1.ActiveView;
IMarkerElement pMarkerElement = new MarkerElementClass();
IElement pElement = pMarkerElement as IElement;
pElement.Geometry = pt;
pGraphicsContainer.AddElement((IElement)pMarkerElement, 0);
pActiveView.Refresh();
画线:
IMap pMap = axMapControl1.Map;
IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;
IGeometry polyline;
polyline = axMapControl1.TrackLine();
ILineElement pLineElement;
pLineElement = new LineElementClass();
IElement pElement;
pElement = pLineElement as IElement;
pElement.Geometry = polyline;
pGraphicsContainer = pMap as IGraphicsContainer;
pGraphicsContainer.AddElement((IElement)pLineElement, 0);
pActiveView.Refresh();
画面:
IMap pMap = axMapControl1.Map;
IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
IActiveView pActiveView = axMapControl1.ActiveView;
IGeometry Polygon = axMapControl1.TrackPolygon();
IPolygonElement PolygonElement = new PolygonElementClass();
IElement pElement = PolygonElement as IElement;
pElement.Geometry = Polygon;
pGraphicsContainer.AddElement((IElement)PolygonElement, 0);
pActiveView.Refresh();
画文字符号:
IActiveView activeView = axMapControl1.ActiveView;
ITextSymbol pTextSymbol;
pTextSymbol = new TextSymbolClass();
pTextSymbol.Size = 10;
stdole.IFontDisp pFont;
//pFont = new stdole.StdFontClass() as stdole.IFontDisp;
//pFont.Name = "黑体";
//pTextSymbol.Font = pFont;
pTextSymbol.Color.RGB = 255;
ITextElement pTextElement = new TextElementClass();
pTextElement.Text = "李疆";
pTextElement.Symbol = pTextSymbol;
IElement pEle;
pEle = pTextElement as IElement;
IPoint pt = new PointClass();
pt = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
pEle.Geometry = pt;
IGraphicsContainer pGraphicsContainer = axMapControl1.Map as IGraphicsContainer;
pGraphicsContainer.AddElement(pEle, 0);
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
右键弹出“取消编辑”内容框
public partial class Form1 : Form
{
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (e.button == 1)
{
switch (edit)
{
case "point":
{
IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;
IMap pMap = axMapControl1.Map;
IPoint pt;
pt = axMapControl1.ToMapPoint(e.x, e.y);
IMarkerElement pMarkerElement;
pMarkerElement = new MarkerElementClass();
IElement pElement;
pElement = pMarkerElement as IElement;
pElement.Geometry = pt;
pGraphicsContainer = pMap as IGraphicsContainer;
pGraphicsContainer.AddElement((IElement)pMarkerElement, 0);
pActiveView.Refresh();
break;
}
case "line":
{
IMap pMap = axMapControl1.Map;
IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;
IGeometry polyline;
polyline = axMapControl1.TrackLine();
ILineElement pLineElement;
pLineElement = new LineElementClass();
IElement pElement;
pElement = pLineElement as IElement;
pElement.Geometry = polyline;
pGraphicsContainer = pMap as IGraphicsContainer;
pGraphicsContainer.AddElement((IElement)pLineElement, 0);
pActiveView.Refresh();
break;
}
case "polygon":
{
IMap pMap = axMapControl1.Map;
IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;
IGeometry Polygon;
Polygon = axMapControl1.TrackPolygon();
IPolygonElement PolygonElement;
PolygonElement = new PolygonElementClass();
IElement pElement;
pElement = PolygonElement as IElement;
pElement.Geometry = Polygon;
pGraphicsContainer = pMap as IGraphicsContainer;
pGraphicsContainer.AddElement((IElement)PolygonElement, 0);
pActiveView.Refresh();
break;
}
default:
break;
}
}
IToolbarMenu mapPopMenu = null;
mapPopMenu = new ToolbarMenu();//这个很关键,主要应用SDK封装的工具类似于C#的OpenDialog
if (e.button == 2)
{
mapPopMenu.AddItem(new StopEditlalala(), -1, 0, false, esriCommandStyles.esriCommandStyleIconAndText);
mapPopMenu.AddItem(new ControlsMapFullExtentCommand(), -1, 1, false, esriCommandStyles.esriCommandStyleIconAndText);
mapPopMenu.SetHook(axMapControl1); 得到地图视窗右键菜单
mapPopMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);//弹出显示菜单
}
}
}
public class StopEditlalala : BaseCommand
{
private IMapControl3 m_mapControl;
public StopEditlalala()
{
base.m_caption = "停止编辑!!!";
}
public override void OnClick()
{
if (Form1.edit == "")
{
MessageBox.Show("没有正在编辑的内容!");
return;
}
Form1.edit = "";
MessageBox.Show("已结束编辑!");
}
public override void OnCreate(object hook)
{
m_mapControl = (IMapControl3)hook;
}
}