ArcEngine(六)用tool工具实现拉框放大缩小和平移

平移

	private void tool平移ToolStripMenuItem_Click(object sender, EventArgs e)
	{
	    	ESRI.ArcGIS.Controls.ControlsMapPanToolClass tool = new ControlsMapPanToolClass();
           	tool.OnCreate(MapControl.Object);
           	MapControl.CurrentTool = tool;
	}

拉框放大

	private void tool拉框放大ToolStripMenuItem_Click(object sender, EventArgs e)
	{	
	    	ESRI.ArcGIS.Controls.ControlsMapZoomInToolClass tool = new ControlsMapZoomInToolClass();
            	tool.OnCreate(MapControl.Object);
            	MapControl.CurrentTool = tool;
	}

拉框缩小

	private void tool拉框缩小ToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ESRI.ArcGIS.Controls.ControlsMapZoomOutToolClass tool = new ControlsMapZoomOutToolClass();
            	tool.OnCreate(MapControl.Object);
            	MapControl.CurrentTool = tool;
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
ArcEngine 中编写 ITool 工具获取鼠标框选内容,可以按照以下步骤进行: 1. 实现 ITool 接口,重写 OnMouseDown、OnMouseMove、OnMouseUp 等方法,以响应鼠标事件。 2. 在 OnMouseDown 方法中记录鼠标按下时的位置,并在 OnMouseUp 方法中记录鼠标抬起时的位置,计算出鼠标框选的矩形范围。 3. 在 OnMouseMove 方法中判断鼠标是否处于框选状态,如果是,则根据框选范围执行相应的操作,比如选择要素、高亮显示等。 4. 在 ITool 工具中可以通过 IMap 接口和 ISelection 接口来获取当前地图和选择集对象,从而实现对地图和图层上要素的操作。 以下是一个简单的示例代码: ```c# public class SelectionTool : ITool { private IMap m_map; private bool m_isSelecting; private IEnvelope m_selectionEnvelope; private ISelection m_selection; public void OnMouseDown(int button, int shift, int x, int y) { if (button == 1) { m_isSelecting = true; m_selectionEnvelope = new EnvelopeClass(); m_selectionEnvelope.XMin = x; m_selectionEnvelope.YMin = y; m_selectionEnvelope.XMax = x; m_selectionEnvelope.YMax = y; } } public void OnMouseMove(int button, int shift, int x, int y) { if (m_isSelecting) { m_selectionEnvelope.XMax = x; m_selectionEnvelope.YMax = y; IGeometry selectionGeometry = m_selectionEnvelope as IGeometry; m_map.SelectByShape(selectionGeometry, null, false); m_selection = m_map.FeatureSelection; m_map.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } } public void OnMouseUp(int button, int shift, int x, int y) { if (m_isSelecting) { m_isSelecting = false; m_selectionEnvelope.XMax = x; m_selectionEnvelope.YMax = y; IGeometry selectionGeometry = m_selectionEnvelope as IGeometry; m_map.SelectByShape(selectionGeometry, null, false); m_selection = m_map.FeatureSelection; m_map.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } } public void OnCreate(IMap map) { m_map = map; } public bool Enabled { get { return true; } } public int Cursor { get { return (int)esriSystemMouseCursor.esriSystemMouseCursorCrosshair; } } public void OnKeyDown(int keyCode, int shift) { } public void OnKeyUp(int keyCode, int shift) { } public string Name { get { return "SelectionTool"; } } public void OnDoubleClick() { } public void OnContextMenu(int x, int y) { } public void Refresh(int hDC) { } public void OnDeactivate() { } public int HelpContextID { get { return 0; } } public string HelpFile { get { return ""; } } public string Message { get { return "Use the mouse to select features."; } } public void OnActivate() { } public void OnFocus(int x, int y) { } public void OnBlur() { } } ``` 在上述代码中,我们实现了一个简单的 ITool 工具,用于在地图上进行鼠标框选,并将框选的要素进行选择。在 OnMouseMove 方法中,我们通过 IMap 接口的 SelectByShape 方法来进行要素选择,并通过 PartialRefresh 方法来更新地图的显示。在实际开发中,我们可以根据具体需求对代码进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稻田里展望者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值