许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  ArcEngine开发——点击选择要素功能实现

ArcEngine开发——点击选择要素功能实现

阅读数 14
点赞 0
article_banner

实现了 地图  元素的点击选择如图)

        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;

          }


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删

相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空