engine的工具中实现Snapping(捕捉)
在Engine的工具(ITool)里:
OnClick事件处理函数中:
首先需要获取一个图层,作为Snapping的参照,
IFeatureLayer targetLayer
然后声明一个IMovePointFeedBack作为鼠标移动时捕捉点的显示:
IMovePointFeedback m_pMovePtFeed = new MovePointFeedback();
mFeedback = (IDisplayFeedback)m_pMovePtFeed;
ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
IRgbColor pRGBColor = new RgbColorClass();
pRGBColor.Red = ;
pRGBColor.Green = ;
pRGBColor.Blue = ;
simpleMarkerSymbol.Color = pRGBColor;
simpleMarkerSymbol.Size = ;
simpleMarkerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSSquare;
ISymbol symbol = simpleMarkerSymbol as ISymbol;
symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
//symbol.ROP2 = esriRasterOpCode.;
m_pMovePtFeed.Symbol = (ISymbol)simpleMarkerSymbol;
然后, 开始Feedback的显示(tmpPoint是指开始的点,其实影响不大,如果不想要源点在屏幕上的话,可以取一个在屏幕外的点):
m_pMovePtFeed.Display = mMapControl.ActiveView.ScreenDisplay;
m_pMovePtFeed.Start(tmpPoint, tmpPoint);
在OnMouseMove事件中:
IPoint pPoint2 = null;
IPoint pPoint = pMap.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
pPoint2 = Snapping(pPoint.X, pPoint.Y, targetLayer, pMap, );
if (pPoint2 == null)
pPoint2 = pPoint;
((IMovePointFeedback)mFeedback).MoveTo(pPoint2);
其中Snapping函数即为最主要的查找函数,其功能为根据输入的点坐标在目标图层上查找最为相近的点(也即需要捕捉的点),返回该点,若没有找到则返回NULL,最后一个参数的含义是,在地图控件上,以多少个像素为单位在周边查找捕捉点.
public IPoint Snapping(double x, double y, IFeatureLayer iFeatureLyr, IMapControl3 axMapControl1,double snappingDis)
{
IPoint iHitPoint = null;
IMap iMap = axMapControl1.Map;
IActiveView iView = axMapControl1.ActiveView;
IFeatureClass iFClss = iFeatureLyr.FeatureClass;
IPoint point = new PointClass();
point.PutCoords(x, y);
double length = ConvertPixelsToMapUnits(axMapControl1.ActiveView, snappingDis);
ITopologicalOperator pTopo = point as ITopologicalOperator;
IGeometry pGeometry = pTopo.Buffer(length).Envelope as IGeometry;
ISpatialFilter spatialFilter = new SpatialFilterClass();
spatialFilter.GeometryField = iFeatureLyr.FeatureClass.ShapeFieldName;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
spatialFilter.Geometry = pGeometry;
IFeatureCursor cursor = iFClss.Search(spatialFilter, false);
IFeature iF = cursor.NextFeature();
if (iF == null) return null;
IPoint iHitPt = new ESRI.ArcGIS.Geometry.Point();
IHitTest iHitTest = iF.Shape as IHitTest;
double hitDist = ;
int partIndex = ;
int vertexIndex = ;
bool bVertexHit = false;
// Tolerance in pixels for line hits
double tol = ConvertPixelsToMapUnits(iView, snappingDis);
if (iHitTest.HitTest(point, tol, esriGeometryHitPartType.esriGeometryPartBoundary,
iHitPt, ref hitDist, ref partIndex, ref vertexIndex, ref bVertexHit))
{
iHitPoint = iHitPt;
}
//axMapControl1.ActiveView.Refresh();
return iHitPoint;
}
public double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
{
double realWorldDisplayExtent;
int pixelExtent;
double sizeOfOnePixel;
pixelExtent = pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame().right - pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame().left;
realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;
return pixelUnits * sizeOfOnePixel;
}
此时即可实现鼠标实时地捕捉目标图层上的对象,若需要获取当前位置的捕捉点时,则可以在相应事件(例如OnMouseDown或OnDbClick)中调用:
IPoint pPoint = ((IMovePointFeedback)mFeedback).Stop();
这时实时捕捉将会停止,若需要重新开始捕捉,则在之后调用这些语句即可:
//重新开始Snap
IPoint tmpPoint = new PointClass();
tmpPoint.PutCoords(pMap.Extent.XMin - , pMap.Extent.YMin - );
IMovePointFeedback m_pMovePtFeed = (IMovePointFeedback)mFeedback;
m_pMovePtFeed.Display = pMap.ActiveView.ScreenDisplay;
m_pMovePtFeed.Start(tmpPoint, tmpPoint);
engine的工具中实现Snapping(捕捉)的更多相关文章
- 使用chrome开发者工具中的network面板测量网站网络性能
前面的话 Chrome 开发者工具是一套内置于Google Chrome中的Web开发和调试工具,可用来对网站进行迭代.调试和分析.使用 Network 面板测量网站网络性能.本文将详细介绍chrom ...
- F12 开发人员工具中的控制台错误消息
使用此参考解释显示在 Internet Explorer 11 的控制台 和调试程序中的错误消息. 简介 使用 F12 开发人员工具进行调试时,错误消息(例如 EC7111 或 HTML1114)将显 ...
- Linux Netcat 命令——网络工具中的瑞士军刀
原文:http://www.oschina.net/translate/linux-netcat-command netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他 ...
- 【译】在 Chrome 开发者工具中调试 node.js
原文链接 : Debugging Node.js in Chrome DevTools 原文作者 : MATT DESLAURIERS 译文出自 : 掘金翻译计划 译文链接 : https://git ...
- 如何在视频处理控件TVideoGrabber中设置音频捕捉设备
TVideoGrabber不仅可以捕捉视频,还可以作为多媒体播放器,并支持包括C#..NET.VB.NET.C++.Delphi.C++Builder和ActiveX平台,本文将剖析TVideoGra ...
- 在listener或者工具中使用spring容器中的bean实例
在项目中经常遇见需要在Listener中或者工具中使用Spring容器中的bean实例,由于bean不能在stataic的类中使用. 介绍一种方式: public class SpringTool { ...
- 详解WPF Blend工具中的复合路径功能 ( 含路径标记语法 )
写此文章的目的是为了简单分析一下 Blend工具中提供的"复合路径"功能.有人在我的博文中留言问我复合路径的问题. 稍微琢磨一下,觉得应该是对的.因此贴出来和大家分享.有不对的说 ...
- Mysql编辑工具中使用(Navicat查询结果显示行号)
Mysql编辑工具中使用(Navicat查询结果显示行号) as rownum,a.roleId ) t where a.roleId='admin';
- Analyze 静态分析工具中显示 大量的CF类型指针 内存leak 问题, Core Foundation 类型指针内存泄漏
Analyze 静态分析工具中显示 大量的CF类型指针 内存leak 问题 今天使用Analyze 看了下项目, 解决办法,项目中使用了ARC,OC的指针类型我们完全不考虑release的问题 ...
随机推荐
- substring和substr的用法
substring 方法用于提取字符串中介于两个指定下标之间的字符 substring(start,end) 开始和结束的位置,从零开始的索引 返回值是一个新的字符串,该字符串值包含 stringOb ...
- windows 查看某个端口号被占用情况
1.查看3798端口是否被占用,以及占用端口的进程PID netstat -ano |findstr 3798 C:\Users\zhaojingbo>netstat -ano|findstr ...
- after I see Little Dorrit
也许是我太追名逐利,所以我不肯承认自己花费了大把的时间看电影,通过写博客好像自己从中感悟到了什么,好像看电影也是一种学习的方式. 也许是我平静自内心的方式,我太忙于玩或者学习,甚至没有机会非常沉静 一 ...
- 【资料目录收藏】.NET开发必看资料53个 经典源码77个
简单描述:为大家整理了下载中心.net资料,都是比较热的,好评率比较高的,做了一个可收藏的下载目录,希望大家喜欢~ 基于.net构架的留言板项目大全源码 http://down.51cto.com/z ...
- linux线程(二)内存释放
linux线程有两种模式joinable和unjoinable. joinable线程:系统会保存线程资源(栈.ID.退出状态等)直到线程退出并且被其他线程join. unjoinable线程:系统会 ...
- nginx提示No input file specified怎么办
用了网上提供的各种方法都不行,即便html能正常打开,php文件依然有问题.而后继续尝试了修改权限 chown -vR www:www /folder 功能都正常. nginx.conf 的 user ...
- 致命错误: Python.h:没有那个文件或目录
In file included from greenlet.c:5:0: greenlet.h:8:20: 致命错误: Python.h:没有那个文件或目录 编译中断. error: Setup s ...
- ACM俱乐部算法基础练习赛(1)
A: 水题 代码: #include<cstdio> #include<algorithm> using namespace std; ]; int n,m,c; int ma ...
- 李洪强漫谈iOS开发[C语言-028]-sizeof运算符
- Windows编程中的堆管理(过于底层,一般不用关心)
摘要: 本文主要对Windows内存管理中的堆管理技术进行讨论,并简要介绍了堆的创建.内存块的分配与再分配.堆的撤销以及new和delete操作符的使用等内容. 关键词: 堆:堆管理 1 引言 在大多 ...