public void LayerTest()
        {
            TestManager.Helpers.CreateTestScene("LayerTest.scene");
            IScene scene = EditorManager.Scene;

            Assert.IsTrue(scene.Save());
            Assert.AreEqual(1, scene.Layers.Count);

            // default layer should be active
            Assert.IsNotNull(scene.ActiveLayer);
            Assert.AreEqual(1, scene.Layers.Count);

            Layer layer1 = new Layer("added1");

            scene.AddLayer(layer1, false);
            Assert.AreEqual(2, scene.Layers.Count);

            Layer layer2 = new Layer("added2");

            scene.AddLayer(layer2, true);
            Assert.AreEqual(3, scene.Layers.Count);
            Assert.AreEqual(layer2, scene.ActiveLayer);

            Assert.IsTrue(scene.RemoveLayer(layer2));
            Assert.IsNotNull(scene.ActiveLayer);
            Assert.IsFalse(layer2 == scene.ActiveLayer);

            TestManager.Helpers.CloseTestProject();
        }
Beispiel #2
0
        public static IGraphicsContainer3D Add3DGraphicsLayer(string string_0, ISceneGraph isceneGraph_0)
        {
            IGraphicsContainer3D result = null;
            IScene scene = isceneGraph_0.Scene;
            bool   flag  = false;

            if (scene.LayerCount > 0)
            {
                IEnumLayer enumLayer = scene.get_Layers(null, true);
                enumLayer.Reset();
                for (ILayer layer = enumLayer.Next(); layer != null; layer = enumLayer.Next())
                {
                    if (layer.Name == string_0 && layer is IGraphicsContainer3D)
                    {
                        result = (layer as IGraphicsContainer3D);
                        flag   = true;
                        break;
                    }
                }
            }
            if (!flag)
            {
                ILayer layer2 = new GraphicsLayer3D();
                layer2.Name = string_0;
                scene.AddLayer(layer2, true);
                result = (layer2 as IGraphicsContainer3D);
                Utils3D.RefreshApp(isceneGraph_0);
            }
            return(result);
        }
Beispiel #3
0
        public void ConstructLayer(string name)
        {
            IGlobeGraphicsLayer globeGraphicsLayer = new GlobeGraphicsLayerClass();

            ILayer layer = globeGraphicsLayer as ILayer;

            layer.Name = name;

            _scene.AddLayer(layer, true);
        }
Beispiel #4
0
        //点确定,将选中图层添加到三维视图,仅支持两个层次的图层树
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (m_pScene == null)
            {
                return;
            }

            for (int i = 0; i < this.LayerTree.Nodes.Count; i++)
            {
                DevComponents.AdvTree.Node pnode = LayerTree.Nodes[i];
                ILayer player = pnode.Tag as ILayer;
                if (pnode.Nodes.Count > 0)
                {   //若该节点存在子节点(该节点是图层组),则遍历子节点
                    for (int j = 0; j < pnode.Nodes.Count; j++)
                    {
                        DevComponents.AdvTree.Node pTmpnode = pnode.Nodes[j];
                        ILayer pTmplayer = pTmpnode.Tag as ILayer;
                        if (pTmpnode.Cells[1].Checked && !ContainLyr(pTmplayer, m_pScene))
                        {
                            m_pScene.AddLayer(pTmplayer, true);
                        }
                    }
                }
                else//若不存在子节点,则该节点是图层
                {
                    if (pnode.Cells[1].Checked && !ContainLyr(player, m_pScene))
                    {
                        m_pScene.AddLayer(player, true);
                    }
                }
            }
            if (this.WriteLog)
            {
                Plugin.LogTable.Writelog("三维视图加载二维图层");//xisheng 日志记录07.08
            }
            this.DialogResult = DialogResult.OK;
        }
Beispiel #5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (m_pScene == null)
            {
                return;
            }

            for (int i = 0; i < this.lstLyrs.Items.Count; i++)
            {
                if (this.lstLyrs.GetItemChecked(i) && !ContainLyr(m_vDicLyrs[i], m_pScene))
                {
                    m_pScene.AddLayer(m_vDicLyrs[i], true);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                if (!m_bConnected)
                {
                    //show the tracking type selection dialog (whether to track the element from above or follow it from behind)
                    TrackSelectionDlg dlg = new TrackSelectionDlg();
                    if (System.Windows.Forms.DialogResult.OK != dlg.ShowDialog())
                    {
                        return;
                    }

                    //get the required tracking mode
                    m_bTrackAboveTarget = dlg.UseOrthoTrackingMode;

                    //do only once initializations
                    if (m_once)
                    {
                        //create the graphics layer to manage the dynamic object
                        m_globeGraphicsLayer = new GlobeGraphicsLayerClass();
                        ((ILayer)m_globeGraphicsLayer).Name = "DynamicObjects";

                        IScene scene = (IScene)m_globeDisplay.Globe;

                        //add the new graphic layer to the globe
                        scene.AddLayer((ILayer)m_globeGraphicsLayer, false);

                        //activate the graphics layer
                        scene.ActiveGraphicsLayer = (ILayer)m_globeGraphicsLayer;

                        //redraw the GlobeDisplay
                        m_globeDisplay.RefreshViewers();

                        //open a polyline featurelayer that would serve the real-time feed GPS simulator
                        IFeatureLayer featureLayer = GetFeatureLayer();
                        if (featureLayer == null)
                        {
                            return;
                        }

                        //assign the featurelayer to the GPS simulator
                        m_realTimeFeedManager.RealTimeFeedSimulator.FeatureLayer = featureLayer;

                        m_once = false;
                    }

                    //get the GlobeViewUtil which is needed for coordinate transformations
                    m_sceneViwer = m_globeDisplay.ActiveViewer;

                    //Set the globe mode to terrain mode, since otherwise it will not be possible to set the target position
                    ((IGlobeCamera)m_sceneViwer.Camera).OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal;


                    //set the simulator elapsed time
                    m_realTimeFeedManager.RealTimeFeedSimulator.TimeIncrement = 0.1; //sec

                    //wire the real-time feed PositionUpdate event
                    ((IRealTimeFeedEvents_Event)m_realTimeFeed).PositionUpdated += new IRealTimeFeedEvents_PositionUpdatedEventHandler(OnPositionUpdated);

                    //start the real-time listener
                    m_realTimeFeed.Start();
                }
                else
                {
                    //stop the real-time listener
                    m_realTimeFeed.Stop();

                    //un-wire the PositionUpdated event handler
                    ((IRealTimeFeedEvents_Event)m_realTimeFeed).PositionUpdated -= new IRealTimeFeedEvents_PositionUpdatedEventHandler(OnPositionUpdated);
                }

                //switch the connection flag
                m_bConnected = !m_bConnected;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            //高程底面
            ILayer   pBaseLayer = null;
            ISurface pSurface   = null;

            if (m_pSceneCtrl != null)
            {
                try
                {
                    // m_pSceneCtrl.LoadSxFile(ClsGDBDataCommon.GetParentPathofExe() +@"Resource\DefaultData\Default.sxd");
                }
                catch
                {
                }
                //IScene pScene = new SceneClass();
                //pScene.Name = "Scene";
                //m_pSceneCtrl.Scene = pScene;

                IScene pScene = m_pSceneCtrl.Scene;
                pScene.Name = "Scene";
                //ILayer pglayer = new GraphicsLayer3DClass();
                //pScene.AddLayer(pglayer);
                //pScene.ActiveGraphicsLayer = new CompositeGraphicsLayerClass();

                pScene.ExaggerationFactor = Convert.ToDouble(doubleInputExaFactor.Value.ToString());
                while (pScene.LayerCount > 0)
                {
                    pScene.DeleteLayer(pScene.get_Layer(0));
                }
                // pScene.ClearLayers();
                pScene.AddLayer(pScene.ActiveGraphicsLayer);
                GC.Collect();
                for (int i = 0; i < m_pMapCtrl.Map.LayerCount; i++)
                {
                    ILayer pMapLayer = m_pMapCtrl.Map.get_Layer(i);
                    ILayer pLayer    = pMapLayer;

                    if (comboBoxExBaseHeightLayer.Items.Count > 0)
                    {
                        if (pLayer.Name == comboBoxExBaseHeightLayer.SelectedItem.ToString())
                        {
                            pBaseLayer = pLayer;
                        }
                    }
                }

                if (pBaseLayer is IRasterLayer)
                {
                    IRaster        pRaster  = ((IRasterLayer)pBaseLayer).Raster;
                    IRasterBand    pBand    = ((IRasterBandCollection)pRaster).Item(0);
                    IRasterSurface rsurface = new RasterSurface();
                    rsurface.RasterBand = pBand;
                    //将dem的数据指定为surface
                    pSurface = rsurface as ISurface;
                }
                if (pBaseLayer is ITinLayer)
                {
                    ITin        pTin        = ((ITinLayer)pBaseLayer).Dataset;
                    ITinSurface pTinSurface = pTin as ITinSurface;
                    pSurface = pTinSurface as ISurface;
                }


                for (int i = 0; i < m_pMapCtrl.Map.LayerCount; i++)
                {
                    ILayer pMapLayer = m_pMapCtrl.Map.get_Layer(i);

                    ILayer pLayer     = pMapLayer;
                    string filepath   = "";
                    string filename   = "";
                    string sourcepath = GetDataLayerPath(pMapLayer as IDataLayer, ref filepath, ref filename);

                    //if (pMapLayer is IRasterLayer)
                    //{
                    //    IRasterLayer prl = new RasterLayerClass();
                    //     prl.CreateFromRaster(((IRasterLayer)pMapLayer).Raster);
                    //     pLayer = prl as ILayer;
                    //}
                    if (pMapLayer is IFeatureLayer)
                    {
                        // if (((IFeatureLayer)pMapLayer).FeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultiPatch)
                        //  {

                        IFeatureLayer pfl = new FeatureLayerClass();
                        IFeatureClass pFc = ((IFeatureLayer)pMapLayer).FeatureClass;
                        if (pFc != null)
                        {
                            pfl.FeatureClass = ((IFeatureLayer)pMapLayer).FeatureClass;
                            pLayer           = pfl as ILayer;
                            pLayer.Name      = pMapLayer.Name;

                            /////////////////////////////////////////////////////////////////////
                            //后期添加,用于带进涂层渲染
                            /////////////////////////////////////////////////////////////////////
                            IGeoFeatureLayer pGeoFLayer  = pfl as IGeoFeatureLayer;
                            IGeoFeatureLayer pGFMapLayer = pMapLayer as IGeoFeatureLayer;
                            if (pGFMapLayer != null)  //注记图层为空
                            {
                                pGeoFLayer.Renderer = pGFMapLayer.Renderer;
                                ILegendInfo pLegend3D = (ILegendInfo)pGeoFLayer;
                                for (int k = 0; k < pLegend3D.LegendGroupCount; k++)
                                {
                                    ILegendGroup pLgroup = pLegend3D.LegendGroup[k];
                                    for (int p = 0; p < pLgroup.ClassCount; p++)
                                    {
                                        ILegendClass pLClass = pLgroup.Class[p];
                                        if (pLClass.Symbol is IMarkerSymbol)
                                        {
                                            IMarkerSymbol pSMSymbol = pLClass.Symbol as IMarkerSymbol;
                                            pSMSymbol.Size /= 20;
                                        }
                                    }
                                }
                                if (pFc.ShapeType == esriGeometryType.esriGeometryMultipoint || pFc.ShapeType == esriGeometryType.esriGeometryPoint)
                                {
                                    if (pGFMapLayer.Renderer is IUniqueValueRenderer)
                                    {
                                    }
                                }
                            }
                        }
                        //  }
                    }

                    #region 这段代码家的有点重复,如果不加有时候会弹出设置数据源的对话框
                    if (pLayer is IRasterLayer)
                    {
                        I3DProperties properties = null;

                        properties = new Raster3DPropertiesClass();
                        ILayerExtensions layerextensions = pLayer as ILayerExtensions;

                        object p3d;
                        for (int j = 0; j < layerextensions.ExtensionCount; j++)
                        {
                            p3d = layerextensions.get_Extension(j);
                            if (p3d != null)
                            {
                                properties = p3d as I3DProperties;
                                if (properties != null)
                                {
                                    break;
                                }
                            }
                        }
                        properties.BaseOption  = esriBaseOption.esriBaseSurface;
                        properties.BaseSurface = pSurface;
                        //I、更改分辨率后,如何让分辨率设置发挥作用。主要是刷新的问题(使用IActiveView刷新、而不能使用Iscene及IScenegraph刷新)
                        //II、分辨率数值在( 262144-268435456)范围之内,越大越清晰。使用3DProperties.MaxTextureMemory 方法
                        properties.MaxTextureMemory = 268435456;
                    }
                    #endregion
                    pScene.AddLayer(pLayer);
                    //if (((CheckBoxItem)itemPanelSetVisible.Items[i]).Checked == false)
                    //{
                    //    pLayer.Visible = false;
                    //}
                    //else
                    //{
                    //    pLayer.Visible = true;
                    //}
                    if (comboBoxExBaseHeightLayer.Items.Count > 0)
                    {
                        if (pLayer.Name == comboBoxExBaseHeightLayer.SelectedItem.ToString())
                        {
                            pBaseLayer = pLayer;
                        }
                    }
                }
            }

            if (pSurface != null)
            {
                for (int i = 0; i < m_pSceneCtrl.Scene.LayerCount; i++)
                {
                    ILayer pLayer = m_pSceneCtrl.Scene.get_Layer(i);

                    ILayerExtensions layerextensions = m_pSceneCtrl.Scene.get_Layer(i) as ILayerExtensions;
                    I3DProperties    properties      = null;
                    if (pLayer is IRasterLayer)
                    {
                        properties = new Raster3DPropertiesClass();
                    }
                    if (pLayer is IFeatureLayer)
                    {
                        properties = new Feature3DPropertiesClass();
                    }
                    if (pLayer is ITinLayer)
                    {
                        properties = new Tin3DPropertiesClass();
                    }
                    object p3d;
                    for (int j = 0; j < layerextensions.ExtensionCount; j++)
                    {
                        p3d = layerextensions.get_Extension(j);
                        if (p3d != null)
                        {
                            properties = p3d as I3DProperties;
                            if (properties != null)
                            {
                                break;
                            }
                        }
                    }
                    if (!(pLayer is IFeatureLayer))
                    {
                        properties.BaseOption  = esriBaseOption.esriBaseSurface;
                        properties.BaseSurface = pSurface;
                        //I、更改分辨率后,如何让分辨率设置发挥作用。主要是刷新的问题(使用IActiveView刷新、而不能使用Iscene及IScenegraph刷新)
                        //II、分辨率数值在( 262144-268435456)范围之内,越大越清晰。使用3DProperties.MaxTextureMemory 方法
                        properties.MaxTextureMemory = 268435456;
                    }
                    else
                    {
                        IFeatureLayer pFlayer = pLayer as IFeatureLayer;
                        //multipatch的本身有高度信息
                        if (pFlayer.FeatureClass != null && pFlayer.FeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultiPatch)
                        {
                            bool needConstantHeight = false;

                            /*
                             * try
                             * {
                             *  //把导航点转向角,视场角等信息都设置成不贴在表面而需要根据生产该信息的文件设置高度
                             *  IFeatureClass fc = pFlayer.FeatureClass;
                             *  IFeatureCursor pFcursor = fc.Search(null, false);
                             *  int OriginalFeatureidx = fc.FindField("OriginalFeatureClass");
                             *  int OriginalFeatureOIDidx = fc.FindField("OID");
                             *  IFeature pF = pFcursor.NextFeature();
                             *  IFeatureLayer pOFeatureLayer = null;
                             *  if (OriginalFeatureidx == -1|| OriginalFeatureOIDidx == -1)
                             *  {
                             *      pF = null;
                             *  }
                             *  else
                             *  {
                             *      if (pF != null)
                             *      {
                             *          //获取路径点图层名称
                             *          string orignalname = pF.get_Value(OriginalFeatureidx).ToString();
                             *          IMap pMap = m_pMapCtrl.Map;
                             *          for (int k = 0; k < pMap.LayerCount; k++)
                             *          {
                             *              if (pMap.get_Layer(k).Name.Equals(orignalname))
                             *              {
                             *                  pOFeatureLayer = pMap.get_Layer(k) as IFeatureLayer;
                             *                  break;
                             *              }
                             *          }
                             *          if (pOFeatureLayer == null)
                             *          {
                             *              pF = null;
                             *          }
                             *      }
                             *  }
                             *
                             *  while (pF != null)
                             *  {
                             *      //IFeatureClass pFClass = pOFeatureLayer.FeatureClass;
                             *      //pFClass.FindField(OriginalFeatureOIDidx);
                             *
                             *
                             *      pF = pFcursor.NextFeature();
                             *  }
                             * }
                             * catch
                             * {
                             *  ;
                             * }
                             */
                            if (needConstantHeight == false)
                            {
                                properties.BaseOption = esriBaseOption.esriBaseSurface;
                                //I3DProperties2 pr = properties as I3DProperties2;
                                //if (pr != null)
                                //{
                                //    pr.OffsetExpressionString = "0.005";
                                //}
                                //  properties.BaseOption = esriBaseOption.esriBaseExpression;
                                properties.BaseSurface = pSurface;
                                //I、更改分辨率后,如何让分辨率设置发挥作用。主要是刷新的问题(使用IActiveView刷新、而不能使用Iscene及IScenegraph刷新)
                                //II、分辨率数值在( 262144-268435456)范围之内,越大越清晰。使用3DProperties.MaxTextureMemory 方法
                                properties.MaxTextureMemory = 268435456;
                            }
                        }
                    }
                    //  properties.Apply3DProperties(domlayer);
                    // ps.SceneGraph.RefreshViewers();

                    IActiveView iv = m_pSceneCtrl.Scene as IActiveView;
                    iv.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null);
                }
            }
        }