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的问题 ...
随机推荐
- 『奇葩问题集锦』function * (next){ 执行报错 SyntaxError: Unexpected token *
这是因为 app.use(function * (){ 语句中有一个 * ,这种方式被称为generator functions ,一般写作function *(){...} 的形式,在此类func ...
- JS 页面加载触发事件 document.ready和onload的区别(转)
原博地址:http://blog.163.com/zhaoyanping_1125/blog/static/20132915320111129113723710/ * document.ready和o ...
- PHP框架原理
本文主要来聊聊框架理论,但不针对任何一款框架,不过任何一款框架都离不开这个理论,首先我们了解下框架的来龙去脉,任何技术的出现都是为了解决某个问题,之前的博客有讲过smarty,其存在就是为了html和 ...
- php中mysqli 处理查询结果集的几个方法
最近对php查询mysql处理结果集的几个方法不太明白的地方查阅了资料,在此整理记下 Php使用mysqli_result类处理结果集有以下几种方法 fetch_all() 抓取所有的结果行并且以关联 ...
- ConfigParser---python
# !/usr/bin/python # Filename:tcfg.py import ConfigParser config = ConfigParser.ConfigParser() confi ...
- [GUIDE] How to install Scipy in Maya Windows 64 bit - Google 网上论坛 - Google Chrome
I've seen a lot of queries about getting scipy working in Maya (Windows 64 bit) with a few not 100% ...
- BZOJ 1052: [HAOI2007]覆盖问题
BZOJ 1052: [HAOI2007]覆盖问题 题意:给定平面上横纵坐标在-1e9~1e9内的20000个整数点的坐标,用三个大小相同边平行于坐标轴的正方形覆盖(在边界上的也算),问正方形的边长最 ...
- Asp.Net MVC 使用FileResult导出Excel数据文件
MVC实现Excel导出功能,今天来记录一下. 采取了最简单的方法.(转载) 用的是Html拼接成Table表格的方式,返回 FileResult 输出一个二进制的文件. 第一种:使用FileCo ...
- lua方法点(.)调用和冒号(:)调用区别:
用.定义方法时object.func_name(arg1,arg2...),方法真正的函数签名形式为: object.func_name(arg1, arg2...) 用:定义方法时object:fu ...
- 大数据量查询优化——数据库设计、SQL语句、JAVA编码
数据库设计方面: 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将 ...