C#+ARCENGINE问题!!!关于使用经纬度在图层上添加区域

cbwlsw 2016-09-22 09:53:02
public sealed class SearchArea : BaseTool
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);

//
// TODO: Add any COM registration code here
//
}

[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);

//
// TODO: Add any COM unregistration code here
//
}

#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Register(regKey);
ControlsCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Unregister(regKey);
ControlsCommands.Unregister(regKey);
}

#endregion
#endregion

private IHookHelper m_hookHelper = null;
private IFeature m_pSearchArea;//搜救区域对象
private ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
private INewPolygonFeedback m_pNewPolygonFeedback;
private IActiveView m_pAV;
private IScreenDisplay m_pScrD;
private IMap m_pMap;
private IPoint m_pPnt;
private IGeometry m_pGeometry;

public SearchArea()
{
//
// TODO: Define values for the public properties
//
base.m_category = ""; //localizable text
base.m_caption = ""; //localizable text
base.m_message = "This should work in ArcMap/MapControl/PageLayoutControl"; //localizable text
base.m_toolTip = ""; //localizable text
base.m_name = ""; //unique id, non-localizable (e.g. "MyCategory_MyTool")
try
{
//
// TODO: change resource name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}

#region Overridden Class Methods

/// <summary>
/// Occurs when this tool is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
try
{
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
if (m_hookHelper.ActiveView == null)
{
m_hookHelper = null;
}
}
catch
{
m_hookHelper = null;
}

if (m_hookHelper == null)
base.m_enabled = false;
else
base.m_enabled = true;

// TODO: Add other initialization code
}

private ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass
{
Color = new RgbColorClass { Red = 255, Green = 0, Blue = 0 },
Width = 2,
Style = esriSimpleLineStyle.esriSLSSolid
};


/// <summary>
/// Occurs when this tool is clicked
/// </summary>
public override void OnClick()
{
DataEditCommon.StartEditing("RESARE");
}



public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
try
{
ISimpleLineSymbol pSLnSym;
if (Button == 1)
{
//获取所画的视图
m_pAV = DataEditCommon.g_pMapControl.ActiveView;
m_pScrD = m_pAV.ScreenDisplay;
m_pMap = DataEditCommon.g_pMapControl.Map;
m_pPnt = m_pScrD.DisplayTransformation.ToMapPoint(X, Y);
//画面
if (m_pNewPolygonFeedback == null)
{
//this.m_cursor = new System.Windows.Forms.Cursor(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\polygon.cur");
m_pNewPolygonFeedback = new NewPolygonFeedbackClass();
IRgbColor pRGB = new RgbColorClass();
pSLnSym = (ISimpleLineSymbol)m_pNewPolygonFeedback.Symbol;
pRGB.Red = 255;
pSLnSym.Color = pRGB;
pSLnSym.Style = esriSimpleLineStyle.esriSLSSolid;
pSLnSym.Width = 2;
simpleFillSymbol.Outline = simpleLineSymbol;
m_pNewPolygonFeedback.Display = m_pScrD;
m_pNewPolygonFeedback.Start(m_pPnt);
}
else
{
m_pNewPolygonFeedback.AddPoint(m_pPnt);
}
}
}
catch (Exception ex)
{
}
}

public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
if (m_pNewPolygonFeedback != null)
{
m_pPnt = m_pScrD.DisplayTransformation.ToMapPoint(X, Y);
m_pNewPolygonFeedback.MoveTo(m_pPnt);
}
}

public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
// TODO: Add SearchArea.OnMouseUp implementation
}

public override void OnDblClick()
{
if (m_pGeometry == null)
{
m_pAV.Refresh();
}
m_pGeometry = m_pNewPolygonFeedback.Stop();
m_pGeometry.SpatialReference = m_pMap.SpatialReference;
//将画面添加到地图上
IPolygonElement pPolygonElement = new PolygonElementClass { Symbol = simpleFillSymbol };
var pEle = pPolygonElement as IElement;
pEle.Geometry = m_pGeometry;
ISimpleFillSymbol pSFSym;
var pElemFillShp = (IFillShapeElement)pEle;
pSFSym = new SimpleFillSymbolClass();
pSFSym.Style = esriSimpleFillStyle.esriSFSForwardDiagonal;
pElemFillShp.Symbol = pSFSym;
IFeatureLayer pFeatureLayer=(IFeatureLayer)DataEditCommon.g_pLayer;
m_pSearchArea = pFeatureLayer.FeatureClass.CreateFeature();
m_pSearchArea.Shape = m_pGeometry;
m_pSearchArea.Store();
base.OnDblClick();
}
#endregion
}
以上是在地图控件上添加区域的代码(基类),请问现在我加了个FORM,需要在这FORM上面输入经纬度,再通过按钮的CLICK事件完成直接在控件上添加区域的功能,请问这个CLICK事件如何写,要将上述代码做哪些改动?
请大神帮忙!!!
...全文
2401 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,141

社区成员

发帖
与我相关
我的任务
社区描述
它是一种特定的十分重要的空间信息系统。它是在计算机硬、软件系统支持下,对整个或部分地球表层(包括大气层)空间中的有关地理分布数据进行采集、储存、管理、运算、分析、显示和描述的技术系统。
社区管理员
  • 地理信息系统
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧