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的问题 ...
随机推荐
- 欢迎使用skymvc框架,简单易用的php框架
skymvc是一款轻量.简单易用的php mvc框架,经过多个项目实践改良. 特点: 1.mvc架构 2.m.v.c之间可以互相调用 3.简单的路由控制 R("/index.php" ...
- 【VB6 学习文档管理系统源码】
VB6写的一款笔记软件的源码,里面包含有很多窗体控件的使用技巧,比如MSHFlexgrid表格.TreeView的动态加载.Ado的增删改查等. 本软件提供对日常生活.工作中的学习笔记.图文并茂存储以 ...
- cygwin下的第一次编程记录
今天在window7上安装了cygwin,体验了一把unix,编了个小c,c++程序 先把过程记录下来 1.先删除以前建立的source文件夹 rm -rf source linux删除目录很简单,很 ...
- 2016030208 - sql50题练习题
数据库建表脚本和使用的数据请参考:http://www.cnblogs.com/zhtzyh2012/p/5235826.html sql50题练习参看:http://blog.sina.com.cn ...
- ipad在非viewport 1:1下缩放问题
1.最小会有980宽度,小于980应设置viewport 2.fix元素使用100%指定宽度时,默认会以min-width或980作为尺寸,可以选择给定与页面缩放时触发定宽来设置宽度,或设置设置bod ...
- 第 3 章 单例模式【Singleton Pattern】
以下内容出自:24种设计模式介绍与6大设计原则 这个模式是很有意思,而且比较简单,但是我还是要说因为它使用的是如此的广泛,如此的有人缘,单例就是单一.独苗的意思,那什么是独一份呢?你的思维是独一份,除 ...
- dynamic 使用
dynamic a = , B = }; Console.WriteLine("a.A=" + a.A); dynamic b = new Dictionary<string ...
- [wikioi]石子归并
http://wikioi.com/problem/1048/ 区间型动态规划.参考PPT:http://wenku.baidu.com/view/73c1ded5b9f3f90f76c61bc4.h ...
- haskell Types 和 Typeclasses
Algebraic Data Types 入门 在前面的章节中,我们谈了一些 Haskell 内置的类型和 Typeclass.而在本章中,我们将学习构造类型和 Typeclass 的方法. 我们已经 ...
- 【HDOJ】1031 Design T-Shirt
qsort直接排序. #include <stdio.h> #include <string.h> #include <stdlib.h> #define MAXN ...