ArcEngine开发 ——点击选择
来源:互联网 发布:mac自带的flash软件 编辑:程序博客网 时间:2024/06/05 17:18
实现了地图元素的点击选择如图)
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
int m_px = e.x;
int m_py = e.y;
IMap m_pMap = axMapControl1.Map;
ClickSelectFeature(ref m_pMap,m_px,m_py);
}
private void ClickSelectFeature( ref IMap m_pMap, int x,int y)
{
// get the layer
IFeatureLayer pFeatureLayer = m_pMap.get_Layer(0) as IFeatureLayer;
if (pFeatureLayer == null) return;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;//get the feature
if (pFeatureClass == null) return;
//get mouse position
IActiveView pActiveView = m_pMap as IActiveView;
IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
//Use a 4 pixel buffer around the cursor for feature search
double length;
length = ConvertPixelsToMapUnits(pActiveView, 4);
ITopologicalOperator pTopo = pPoint as ITopologicalOperator;
IGeometry pBuffer = pTopo.Buffer(length);//建立4个地图单位的缓冲区
IGeometry pGeometry = pBuffer.Envelope;//确定鼠标周围隐藏的选择框
//新建一个空间约束器
ISpatialFilter pSpatialFilter;
IQueryFilter pFilter;
//设置查询约束条件
pSpatialFilter = new SpatialFilter();
pSpatialFilter.Geometry = pGeometry;
switch (pFeatureClass.ShapeType)
{
case esriGeometryType.esriGeometryPoint:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
break;
case esriGeometryType.esriGeometryPolyline:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
break;
case esriGeometryType.esriGeometryPolygon:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
break;
default:
break;
}
pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
pFilter = pSpatialFilter;
//Do the Search 从图层中查询出满足约束条件的元素
IFeatureCursor pCursor = pFeatureLayer.Search(pFilter, false);
//select
IFeature pFeature = pCursor.NextFeature();
m_pMap.SelectFeature(pFeatureLayer, pFeature);
while (pFeature != null)
{
m_pMap.SelectFeature(pFeatureLayer, pFeature);
pFeature = pCursor.NextFeature();
}
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
private double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
{
// Uses the ratio of the size of the map in pixels to map units to do the conversion
IPoint p1 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperLeft;
IPoint p2 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperRight;
int x1, x2, y1, y2;
pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out x1, out y1);
pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p2, out x2, out y2);
double pixelExtent = x2 - x1;
double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
double sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;
return pixelUnits * sizeOfOnePixel;
}
- ArcEngine开发 ——点击选择
- ArcEngine开发——从TocControl上获取鼠标点击位置的信息(转载)
- ArcEngine开发——在64位操作系统下使用VS2010中开发ArcEngine应用程序的编译问题
- ArcEngine开发——在64位操作系统下使用VS2010中开发ArcEngine应用程序的编译问题
- ArcEngine开发——在64位操作系统下使用VS2010中开发ArcEngine应用程序的编译问题
- ArcEngine数据编辑--选择要素
- ArcEngine开发感想
- ArcEngine开发问题总结
- C#+ArcEngine开发笔记
- arcengine 开发经典帖
- ARCENGINE开发经典贴
- 常用ArcEngine开发代码
- ARCENGINE开发经典贴
- ARCENGINE开发经典贴
- Arcengine开发基础
- ArcEngine开发证书初始化
- ArcEngine开发--网络分析
- 初学arcengine——ICommand 用法
- ZenCart基本设置
- jmap + Eclipse MAT :排查内存泄漏的好工具
- POJ 1321 棋盘问题类似八皇后 dfs搜索
- 2010年02月《安全天下事之谷歌和百度的安全交汇点》
- 最小公倍数,最大公约数
- ArcEngine开发 ——点击选择
- 如何提高应用程序性能?
- 公式是怎样炼成的
- 经纬度距离的简化计算
- https客户端的实现(libcurl)
- css Hack技巧
- zen cart 一些细节修改
- WindowsX86 最新版JDK 6U23下载地址
- C#实现全局热键响应,失去焦点情况下响应全局快捷键的方法