基于ArcEngine二次开发的选择带橡皮筋平移工具

基于ArcEngine二次开发的选择带橡皮筋平移工具
去掉了单击居中的功能
主要采用了下面三个方法:
ScreenDisplay.PanStart(this.startPoint)
ScreenDisplay.PanMoveTo(movePoint);
ScreenDisplay.PanStop();

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using Galaxy.Common;
using Galaxy.Framework.MapEngine;
using Galaxy.MapEngine.Common;
using Galaxy.MapEngine.Core;
using Galaxy.Plugins.LandRearrangement.ADF;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Galaxy.Plugins.LandRearrangement.Commands
{
    public class SelectDKTool : MapTool
    {
        private IPoint startPoint = null;
        private IPoint endPoint = null;
        private bool isDown = false;
        private bool isMove = false;
        private bool isPanStart = false;
        //        
        private double cX;
        private double cY;
        //
        private Image img = null;
        public SelectDKTool()
        { 

        }

        private System.Windows.Forms.Cursor m_Cursor = Cursors.Default;
        public override System.Windows.Forms.Cursor Cursor
        {
            get
            {
                return this.m_Cursor;
            }
        }

        public override bool Deactivate()
        {            
            return true;
        }



        public override void OnMouseDown(int button, int shift, int x, int y)
        {
            try
            {
                base.OnMouseDown(button, shift, x, y);
                this.isDown = true;
                //清除原有选中要素
                IMap map = zzApp.mapView.MapControl.ActiveView.FocusMap;
                map.ClearSelection();
                //
                this.startPoint = zzApp.mapView.MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
                //
                this.cX = (zzApp.mapView.MapControl.ActiveView.Extent.XMax + zzApp.mapView.MapControl.ActiveView.Extent.XMin) / 2;
                this.cY = (zzApp.mapView.MapControl.ActiveView.Extent.YMax + zzApp.mapView.MapControl.ActiveView.Extent.YMin) / 2;
                //
                IFeatureLayer fLayer = zzApp.imageIdentiControl.currentLayer;
                //
                ISpatialFilter sf = new SpatialFilterClass();
                sf.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;
                sf.Geometry = this.startPoint;
                IFeatureCursor fCur = fLayer.Search(sf, false);
                IFeature feat = null;
                if (fCur != null)
                {
                    feat = fCur.NextFeature();
                    TokayWorkspace.ComRelease(fCur);
                    fCur = null;
                }
                if (feat != null)
                {
                    //显示属性值
                    zzApp.imageIdentiControl.SelectFeature(feat);
                    //选中要素
                    zzApp.mapView.MapControl.ActiveView.FocusMap.SelectFeature(fLayer, feat);
                }
                else
                {
                    zzApp.imageIdentiControl.SelectFeature(null);                    
                }
                //刷新显示
                zzApp.mapView.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, fLayer, zzApp.mapView.MapControl.ActiveView.Extent);
                
                //
            }
            catch (Exception ex)
            {
                MsgFactory.ShowError(ex.Message);
            }
        }
        

        public override void OnMouseMove(int button, int shift, int x, int y)
        {
            base.OnMouseMove(button, shift, x, y);

            if (this.isDown == true && this.isMove==false)
            {
                this.isMove = true;
                this.m_Cursor = Cursors.Hand;
                //平移开始点(有平移的橡皮筋效果)
                zzApp.mapView.MapControl.ActiveView.ScreenDisplay.PanStart(this.startPoint);
                this.isPanStart = true;

            }
            if(this.isDown==true && this.isMove==true)
            { 
                //平移
                IPoint movePoint = zzApp.mapView.MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
                zzApp.mapView.MapControl.ActiveView.ScreenDisplay.PanMoveTo(movePoint);
            }
        }

        public override void OnMouseUp(int button, int shift, int x, int y)
        {
            base.OnMouseUp(button, shift, x, y);
            if (this.isDown == true)
            {
                //this.panCustom(x, y);
                if (this.isPanStart == true && this.isMove == true)
                {
                    IPoint movePoint = zzApp.mapView.MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
                    zzApp.mapView.MapControl.ActiveView.ScreenDisplay.PanMoveTo(movePoint);
                    //
                    zzApp.mapView.MapControl.ActiveView.ScreenDisplay.PanStop();
                }
                //
                this.isDown = false;
                this.isMove = false;
                this.isPanStart = false;
                //
                this.m_Cursor = Cursors.Default;
            }
            //
        }
        private void panCustom(int x,int y)
        {
            this.endPoint = zzApp.mapView.MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
            //平移计算
            //计算偏移值
            double offsetX = this.endPoint.X - this.startPoint.X;
            double offsetY = this.endPoint.Y - this.startPoint.Y;
            //重新计算坐标
            IPoint centerPoint = new PointClass();
            centerPoint.X = this.cX - offsetX;
            centerPoint.Y = this.cY - offsetY;
            zzApp.mapView.MapControl.CenterAt(centerPoint);
            //            
        }

    }
}

你可能感兴趣的:(GIS相关,ArcGIS,Engine开发,笔记)