Mapgis选择要素
class RectSelectTool : GISBasTool { //地图视图控件 MapControl mapCtrl; //交互工具:选择工具控件 public SelectTool selTool; //选择数据时的数据类型过滤 SelectDataType dataType; //查询选择方式:圆选择、多边形选择、矩形选择 SelectType selectType; /// <summary> /// 实现矩形查询 /// </summary> /// <param name="control">地图视图控件</param> /// <param name="seltype">查询选择方式:矩形查询 </param> /// <param name="selOp"> /// <param name="type"></param> public RectSelectTool(MapControl mapControl, SelectType seltype, SelectDataType type) : base() { //初始化 this.mapCtrl = mapControl; this.dataType = type; this.selectType = seltype; //查询选择项 SelectOption selOpt = new SelectOption(); selOpt.DataType = dataType; //选择数据时的类型过滤类型 selOpt.SelMode = SelectMode.Multiply; //选择模式 selOpt.UnMode = UnionMode.Copy; //结果数据合并模式 selOpt.LayerCtrl = SelectLayerControl.Visible; //选择数据时的图层过滤类型 //创建矩形交互工具 selTool = new SelectTool(mapControl, selectType, selOpt, SpaQueryMode.Intersect, mapControl.Transformation); selTool.Selected += new SelectTool.SelectHandler(selTool_Selected); this.Active += new ToolEventHandler(RectSelectTool_Active); this.Unactive += new ToolEventHandler(RectSelectTool_Unactive); this.Cancel += new ToolEventHandler(RectSelectTool_Cancel); this.PreRefresh += new ToolEventHandler(RectSelectTool_PreRefresh); this.PostRefresh += new ToolEventHandler(RectSelectTool_PostRefresh); } //public void SetQery #region 事件响应实现 void RectSelectTool_Active(object sender, ToolEventArgs e) { this.mapCtrl.Cursor = Cursors.Cross; this.selTool.Start(); } void RectSelectTool_Unactive(object sender, ToolEventArgs e) { this.mapCtrl.Cursor = Cursors.Default; this.selTool.Pause(); } void RectSelectTool_Cancel(object sender, ToolEventArgs e) { this.selTool.Cancel(); } void RectSelectTool_PreRefresh(object sender, ToolEventArgs e) { return; } void RectSelectTool_PostRefresh(object sender, ToolEventArgs e) { this.selTool.PostRefresh(); } #endregion #region 重写GISBasTool方法 public override int OnKeyDown(object sender, KeyEventArgs e) { return 0; } public override int OnKeyUp(object sender, KeyEventArgs e) { return 0; } public override int OnMouseDbClick(object sender, MouseEventArgs e) { return 0; } public override int OnMouseDown(object sender, MouseEventArgs e) { this.mapCtrl.EndFlash(); this.mapCtrl.ActiveMap.GetSelectSet().Clear(); this.selTool.OnMouseDown(sender, e); if (e.Button == MouseButtons.Left) { this.mapCtrl.Cursor = Cursors.Cross; } return 0; } public override int OnMouseMove(object sender, MouseEventArgs e) { this.selTool.OnMouseMove(sender, e); return 0; } public override int OnMouseUp(object sender, MouseEventArgs e) { this.selTool.OnMouseUp(sender, e); return 0; } public override int OnMouseWheel(object sender, MouseEventArgs e) { return 0; } public override int OnContextMenu(int X, int Y) { return 0; } #endregion #region SelectTool的Selected事件响应 public void selTool_Selected(object sender, SelectEventArgs e) { } public void selTool_Selected0(object sender, SelectEventArgs e) { //MessageBox.Show("ok"); List<IVectorCls> selClsList = null;//查询图层列表 List<RecordSet> rcdSetList = null; //对应图层的结果集列表 if (e.SelSet != null) { //闪烁选择集 this.mapCtrl.FlashSelectSet(); //获取查询结果信息 GetSelectSetCount(e.SelSet, out selClsList, out rcdSetList); //显示选中图元的参数 if (selClsList.Count > 0 && rcdSetList.Count > 0) { GeomInfo geomInfo = null; RecordSet rcdSet = rcdSetList[0]; rcdSet.MoveFirst(); long oid = rcdSet.CurrentID; geomInfo = selClsList[0].GetInfo(oid); EditGeomInfoForm geomInfoForm = new EditGeomInfoForm((VectorLayer)null, geomInfo); if (oid > 0) { if (geomInfoForm.ShowDialog() == DialogResult.OK) { if (dataType == SelectDataType.Ann) { AnnotationCls ancls = selClsList[0] as AnnotationCls; IGeometry geo = null; Record rcd = null; GeomInfo tempInfo = null; ancls.Get(oid, out geo, out rcd, out tempInfo); TextAnno textAnno = geo as TextAnno; textAnno.SetAnnInfo(geomInfo as AnnInfo); ancls.Update(oid, geo, rcd, tempInfo); } else { selClsList[0].UpdateInfo(oid, geomInfo); } } this.mapCtrl.EndFlash(); } } }/*end of if (e.SelSet != null)*/ this.mapCtrl.Refresh(); } #endregion /// <summary> /// 获取查询结果信息 /// </summary> /// <param name="set">选择集对象</param> /// <param name="selClsList">查询图层列表</param> /// <param name="rcdSetList">对应图层的结果集列表</param> public void GetSelectSetCount(SelectSet set, out List<IVectorCls> selClsList, out List<RecordSet> rcdSetList) { //记录符合选择项的ids ObjectIDs oids = new ObjectIDs(); ObjectID oid = new ObjectID(); selClsList = new List<IVectorCls>(); rcdSetList = new List<RecordSet>(); //获取选择集列表 List<SelectSetItem> selSetList = set.Get(); if (selSetList == null || selSetList.Count == 0) return; for (int i = 0; i < selSetList.Count; i++) { //获取图层 MapLayer maplayer = selSetList[i].Layer; //获取处于编辑状态第一个图层的要素ID列表 List<long> oidList = selSetList[i].IDList; //获取图层对应的类的信息 IVectorCls selCls = maplayer.GetData() as IVectorCls; oids = new ObjectIDs(); for (int id = 0; id < oidList.Count; id++) { oid.Int64Val = oidList[id]; oids.Append(oid); } //获取结果集 RecordSet rcdSet = new RecordSet(selCls); rcdSet.AddSet(oids); //记录图层和结果集 selClsList.Add(selCls); rcdSetList.Add(rcdSet); } return; } }
本博有部分内容来自网络,如有问题请联系:hebeilijianghua@qq.com,并注明来自博客园。