首页 / 浏览问题 / 三维GIS / 问题详情
如何旋转kml图层的模型
66EXP 2017年10月26日
object.net 9d中,我将sgm加载到kml图层(示例代码如下),我通过修改GeoModel.RotationZ是可以实现沿Z轴旋转,但是我想问下组件中有没有像在idesktop可编辑状态下那样,可以选中一个模型,然后出现沿Z轴方向旋转的箭头,用户可以任意旋转模型。还是要自己写代码实现?

private void AddFeature(int smID,string modelFilePath, double RotationZ, GeoPoint3D position)
        {
            GeoPlacemark geoPlacemark = new GeoPlacemark();
            var geoModel = new GeoModel();
            geoModel.FromFile(modelFilePath);
            //人物模型朝向前进方向,如果原始方向一致则不需要旋转。
            geoModel.RotationZ = RotationZ;
            geoModel.Position = new Point3D { X = position.X, Y = position.Y, Z = position.Z };
            GeoStyle3D geoStyle3D = new GeoStyle3D();
            geoStyle3D.AltitudeMode = AltitudeMode.Absolute;
            geoModel.Style3D = geoStyle3D;
            geoPlacemark.Geometry = geoModel;
            Feature3Ds feture3Ds = m_layerKML.Features;
            Feature3D feature = new Feature3D();
            feature.Name = smID.ToString();//记录smID
            feature.Geometry = geoPlacemark;
            feature.Description = Path.GetFileNameWithoutExtension(modelFilePath);
            //feature.Name = feature.Description;
            feture3Ds.Add(feature);
            feture3Ds.ToKMLFile(m_layerKML.DataName);
        }

1个回答

和桌面一样的。只要kml图层设为可编辑,即可在点击模型后进行可视化编辑。
5,560EXP 2017年10月26日
恩,没错,谢谢。还有一个问题是,有没有事件可以监听这个模型发生了旋转?因为我要将这个模型的RotationZ保存到数据库。
这个没有。您可以考虑定时检测,或者由某些事件触发(检测所有模型的z值,看看是否有旋转)。
你好,我编辑模型,移动了位置,并做了旋转。我获取Feature3D.Geometry.Position数值的确有变化,可是Feature3D.Geometry.RotationZ一直是0.要如何获取变化后的RotationZ?

if (null == sceneControl || string.IsNullOrWhiteSpace(layerName))
                return;
            var layerKML = m_SceneControlHelper.GetLayer3DKML(sceneControl, layerName);
            if (null == layerKML||null== layerKML.Features|| layerKML.Features.Count<=0)
                return;
            var features = layerKML.Features.GetFeatureArray(Feature3DSearchOption.AllFeatures);
            if (null == features || features.Length <= 0)
                return;
            features.ToList().ForEach(feature =>
            {
                if (string.IsNullOrWhiteSpace(feature.Name))
                    throw new Exception("if(string.IsNullOrWhiteSpace(feature.Name))");
                var smID = Convert.ToInt32(feature.Name);
                Dictionary<string, object> values = new Dictionary<string, object>();
                values.Add(LocalConstsFields.Height, feature.Geometry.Position.Z);
                values.Add(LocalConstsFields.RotationZ, feature.Geometry.RotationZ);
                var geometry = new GeoPoint { X = feature.Geometry.Position.X, Y = feature.Geometry.Position.Y };
                RecordsetHelper.UpdateGeometry(LocalVariables.SpatialDatasourceConnectionInfo, layerName, smID, geometry, values);
            });
...