首页 / 浏览问题 / 桌面GIS / 问题详情
SceneControl的Action属性
9EXP 2017年06月06日
SceneControl的Action属性设置后,场景还是不可编辑。还需要设置其他属性吗?

补充:场景有个KML图层,可编辑属性也设置为true

1个回答

您好,您可以参考以下代码对kml图层进行编辑

 public void Geometry3DSample(Scene sceneObject)
 {
    // 得到顶层的三维要素对象
    Layer3D layer3D = sceneObject.Layers.Add(@"D:\SampleData\kml.kml",Layer3DType.KML, true);
    Feature3D feature3D = layer3D.Features[0] as Feature3D;

    // 获得三维要素对应的三维几何对象
    GeoPlacemark geoPlacemark = feature3D.Geometry as GeoPlacemark;
     Geometry3D geometry3D = geoPlacemark.Geometry as Geometry3D;

    // 将三维几何对象进行平移
    geometry3D.Offset(10, 10, 12);

    // 设置三维几何对象的属性
    geometry3D.ID = 25;
    geometry3D.Position = new Point3D(20, 25, 20);
    geometry3D.RotationX = 10;
    geometry3D.RotationY = 15;
    geometry3D.RotationZ = 5;
    geometry3D.ScaleX = 0.5;
    geometry3D.ScaleY = 0.8;
    geometry3D.ScaleZ = 1.2;

    // 释放资源
    geometry3D.Dispose();
    feature3D.Dispose();
}

5,560EXP 2017年06月06日
我想做的是在球星场景上移动鼠标画线,有实例代码吗?还有这个Action 是不是CAD图层可以编辑时才能用?KML图层不能用

KML图层仅用来展示模型,不能用来存储矢量对象。您要想画线并展示的话,有两种方法,一是将画好的线添加到三(二)维线数据集或者CAD数据集,且该数据集在场景里有相应的图层;二是利用跟踪图层将画好的线实时展示出来。

利用跟踪图层绘制线的方法可参考如下代码:

        private void select_Click(object sender, EventArgs e)
        {
            try
            {
                p2ds = new Point2Ds();
                curPoint2D = new Point2D();
                sceneControl.Action = Action3D.MeasureArea;
                sceneControl.TrackMode = TrackMode3D.Track;
                sceneControl.MouseClick += new MouseEventHandler(mouse_Click);
                sceneControl.Tracking += new Tracking3DEventHandler(track_On);
                sceneControl.Tracked += new Tracked3DEventHandler(track_End);
            }
            catch
            {
                
            }
        }

        private void mouse_Click(Object sender, MouseEventArgs e)
        {
            switch (e.Button)
            {
                case MouseButtons.Left:
                    if(sceneControl.TrackMode == TrackMode3D.Track)
                    {
                        p2ds.Add(curPoint2D);
                    }
                    break;
                default:
                    break;
            }
        }

        private void track_On(Object sender, Tracking3DEventArgs e)
        {
            realtimeTextPart(e);
        }

        private void track_End(Object sender, Tracked3DEventArgs e)
        {
            try
            {
                GeoRegion grDisplay = new GeoRegion(p2ds);
                sceneControl.Scene.TrackingLayer.Add(grDisplay, "range");
            }
            catch { }

            sceneControl.TrackMode = TrackMode3D.Edit;
            sceneControl.Action = Action3D.Pan2;
            sceneControl.MouseClick += null;
            sceneControl.Tracking -= track_On;
            sceneControl.Tracked -= track_End;
            sceneControl.MouseClick -= mouse_Click;
        }

        private void realtimeTextPart(Tracking3DEventArgs e)
        {
            tp3d = new TextPart3D();
            tp3d.AnchorPoint = new Point3D(e.X, e.Y, e.Z);
            curPoint2D = new Point2D();
            curPoint2D.X = e.X;
            curPoint2D.Y = e.Y;

            //Point2Ds curPoint2Ds = new Point2Ds();
            //curPoint2Ds.Add(new Point2D(e.X,e.Y));
            //PrjCoordSys prj = workspace.Datasources[comboBox1.Text].PrjCoordSys;
            //CoordSysTranslator.Forward(curPoint2Ds, prj);
            //Point2D tempP2d = curPoint2Ds[0];
            tp3d.Text = "X=" + Math.Round(tempP2d.X, 2) + " Y=" + Math.Round(tempP2d.Y, 2);
            TextStyle textStyle = new TextStyle();
            textStyle.ForeColor = Color.Black;
            textStyle.BackColor = Color.White;
            textStyle.FontHeight = 6;
            gt3d = new GeoText3D(tp3d, textStyle);
            gt3d.Style3D = new GeoStyle3D();
            gt3d.Style3D.AltitudeMode = AltitudeMode.Absolute;
            if(sceneControl.Scene.TrackingLayer.Count != 0)
            {
                sceneControl.Scene.TrackingLayer.Clear();
            }
            sceneControl.Scene.TrackingLayer.Add(gt3d, "Temp_Position" + sceneControl.Scene.TrackingLayer.Count);
        }

...