private void MainForm_Load(object sender, EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; this.axRenderControl1.Camera.FlyTime = 1; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "PolygonToBuilding.html"; } // 可视化Polygon类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polyline.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, true, "Polyline"); } //绑定事件 this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); this.axRenderControl1.InteractMode = gviInteractMode.gviInteractSelect; this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectAll; this.axRenderControl1.MouseSelectMode = gviMouseSelectMode.gviMouseSelectClick; }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 可视化Polygon类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polygon.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, true, "Polygon"); } if (gfactory == null) { gfactory = new GeometryFactory(); } geo1 = gfactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeNone) as IMultiPolygon; geo2 = gfactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeNone) as IMultiPolygon; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "TopologicalOperator.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { enableRightPanel(false); // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 注册地形 string tmpTedPath = (strMediaPath + @"\terrain\terrain.ted"); this.axRenderControl1.Terrain.RegisterTerrain(tmpTedPath, ""); crs = crsFactory.CreateFromWKT(this.axRenderControl1.GetTerrainCrsWKT(tmpTedPath, "")); this.axRenderControl1.Terrain.FlyTo(gviTerrainActionCode.gviFlyToTerrain); // 注册事件 this.axRenderControl1.RcObjectEditing += new _IRenderControlEvents_RcObjectEditingEventHandler(axRenderControl1_RcObjectEditing); this.axRenderControl1.RcObjectEditFinish += new _IRenderControlEvents_RcObjectEditFinishEventHandler(axRenderControl1_RcObjectEditFinish); { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "CutFill.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 下拉框控件默认选中第一项 this.toolStripComboBoxObjectManager.SelectedIndex = 0; this.toolStripComboBoxColor.SelectedIndex = 0; // 注册控件拾取事件 this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); this.axRenderControl1.InteractMode = gviInteractMode.gviInteractSelect; this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectAll; this.axRenderControl1.MouseSelectMode = gviMouseSelectMode.gviMouseSelectClick; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "LabelAndRenderGeometry.html"; } }
private void SetSkyBox(SkyBoxType sky) { string skyVal = ((int)sky).ToString(); if (skyVal == "0" || skyVal == "4") { skyVal = "0" + skyVal; } // 获取天空盒 skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(i3dSkyboxImageIndex.i3dSkyboxImageBack, Path.Combine(tmpSkyboxPath, skyVal + "_BK.jpg")); skybox.SetImagePath(i3dSkyboxImageIndex.i3dSkyboxImageBottom, Path.Combine(tmpSkyboxPath, skyVal + "_DN.jpg")); skybox.SetImagePath(i3dSkyboxImageIndex.i3dSkyboxImageFront, Path.Combine(tmpSkyboxPath, skyVal + "_FR.jpg")); skybox.SetImagePath(i3dSkyboxImageIndex.i3dSkyboxImageLeft, Path.Combine(tmpSkyboxPath, skyVal + "_LF.jpg")); skybox.SetImagePath(i3dSkyboxImageIndex.i3dSkyboxImageRight, Path.Combine(tmpSkyboxPath, skyVal + "_RT.jpg")); skybox.SetImagePath(i3dSkyboxImageIndex.i3dSkyboxImageTop, Path.Combine(tmpSkyboxPath, skyVal + "_UP.jpg")); }
/// <summary> /// 初始化 /// </summary> private void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); //this.axRenderControl1.Initialize2("PROJCS[\"MacauProj\",GEOGCS[\"MacauGrid\",DATUM[\"D_International_1924\",SPHEROID[\"International_1924\",6378388.0,297.0]],PRIMEM[\"<custom>\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",20000.0],PARAMETER[\"False_Northing\",20000.0],PARAMETER[\"Central_Meridian\",113.5364694444],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",22.2123972222],UNIT[\"Meter\",1.0]]", ps); this.axRenderControl1.Initialize(false, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 加载瓦片图层 string tilePath = (strMediaPath + @"\sdk.tdb"); I3DTileLayer layer = this.axRenderControl1.ObjectManager.Create3DTileLayer(tilePath, "", rootId); this.axRenderControl1.Camera.FlyToObject(layer.Guid, gviActionCode.gviActionFlyTo); { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "ShadowMapApplication.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "CalculateTopOnTerrain.html"; } // 注册地形 string tmpTedPath = (strMediaPath + @"\terrain\terrain.ted"); this.axRenderControl1.Terrain.RegisterTerrain(tmpTedPath, ""); this.axRenderControl1.Terrain.FlyTo(gviTerrainActionCode.gviFlyToTerrain); // 默认选buffer this.toolStripAreaType.SelectedIndex = 0; this.axRenderControl1.RcKeyUp += new _IRenderControlEvents_RcKeyUpEventHandler(axRenderControl1_RcKeyUp); }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(false, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; this.axRenderControl1.Camera.FlyTime = 1; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } this.toolStripComboBoxOsgMode.SelectedIndex = 0; this.axRenderControl1.RcObjectEditFinish += new Gvitech.CityMaker.Controls._IRenderControlEvents_RcObjectEditFinishEventHandler(axRenderControl1_RcObjectEditFinish); { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "FileToRenderGeometry.html"; } }
/// <summary> /// 开启关闭雾效果菜单项 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripFog_Click(object sender, EventArgs e) { bool fogCheck = (sender as ToolStripMenuItem).Checked; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); if (!fogCheck) { skybox.FogStartDistance = 0; skybox.FogEndDistance = 500; skybox.FogMode = gviFogMode.gviFogLinear; IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 500, angle); toolStripFog.Text = "关闭雾效"; } else { skybox.FogMode = gviFogMode.gviFogNone; toolStripFog.Text = "开启雾效"; } (sender as ToolStripMenuItem).Checked = !fogCheck; }
private void toolStripButtonLoadTerrain_Click(object sender, System.EventArgs e) { boundaryrmp.VisibleMask = gviViewportMask.gviViewNone; OpenFileDialog od = new OpenFileDialog(); od.Filter = "地形文件(*.ted)|*.ted"; if (System.IO.Directory.Exists(strMediaPath)) { od.InitialDirectory = strMediaPath + @"\terrain"; } od.RestoreDirectory = true; if (DialogResult.OK == od.ShowDialog()) { string wkt = this.axRenderControl1.GetTerrainCrsWKT(od.FileName, ""); if (crsFactory.CreateFromWKT(wkt).IsGeographic()) { MessageBox.Show("球面不能进行水淹分析,经纬度不能计算体积,面积"); return; } this.axRenderControl1.Reset2(wkt); this.axRenderControl1.Terrain.RegisterTerrain(od.FileName, ""); if (this.axRenderControl1.Terrain.IsPlanarTerrain) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } crs = crsFactory.CreateFromWKT(wkt); this.axRenderControl1.Terrain.FlyTo(gviTerrainActionCode.gviFlyToTerrain); } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); ps.SetProperty("QuadBufferStereo", true); //设置四缓冲立体启用 this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } #endregion // 下拉框控件默认选中第一项 this.toolStripComboBoxViewportMode.SelectedIndex = 0; this.txtEyeSeparation.Text = this.axRenderControl1.GetRenderParam(gviRenderControlParameters.gviRenderParamStereoEyeSeparation).ToString(); this.txtFusionDistance.Text = this.axRenderControl1.GetRenderParam(gviRenderControlParameters.gviRenderParamStereoFusionDistance).ToString(); this.txtScreenDistance.Text = this.axRenderControl1.GetRenderParam(gviRenderControlParameters.gviRenderParamStereoScreenDistance).ToString(); this.txtFusionDistance.TextChanged += new System.EventHandler(this.txtFusionDistance_TextChanged); this.txtEyeSeparation.TextChanged += new System.EventHandler(this.txtEyeSeparation_TextChanged); this.txtScreenDistance.TextChanged += new System.EventHandler(this.txtScreenDistance_TextChanged); { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "StereoDisplay.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 加载FDB try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\empty.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); TreeNode sourceNode = new TreeNode(ci.Database); this.treeViewCatalogTree.Nodes.Add(sourceNode); // 获取第1个dataset string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset = ds.OpenFeatureDataset(setnames[0]); TreeNode setNode = new TreeNode(setnames[0]); sourceNode.Nodes.Add(setNode); // 获取第1个featureclass string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fc = dataset.OpenFeatureClass(fcnames[0]); TreeNode fcNode = new TreeNode(fcnames[0]); setNode.Nodes.Add(fcNode); // 找到空间列字段 geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer layerList = new List <IFeatureLayer>(); foreach (string geoName in geoNames) { //****特别注意**** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); geoRender.RenderGroupField = "Groupid"; //**************** IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, geoRender, rootId); layerList.Add(featureLayer); // 设置featureLayer可见 SetGroupVisiable(dataset, featureLayer); IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } this.treeViewCatalogTree.ExpandAll(); // 加载FeatureDataSet对应的LogicGroupTree到界面控件 nodekeyMap = new Hashtable(); byte[] bb = GetLogicTreeContent(dataset); if (bb != null) { string strContent = System.Text.Encoding.UTF8.GetString(bb).Trim(); ShowCurDataSet(strContent); } // 删除回收站及其子节点 foreach (TreeNode node in this.treeViewLogicTree.Nodes[0].Nodes) { if (node.Text.Equals("回收站")) { this.treeViewLogicTree.Nodes.Remove(node); } } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "ImportModel.html"; } CommonEntity.RenderEntity = this.axRenderControl1; CommonEntity.FormEntity = this; }
/// <summary> /// 初始化 /// </summary> private void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); // Unknown this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 平面坐标系 //string wkt = @"PROJCS['Beijing_1954_3_Degree_GK_CM_102E',GEOGCS['GCS_Beijing_1954',DATUM['D_Beijing_1954',SPHEROID['Krasovsky_1940',6378245.0,298.3]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Gauss_Kruger'],PARAMETER['False_Easting',500000],PARAMETER['False_Northing',0],PARAMETER['Central_Meridian',102],PARAMETER['Scale_Factor',1],PARAMETER['Latitude_Of_Origin',0],UNIT['metre',1]]"; //this.axRenderControl1.Initialize2(wkt, ps); // 球面1 //this.axRenderControl1.Initialize(false, ps); // 球面2 //IGeographicCRS crs = new CRSFactory().CreateWGS84(); //this.axRenderControl1.Initialize2(crs.AsWKT(), ps); // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); datasetCRS = dataset.SpatialReference; string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } #endregion 加载FDB场景 this.axRenderControl1.Camera.FlyTime = 0; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "ParticleEffect.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { //错误日志 Logger.Create(Environment.CurrentDirectory); //Application.LocalUserAppDataPath // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); fcGUIDMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); fcGUIDMap.Add(fc.Guid, fc); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } // 获取定位featurelayer时要飞到的坐标信息 envX = env.Center.X; envY = env.Center.Y; envZ = env.Center.Z; IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } #endregion { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "GeometryEditor.html"; } // 进入编辑模式 this.axRenderControl1.InteractMode = gviInteractMode.gviInteractEdit; setEnableEditButtons(true, false); //// 俯视 //IVector3 position = new Vector3(); //position.Set(28.66, -169.75, 258.83); //IEulerAngle angle = new EulerAngle(); //angle.Set(0, -20, 0); //this.axRenderControl1.Camera.SetCamera(position, angle, gviSetCameraFlags.gviSetCameraNoFlags); // 注册交互编辑事件 _geoEditor = this.axRenderControl1.ObjectEditor; this.axRenderControl1.RcObjectEditing += new _IRenderControlEvents_RcObjectEditingEventHandler(axRenderControl1_RcObjectEditing); this.axRenderControl1.RcObjectEditFinish += new _IRenderControlEvents_RcObjectEditFinishEventHandler(axRenderControl1_RcObjectEditFinish); }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\PIPE.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, rootId); } } IPoint position = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); position.SetCoords(506308.31579040177, 314272.281405516, 3.2581421811509275, 0, 0); position.SpatialCRS = dataset.SpatialReference; IEulerAngle angle = new EulerAngle(); angle.Set(66.16, -14.2, 0); this.axRenderControl1.Camera.SetCamera2(position, angle, gviSetCameraFlags.gviSetCameraNoFlags); { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "DynamicPipe.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 加载FDB场景 //try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } //catch (COMException ex) //{ // System.Diagnostics.Trace.WriteLine(ex.Message); // return; //} // CreateFeautureLayer foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, rootId); } } IPoint position = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); position.SetCoords(15371.768457028507, 35951.723472296966, 20.9338220668297, 0, 0); position.SpatialCRS = dataset.SpatialReference; IEulerAngle angle = new EulerAngle(); angle.Set(11.76, -19.26, 0); this.axRenderControl1.Camera.SetCamera2(position, angle, gviSetCameraFlags.gviSetCameraNoFlags); //获取默认的静态贴图 //try { resManager = dataset as IResourceManager; imgStatic = resManager.GetImage("paizi6"); } //catch (System.Exception ex) //{ // if (ex.GetType().Name.Equals("UnauthorizedAccessException")) // MessageBox.Show("需要标准runtime授权"); // else // MessageBox.Show(ex.Message); //} { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "DynamicImage.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } this.axRenderControl1.Camera.FlyTime = 0; // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\IFC.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } IFeatureClass fc = dataset.OpenFeatureClass(fcnames[0]); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } ISimpleGeometryRender geoRender = new SimpleGeometryRender(); geoRender.RenderGroupField = "ParentObjectId"; layer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, fieldinfo.Name, null, geoRender, rootId); IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 100, angle); Hashtable cusData = fc.CustomData.AsHashtable(); IEnumerator etor = cusData.Keys.GetEnumerator(); etor.MoveNext(); string strXML = (string)cusData[etor.Current]; ShowIFCTree(strXML); break; } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "IfcTree.html"; } }
/// <summary> /// 设置默认天空盒 /// </summary> private void SetDefaultSkyBox() { // 获取天空盒 skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); SetSkyBox(SkyBoxType.JSCX); }
public MainForm() { InitializeComponent(); // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\BIMTIME.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); bool bHasTemp = fc.HasTemporal(); if (bHasTemp) { ITemporalManager tm = fc.TemporalManager; if (tm != null) { try { DateTime[] times = tm.GetKeyDatetimes(); for (int i = 0; i < times.Length; i++) { if (keyDatetimesList.Contains(times[i])) { continue; } keyDatetimesList.Add(times[i]); } } catch (COMException) { } } } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // 设置时间轴 keyDatetimesList.Sort(); if (keyDatetimesList.Count > 3) { TimeSpan tsmin = keyDatetimesList[0] - dayLongLongAgo; this.trackBarTime.Minimum = tsmin.Days - 1; this.trackBarTimeCompare.Minimum = tsmin.Days - 1; TimeSpan tsmax = keyDatetimesList[keyDatetimesList.Count - 2] - dayLongLongAgo; this.trackBarTime.Maximum = tsmax.Days + 1; this.trackBarTimeCompare.Maximum = tsmax.Days + 1; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (featureLayer == null) { continue; } #region 设置时态 featureLayer.EnableTemporal = true; layerList.Add(featureLayer); //设置curLayer的时刻 this.trackBarTime.Value = this.trackBarTime.Minimum; DateTime d = dayLongLongAgo.AddDays((double)this.trackBarTime.Value); this.labelTime.Text = d.ToString(); featureLayer.Time = d; #endregion #region 比较规则 pset.SetProperty("提前", "$(starttime)"); featureLayer.CompareRenderRuleVariants = pset; IValueMapGeometryRender render = new ValueMapGeometryRender(); { IGeometryRenderScheme scheme = new GeometryRenderScheme(); IComparedRenderRule rule = new ComparedRenderRule(); rule.LookUpField = "实际开始时间"; rule.CompareVariant = "提前"; rule.CompareOperator = gviCompareType.gviCompareLess; scheme.AddRule(rule); IModelPointSymbol symbol = new ModelPointSymbol(); symbol.EnableColor = true; symbol.Color = System.Drawing.Color.Green; scheme.Symbol = symbol; render.AddScheme(scheme); } { IGeometryRenderScheme scheme = new GeometryRenderScheme(); IComparedRenderRule rule = new ComparedRenderRule(); rule.LookUpField = "实际开始时间"; rule.CompareVariant = "提前"; rule.CompareOperator = gviCompareType.gviCompareGreaterOrEqual; scheme.AddRule(rule); IModelPointSymbol symbol = new ModelPointSymbol(); symbol.EnableColor = false; scheme.Symbol = symbol; render.AddScheme(scheme); } featureLayer.SetGeometryRender(render); #endregion if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } angle.Set(0, -52, 0); position.Set(-13.44, -88.77, 59.28); this.axRenderControl1.Camera.LookAt(position, 100, angle); hasfly = true; } } } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "FiveDShow.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 开启顶点捕捉 this.axRenderControl1.MouseSnapMode = gviMouseSnapMode.gviMouseSnapVertex; _geoEditor = this.axRenderControl1.ObjectEditor; enableSnapBox.CheckedChanged += new System.EventHandler(enableSnapBox_CheckedChanged); this.toolStripComboBoxMeasure.SelectedIndex = 0; this.toolStripComboBoxEdit.SelectedIndex = 0; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "MouseSnap.html"; } layerEnvelopeMap = new Hashtable(); fcGUIDMap = new Hashtable(); // 可视化Point类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\point.FDB"); ci.Database = tmpFDBPath; ISimpleGeometryRender render = new SimpleGeometryRender(); ISimplePointSymbol pointSymbol = new SimplePointSymbol(); pointSymbol.Size = 10; render.Symbol = pointSymbol; FeatureLayerVisualize(ci, true, "Point", render); } // 可视化Polyline类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polyline.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, false, "Polyline", null); } // 可视化Polygon类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polygon.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, false, "Polygon", null); } // 可视化ModelPoint类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, false, "ModelPoint", null); } // 绑定选择事件 this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\REVIT-ALL2013.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } angle.Set(0, -20, 0); point = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); point.SpatialCRS = fc.FeatureDataSet.SpatialReference; point.SetCoords(env.Center.X, env.Center.Y, env.Center.Z, 0, 0); this.axRenderControl1.Camera.LookAt2(point, 100, angle); } hasfly = true; } } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "Revit.html"; } }
// 更换天空盒 private void skyboxListView_MouseDoubleClick(object sender, MouseEventArgs e) { if (this.skyboxListView.SelectedItems.Count > 0) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); switch (skyboxListView.SelectedItems[0].Text) { case "无": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\00_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\00_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\00_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\00_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\00_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\00_UP.jpg"); break; case "金色晨曦": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); break; case "光暗之手": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\2_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\2_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\2_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\2_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\2_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\2_UP.jpg"); break; case "天马行空": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\04_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\04_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\04_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\04_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\04_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\04_UP.jpg"); break; case "飘絮人间": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\7_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\7_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\7_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\7_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\7_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\7_UP.jpg"); break; case "七彩紫罗": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\9_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\9_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\9_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\9_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\9_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\9_UP.jpg"); break; case "云中之触": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\10_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\10_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\10_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\10_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\10_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\10_UP.jpg"); break; case "鲲鹏万里": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\11_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\11_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\11_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\11_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\11_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\11_UP.jpg"); break; case "血色苍穹": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\12_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\12_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\12_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\12_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\12_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\12_UP.jpg"); break; case "白云旋天": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\13_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\13_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\13_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\13_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\13_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\13_UP.jpg"); break; case "长空破日": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\22_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\22_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\22_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\22_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\22_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\22_UP.jpg"); break; case "霞光掩影": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\44_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\44_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\44_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\44_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\44_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\44_UP.jpg"); break; case "混沌沧海": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\99_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\99_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\99_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\99_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\99_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\99_UP.jpg"); break; case "梦境之末": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\100_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\100_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\100_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\100_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\100_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\100_UP.jpg"); break; case "玄浑宇宙": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\120_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\120_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\120_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\120_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\120_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\120_UP.jpg"); break; case "月神之眼": skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\130_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\130_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\130_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\130_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\130_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\130_UP.jpg"); break; } } }
private void MainForm_Load(object sender, EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; CommonUnity.RenderHelper = this.axRenderControl1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } this.axRenderControl1.Camera.VerticalFieldOfView = 60; // 加载瓦片图层 string tilePath = (strMediaPath + @"\sdk.tdb"); I3DTileLayer layer = this.axRenderControl1.ObjectManager.Create3DTileLayer(tilePath, "", rootId); this.axRenderControl1.Camera.FlyToObject(layer.Guid, gviActionCode.gviActionFlyTo); IGeometryFactory fac = new GeometryFactory(); positionPoint = fac.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); ConstructTable(); // 绑定键盘事件 this.axRenderControl1.RcKeyUp += new _IRenderControlEvents_RcKeyUpEventHandler(axRenderControl1_RcKeyUp); string filePath = Application.StartupPath + @"\adjust.txt"; if (File.Exists(filePath)) { streamWriter = new StreamWriter(filePath, true); } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "Viewshed.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } this.axRenderControl1.Camera.FlyTime = 1; #region 加载SDKDEMO场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); //遍历FeatureClass string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); flayerList.Add(featureLayer); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -90, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } #endregion //注册地形 string tmpTedPath = (strMediaPath + @"\terrain\SingaporePlanarTerrain.ted"); this.axRenderControl1.Terrain.RegisterTerrain(tmpTedPath, ""); if (player == null) { player = this.axRenderControl1.HeatMapPlayer; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\HeatMap.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); if (fc.HasTemporal()) { ITemporalManager tm = fc.TemporalManager; DateTime[] times = tm.GetKeyDatetimes(); for (int i = 0; i < times.Length; i++) { if (keyDatetimesList.Contains(times[i])) { continue; } keyDatetimesList.Add(times[i]); } } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // 设置时间轴 if (keyDatetimesList.Count == 0) { this.cbKeyTimes.Enabled = false; this.btnPlay.Enabled = false; this.btnPause.Enabled = false; this.btnStop.Enabled = false; } else { keyDatetimesList.Sort(); for (int t = 0; t < keyDatetimesList.Count; t++) { DateTime d = keyDatetimesList[t]; cbKeyTimes.Items.Add(d); } } // CreateFeautureLayer foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { heatmap = this.axRenderControl1.ObjectManager.CreateHeatMap( fc, geoName, "HotValue", rootId); if (heatmap == null) { continue; } this.txtMinValue.Text = heatmap.MinHeatValue.ToString(); this.txtMaxValue.Text = heatmap.MaxHeatValue.ToString(); } } //设置curLayer的时刻为最新时刻 if (keyDatetimesList.Count > 0) { DateTime dmax = (keyDatetimesList[keyDatetimesList.Count - 1]); player.SetTime(dmax); //设置时间轴为最小 cbKeyTimes.SelectedIndex = keyDatetimesList.Count - 1; } //测试自定义颜色 //System.Drawing.Color[] colors = new System.Drawing.Color[2]; //colors[0] = System.Drawing.Color.White; //colors[1] = System.Drawing.Color.Gray; //bool suc = player.SetColor(colors, 2); //if(suc) //{ // System.Drawing.Color[] colorvec; // byte c; // bool suc2 = player.GetColor(out colorvec, out c); // if (suc2) // this.Text = c.ToString(); //} this.cbShowHeatMap.Checked = true; this.cbShowFeatureLayer.Checked = true; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "Temporal.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "FeatureLayerSimpleRender.html"; } layerEnvelopeMap = new Hashtable(); layerFcMap = new Hashtable(); // 可视化Point类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\point.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* ISimpleTextRender textRender = new SimpleTextRender(); textRender.Expression = "''..$(oid)"; ITextSymbol textSymbol = new TextSymbol(); TextAttribute textAttribute = new TextAttribute(); textAttribute.TextColor = System.Drawing.Color.Red; textSymbol.TextAttribute = textAttribute; textSymbol.PivotAlignment = gviPivotAlignment.gviPivotAlignBottomCenter; textSymbol.VerticalOffset = 10; // 注意:必须设置symbol,默认文字不显示 textRender.Symbol = textSymbol; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); // 特别注意:此处设置了逻辑组字段,则需要在CreateFeatureLayer后设置组的可见性。否则,默认FeatureLayer将不可见。 // 注意:必须用已注册RenderIndex的字段,否则CreateFeatureLayer创建不成功返回null geoRender.RenderGroupField = "Groupid"; IImagePointSymbol geoSymbol = new ImagePointSymbol(); //将点以图片的形式显示出来 geoSymbol.ImageName = "huang.png"; //使用素材库里存在的图片 geoSymbol.Size = 25; geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, true, "Point", textRender, geoRender); } // 可视化Polyline类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polyline.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* ISimpleTextRender textRender = new SimpleTextRender(); textRender.Expression = "''..$(oid)"; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); // 特别注意:此处设置了逻辑组字段,则需要在CreateFeatureLayer后设置组的可见性。否则,默认FeatureLayer将不可见。 geoRender.RenderGroupField = "Groupid"; ICurveSymbol geoSymbol = new CurveSymbol(); geoSymbol.Color = System.Drawing.Color.Red; //线颜色为Purple geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, false, "Polyline", textRender, geoRender); } // 可视化Polygon类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polygon.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* ISimpleTextRender textRender = new SimpleTextRender(); textRender.Expression = "''..$(oid)"; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); // 特别注意:此处设置了逻辑组字段,则需要在CreateFeatureLayer后设置组的可见性。否则,默认FeatureLayer将不可见。 geoRender.RenderGroupField = "Groupid"; ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Yellow; //面填充色为Yellow geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, false, "Polygon", textRender, geoRender); } // 可视化ModelPoint类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\community.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* ISimpleTextRender textRender = new SimpleTextRender(); textRender.Expression = "''..$(oid)"; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); //特别注意:此处设置了逻辑组字段,则需要在CreateFeatureLayer后设置组的可见性。否则,默认FeatureLayer将不可见。 geoRender.RenderGroupField = "Groupid"; IModelPointSymbol geoSymbol = new ModelPointSymbol(); geoSymbol.Color = System.Drawing.Color.Yellow; //模型颜色为Red geoSymbol.EnableColor = true; //需开启,否则颜色设置无效 geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, false, "ModelPoint", textRender, geoRender); } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "FeatureLayerVisualize.html"; } layerEnvelopeMap = new Hashtable(); // 可视化Point类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\point.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, true, "Point"); } // 可视化Polyline类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polyline.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, false, "Polyline"); } // 可视化Polygon类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polygon.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, false, "Polygon"); } // 可视化ModelPoint类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, false, "ModelPoint"); } }
void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 注册出图事件 this.axRenderControl1.RcPictureExportBegin += new _IRenderControlEvents_RcPictureExportBeginEventHandler(axRenderControl1_RcPictureExportBegin); this.axRenderControl1.RcPictureExporting += new _IRenderControlEvents_RcPictureExportingEventHandler(axRenderControl1_RcPictureExporting); this.axRenderControl1.RcPictureExportEnd += new _IRenderControlEvents_RcPictureExportEndEventHandler(axRenderControl1_RcPictureExportEnd); // 注册相机“返回”和“前进”事件 this.axRenderControl1.RcCameraUndoRedoStatusChanged += new _IRenderControlEvents_RcCameraUndoRedoStatusChangedEventHandler(axRenderControl1_RcCameraUndoRedoStatusChanged); _rcCameraUndoRedo = new _IRenderControlEvents_RcCameraUndoRedoStatusChangedEventHandler(axRenderControl1_RcCameraUndoRedoStatusChanged); // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } // 加载动画导航 BindingSource bindingSource1 = new BindingSource(); { string tmpXMLPath = (strMediaPath + @"\xml\CameraTour_1.xml"); tour = this.axRenderControl1.ObjectManager.CreateCameraTour(rootId); if (File.Exists(tmpXMLPath)) { StreamReader sr = new StreamReader(tmpXMLPath); string xmlstring = ""; string line = sr.ReadLine(); while (!string.IsNullOrEmpty(line)) { xmlstring += line; line = sr.ReadLine(); } sr.Close(); tour.FromXml(xmlstring); } bindingSource1.Add(new Knight("CameraTour_1", tour)); } { string tmpXMLPath = (strMediaPath + @"\xml\CameraTour_2.xml"); tour = this.axRenderControl1.ObjectManager.CreateCameraTour(rootId); if (File.Exists(tmpXMLPath)) { StreamReader sr = new StreamReader(tmpXMLPath); string xmlstring = ""; string line = sr.ReadLine(); while (!string.IsNullOrEmpty(line)) { xmlstring += line; line = sr.ReadLine(); } sr.Close(); tour.FromXml(xmlstring); } bindingSource1.Add(new Knight("CameraTour_2", tour)); } dataGridView1.DataSource = bindingSource1; dataGridView1.Columns[1].Visible = false; this.btnPause.Enabled = false; this.btnStop.Enabled = false; this.toolStripComboBoxWeather.SelectedIndex = 0; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "HelloWorld.html"; } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\MultiSpatialColumns.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } // 仅仅加载“建筑”要素类 _featureClass = dataset.OpenFeatureClass("建筑"); { // 用名为"Geometry"的空间列创建模型FeautureLayer IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(_featureClass, "Geometry", null, null, rootId); // 添加节点到界面控件上 myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "ModelPoint", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer); item.Checked = true; listView1.Items.Add(item); } { //用名为"Surface"的空间列创建模型FeautureLayer IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(_featureClass, "Surface", null, null, rootId); // 添加节点到界面控件上 myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "Surface", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer); item.Checked = true; listView1.Items.Add(item); } { //用名为"Polygon"的空间列创建模型FeautureLayer IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(_featureClass, "Polygon", null, null, rootId); // 添加节点到界面控件上 myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "Polygon", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer); item.Checked = true; listView1.Items.Add(item); } //{ // //用名为"Point"的空间列创建模型FeautureLayer // IFeatureLayer featureLayer = this.axRenderControl1.FeatureLayerManager.CreateFeatureLayer(_featureClass, "Point", null, null); // // 添加节点到界面控件上 // myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "Point", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer); // item.Checked = true; // listView1.Items.Add(item); //} IFieldInfoCollection fieldinfos = _featureClass.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf("Geometry")); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 400, angle); } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } #endregion { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "MultiSpatialColumns.html"; } }
/// <summary> /// 初始化 /// </summary> private void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); skybox = this.axRenderControl1.ObjectManager.GetSkyBox(1); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\2_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\2_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\2_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\2_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\2_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\2_UP.jpg"); skybox = this.axRenderControl1.ObjectManager.GetSkyBox(2); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\04_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\04_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\04_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\04_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\04_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\04_UP.jpg"); skybox = this.axRenderControl1.ObjectManager.GetSkyBox(3); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\9_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\9_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\9_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\9_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\9_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\9_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } #endregion 加载FDB场景 { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "HideSelectedArea.html"; } // 注册控件拾取事件 this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); this.axRenderControl1.RcMouseDragSelect += new _IRenderControlEvents_RcMouseDragSelectEventHandler(axRenderControl1_RcMouseDragSelect); this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectFeatureLayer; this.axRenderControl1.InteractMode = gviInteractMode.gviInteractSelect; this.axRenderControl1.MouseSelectMode = gviMouseSelectMode.gviMouseSelectClick | gviMouseSelectMode.gviMouseSelectDrag; }
private void init() { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\7_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\7_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\7_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\7_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\7_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\7_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } #region 加载shp try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionShapeFile; string tmpFDBPath = (strMediaPath + @"\shp\road\road.shp"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); datasetCRS = dataset.SpatialReference; string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); IPoint point = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); point.Position = env.Center; point.SpatialCRS = fc.FeatureDataSet.SpatialReference; this.axRenderControl1.Camera.LookAt2(point, 1000, angle); } hasfly = true; } } #endregion }