private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { DevExpress.XtraEditors.Controls.EditorButton btn = e.Button; switch (btn.Caption) { case "定位": DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } int focusedRowHandle = this.gridView1.FocusedRowHandle; if (focusedRowHandle == -1) { return; } DataRow dr = this.gridView1.GetDataRow(focusedRowHandle); if (dr["geo"] != null && dr["Name"] != null && dr["fcName"] != null && dr["fc"] != null) { ISurfaceSymbol ss = new SurfaceSymbolClass(); ss.Color = 0xcc00ff00; ICurveSymbol cs = new CurveSymbolClass(); cs.Color = 0xff00ff00; cs.Width = -5; ss.BoundarySymbol = cs; ISimplePointSymbol ps = new SimplePointSymbol(); ps.Size = SystemInfo.Instance.SymbolSize; ps.FillColor = Convert.ToUInt32(SystemInfo.Instance.FillColor, 16); IGeometry objGeo = dr["geo"] as IGeometry; if (objGeo.GeometryType == gviGeometryType.gviGeometryModelPoint) { IModelPoint mp = objGeo as IModelPoint; IModelPointSymbol mps = new ModelPointSymbol(); mps.SetResourceDataSet((dr["fc"] as IFeatureClass).FeatureDataSet); mps.Color = 0xffffff00; IRenderModelPoint rMP = app.Current3DMapControl.ObjectManager.CreateRenderModelPoint(mp, mps, app.Current3DMapControl.ProjectTree.RootID); rMP.Glow(8000); app.Current3DMapControl.ObjectManager.DelayDelete(rMP.Guid, 8000); IGeometryFactory geoFact = new GeometryFactory(); IPoint pt = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pt.X = mp.X; pt.Y = mp.Y; pt.Z = mp.Z; ITableLabel tl = DrawTool.CreateTableLabel1(1); tl.TitleText = dr["fcName"].ToString(); tl.SetRecord(0, 0, dr["Name"].ToString()); tl.Position = pt; this._listRender.Add(tl.Guid); app.Current3DMapControl.Camera.FlyToObject(tl.Guid, gviActionCode.gviActionFlyTo); } } break; } }
/// <summary> /// 单击表格记录进行定位 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex]; if (row != null) { string fid = row.Cells["FID"].Value.ToString(); IFeatureClass fc = row.Cells["FID"].Tag as IFeatureClass; IModelPoint mp = rowMap[fid].Modelpoint; IModelPointSymbol symbol = new ModelPointSymbol(); symbol.SetResourceDataSet(fc.FeatureDataSet); IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, symbol, rootId); if (rmp != null) { //定位 this.axRenderControl1.Camera.FlyToObject(rmp.Guid, gviActionCode.gviActionJump); //闪烁 rmp.Glow(2000); this.axRenderControl1.ObjectManager.DelayDelete(rmp.Guid, 2000); } } }
/// <summary> /// 定位和闪烁 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView_MouseDoubleClick(object sender, MouseEventArgs e) { int featureId = int.Parse((sender as DataGridView).CurrentRow.Cells[0].Value.ToString()); IFeatureClass curFeatureClass = null; switch (tabControl1.SelectedTab.Name) { case "tabPage0Road": { foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Name == "Road") { curFeatureClass = fc; } } } break; case "tabPage1Building": { foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Name == "Building") { curFeatureClass = fc; } } } break; case "tabPage2Trees": { foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Name == "Trees") { curFeatureClass = fc; } } } break; case "tabPage3Facility": { foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Name == "Facility") { curFeatureClass = fc; } } } break; case "tabPage4LandScape": { foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Name == "Landscape") { curFeatureClass = fc; } } } break; } string filterString = string.Format("oid={0}", featureId); IQueryFilter filter = new QueryFilter(); filter.WhereClause = filterString; IFdeCursor cursor = null; try { cursor = curFeatureClass.Search(filter, true); if (cursor != null) { IRowBuffer fdeRow = null; if ((fdeRow = cursor.NextRow()) != null) { int nPos = fdeRow.FieldIndex("Geometry"); if (nPos != -1 && !fdeRow.IsNull(nPos)) { IModelPoint mp = fdeRow.GetValue(nPos) as IModelPoint; // 从库中读取值 IModelPointSymbol symbol = new ModelPointSymbol(); symbol.SetResourceDataSet(curFeatureClass.FeatureDataSet); IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, symbol, rootId); if (rmp != null) { // 定位 this.axRenderControl1.Camera.FlyToObject(rmp.Guid, gviActionCode.gviActionJump); // 闪烁 rmp.Glow(2000); this.axRenderControl1.ObjectManager.DelayDelete(rmp.Guid, 2000); } } } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { if (cursor != null) { //Marshal.ReleaseComObject(cursor); cursor = null; } } }