Пример #1
0
        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;
            }

            // 可视化ModelPoint类型FeatureLayer
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\community.FDB");
                ci.Database = tmpFDBPath;

                // *******定义文字渲染风格*******
                IValueMapTextRender textRender = new ValueMapTextRender();
                textRender.Expression = "''..$(Name)";

                {
                    TextAttribute textAttribute = new TextAttribute();
                    textAttribute.TextColor = System.Drawing.Color.Yellow;
                    textAttribute.Font      = "黑体";
                    textAttribute.TextSize  = 15;

                    ITextSymbol textSymbol = new TextSymbol();
                    textSymbol.TextAttribute  = textAttribute;
                    textSymbol.PivotAlignment = gviPivotAlignment.gviPivotAlignBottomCenter;

                    IUniqueValuesRenderRule uniqValRule = new UniqueValuesRenderRule();
                    uniqValRule.LookUpField = "type";
                    uniqValRule.AddValue("写字楼");

                    ITextRenderScheme textScheme = new TextRenderScheme();
                    textScheme.Symbol = textSymbol;
                    textScheme.AddRule(uniqValRule);
                    textRender.AddScheme(textScheme);
                }

                {
                    TextAttribute textAttribute = new TextAttribute();
                    textAttribute.TextColor = Color.Black;
                    textAttribute.TextSize  = 11;
                    textAttribute.Font      = "华文新魏";

                    ITextSymbol textSymbol = new TextSymbol();
                    textSymbol.TextAttribute  = textAttribute;
                    textSymbol.PivotAlignment = gviPivotAlignment.gviPivotAlignBottomCenter;

                    IUniqueValuesRenderRule uniqValRule = new UniqueValuesRenderRule();
                    uniqValRule.LookUpField = "type";
                    uniqValRule.AddValue("别墅");

                    ITextRenderScheme textScheme = new TextRenderScheme();
                    textScheme.Symbol = textSymbol;
                    textScheme.AddRule(uniqValRule);
                    textRender.AddScheme(textScheme);
                }

                {
                    TextAttribute textAttribute = new TextAttribute();
                    textAttribute.TextColor = Color.Red;
                    textAttribute.TextSize  = 20;
                    textAttribute.Font      = "幼圆";

                    ITextSymbol textSymbol = new TextSymbol();
                    textSymbol.TextAttribute  = textAttribute;
                    textSymbol.PivotAlignment = gviPivotAlignment.gviPivotAlignBottomCenter;

                    IUniqueValuesRenderRule uniqValRule = new UniqueValuesRenderRule();
                    uniqValRule.LookUpField = "type";
                    uniqValRule.AddValue("商场");

                    ITextRenderScheme textScheme = new TextRenderScheme();
                    textScheme.Symbol = textSymbol;
                    textScheme.AddRule(uniqValRule);
                    textRender.AddScheme(textScheme);
                }

                // *****定义几何物体渲染风格*****
                IValueMapGeometryRender geoRender = new ValueMapGeometryRender();
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "storey";
                    rangeRule.MaxValue    = 3;
                    rangeRule.MinValue    = 0;
                    rangeRule.IncludeMin  = false;

                    IModelPointSymbol geoSymbol = new ModelPointSymbol();
                    geoSymbol.Color       = Color.Yellow; //模型颜色为浅黄
                    geoSymbol.EnableColor = true;         //需开启,否则颜色设置无效

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "storey";
                    rangeRule.MaxValue    = 9;
                    rangeRule.MinValue    = 3;
                    rangeRule.IncludeMin  = false;

                    IModelPointSymbol geoSymbol = new ModelPointSymbol();
                    geoSymbol.Color       = Color.YellowGreen; //模型颜色为中黄
                    geoSymbol.EnableColor = true;              //需开启,否则颜色设置无效

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "storey";
                    rangeRule.MaxValue    = 12;
                    rangeRule.MinValue    = 9;
                    rangeRule.IncludeMin  = false;

                    IModelPointSymbol geoSymbol = new ModelPointSymbol();
                    geoSymbol.Color       = Color.Red; //模型颜色为深黄
                    geoSymbol.EnableColor = true;      //需开启,否则颜色设置无效

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "storey";
                    rangeRule.MaxValue    = 15;
                    rangeRule.MinValue    = 12;
                    rangeRule.IncludeMin  = false;

                    IModelPointSymbol geoSymbol = new ModelPointSymbol();
                    geoSymbol.Color       = Color.PowderBlue; //模型颜色为深黄
                    geoSymbol.EnableColor = true;             //需开启,否则颜色设置无效

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IGeometryRenderScheme geoSchemeOther = new GeometryRenderScheme();
                    geoRender.AddScheme(geoSchemeOther);
                }

                FeatureLayerVisualize(ci, true, "建筑", textRender, geoRender);
            }

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "FeatureLayerValueMapRender.html";
            }
        }
Пример #2
0
        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;

            ICRSFactory crsfac = new CRSFactory();

            _currentCRS = (crsfac.CreateFromWKT(this.axRenderControl1.GetCurrentCrsWKT())) as ISpatialCRS;

            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;

            // 加载瓦片图层
            string       tilelayerString = (strMediaPath + @"\sdk.tdb");
            I3DTileLayer layer           = this.axRenderControl1.ObjectManager.Create3DTileLayer(tilelayerString, "", rootId);

            this.axRenderControl1.Camera.FlyToObject(layer.Guid, gviActionCode.gviActionFlyTo);
            // 添加节点到界面控件上
            myListNode item = new myListNode("tilelayer", TreeNodeType.NT_TiltedLAYER, layer);

            item.Checked = true;
            listView1.Items.Add(item);

            #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;

                //遍历FeatureClass
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap    = new Hashtable(fcnames.Length);
                fcuidMap = 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;
                        }
                        if (geometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnPolygon)
                        {
                            geoNames.Add(fieldinfo.Name);
                        }
                    }
                    fcMap.Add(fc, geoNames);
                    fcuidMap.Add(fc.Guid, fc);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
            #endregion

            //CreateFeautureLayer for 矢量贴地
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                if (geoNames.Count == 0)
                {
                    continue;
                }

                #region 定义几何物体渲染风格
                ICurveSymbol cs = new CurveSymbol();
                cs.Color = System.Drawing.Color.Empty;  //防止贴瓦片时出现绿色竖边
                IValueMapGeometryRender geoRender = new ValueMapGeometryRender();
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1100;
                    rangeRule.MinValue    = 1000;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Yellow;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1200;
                    rangeRule.MinValue    = 1100;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Blue;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1300;
                    rangeRule.MinValue    = 1200;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Green;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1400;
                    rangeRule.MinValue    = 1300;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Goldenrod;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Fuchsia;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme geoSchemeOther = new GeometryRenderScheme();
                    geoSchemeOther.Symbol = geoSymbol;
                    geoRender.AddScheme(geoSchemeOther);
                }
                #endregion
                geoRender.HeightStyle = gviHeightStyle.gviHeightOnEverything;

                IFeatureLayer fcLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoNames[0], null, geoRender, rootId);
                if (fcLayer != null)
                {
                    fcLayer.VisibleMask = gviViewportMask.gviViewNone;

                    // 添加节点到界面控件上
                    myListNode item2 = new myListNode(fc.Name + "_" + geoNames[0], TreeNodeType.NT_FeatureLayer, fcLayer);
                    item.Checked = false;
                    listView1.Items.Add(item2);
                }
                else
                {
                    MessageBox.Show("Create FeatureLayer Failed! " + this.axRenderControl1.GetLastError().ToString());
                }
            }

            // 注册事件
            this.axRenderControl1.RcMouseClickSelect += new Gvitech.CityMaker.Controls._IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect);


            //设置highlight可用
            this.axRenderControl1.HighlightHelper.VisibleMask = 1;



            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "TileHole.html";
            }
        }