2.5.3 视点图层


视点图层

视点图层功能是指通过图层的方式来保存场景当前视点,然后调用图层的定位功能()来实现飞行定位的操作。

主要包括添加(创建)、更新、定位、删除和获取结果5种操作。

参数说明

视点图层可配置的参数如下表所示:

配置项 配置说明 值类型 备注
LayerOptionsName 图层配置对象名称 string 视点图层需配置为:ViewPointLayerOptions
Auto 是否自动获取 int 设置是否自动获取当前场景的视点信息。 1-自动获取;0-手动设置
Azimuth 方位角 double 水平方位角。角度在0-360度之间,超过会自动转换。弧度制
Pitch 俯仰角 double 垂直俯仰角。角度在 -89 - 89度之间。弧度制
Range 距离 double 相机到目标点的距离。取值需大于0.0
WorldPos 目标点坐标 x,y,z 相机指向目标位置坐标。需传入经度,纬度,高程坐标
FlyTime 飞行时间 double 设置飞行定位时间。默认3秒。当设为0时,将忽略飞行过程,直接定位到指定位置
IsGeoPoint 是否是目标点 bool 是否使用目标点定位。true-目标点;false-观察点。默认true

获取结果说明

视点图层可以通过图层对象的GetLayerResult() 方法获取结果。获取的结果值对象参数如下表所示:

配置项 配置说明 值类型 备注
DataSourceTypeName 数据源类型 string ViewPointLayer代表视点图层
GeoPos 目标点坐标 x,y,z 相机目标点的经度,纬度,高程坐标
Azimuth 方位角 double 水平方位角。角度在0-360度之间,超过会自动转换。弧度制
Pitch 俯仰角 double 垂直俯仰角。角度在 -89 - 89度之间。弧度制
Range 距离 double 相机到目标点的距离。取值需大于0.0

代码调用示例

Javascript调用

var viewPointLayer = null;
var azimuth = 0.51214;
//创建视点图层
function createViewPointLayer(state){
    if(viewPointLayer == null){
        var tlo = map.CreateLayerOptions("ViewPointLayer");//创建图层配置对象,任意名称
        tlo.AddConfig("LayerOptionsName", "ViewPointLayerOptions");//图层配置对象名称, ViewPointLayerOptions代表视点图层数据配置
        if(state){
            tlo.AddConfig("Auto", "1");//是否自动获取当前场景视点。1-自动获取,0-手动设置。默认值1
        }else{
            tlo.AddConfig("Auto", "0");//是否自动获取当前场景视点。
            tlo.AddConfig("Azimuth", "0.51214");//方位角设置 
            tlo.AddConfig("Pitch", "-0.386951");//俯仰角设置 
            tlo.AddConfig("Range", "52.23");//距离设置     
            tlo.AddConfig("WorldPos", "120.218178872,30.2095159402,34.642997");//目标位置设置,为经纬度坐标 
            tlo.AddConfig("FlyTime","1");//飞行定位的时间,单位为妙
            //tlo.AddConfig("IsGeoPoint","false");//是否使用目标点定位,false会使用观察点进行定位,默认为true
        }
        viewPointLayer = map.CreateLayer("ViewPointLayer", tlo);//创建视点图层,第一项参数为ViewPointLayer
        map.AddLayer(viewPointLayer);//添加图层
        viewPointLayer.Locate();//定位图层。如要获取视点信息结果,需先调用该接口
    }else{
        alert("图层已存在,无需重复创建!");
    }
}
//获取视点图层参数
function getViewPointLayerInfo(){
    if(viewPointLayer){
        var result = viewPointLayer.GetLayerResult();//获取图层结果
        if(result.GetConfigValueByKey("DataSourceTypeName") == "ViewPointLayer"){
            var geoPos = result.GetConfigValueByKey("GeoPos");//目标点坐标
            azimuth = result.GetConfigValueByKey("Azimuth");//方位角
            var pitch = result.GetConfigValueByKey("Pitch");//俯仰角
            var range = result.GetConfigValueByKey("Range");//与目标点距离
            alert("GeoPos:" + geoPos + " Azimuth:" + azimuth + " Pitch:" + pitch + " Range:" + range);
        }
    }else{
        alert("图层为空,无法获取信息!");
    }
}
//更新视点图层
function updateViewPointLayer(){
    if(viewPointLayer){
        azimuth += 0.5;
        var tlo = map.CreateLayerOptions("ViewPointLayer");//创建图层配置对象,任意名称
        tlo.AddConfig("LayerOptionsName", "ViewPointLayerOptions");//图层配置对象名称
        tlo.AddConfig("Auto", "0");//是否自动获取当前场景视点。
        tlo.AddConfig("Azimuth", String(azimuth));//方位角设置 
        tlo.AddConfig("Pitch", "-0.386951");//俯仰角设置 
        tlo.AddConfig("Range", "52.23");//距离设置     
        tlo.AddConfig("WorldPos", "120.218178872,30.2095159402,34.642997");//位置设置,为经纬度坐标 
        viewPointLayer.UpdateLayerOptions(tlo);//更新图层
        viewPointLayer.Locate();//定位图层
    }else{
        alert("图层为空,无法更新!");
    }
}
//定位视点图层
function locateViewPointLayer(){
    if(viewPointLayer){
        viewPointLayer.Locate();//定位图层
    }else{
        alert("图层为空,无法定位!");
    }
}
//删除视点图层
function removeViewPointLayer(){
    if(viewPointLayer){
        map.RemoveLayer(viewPointLayer);//移除图层
        viewPointLayer = null;
    }else{
        alert("图层为空,无法删除!");
    }
}

C++调用

BaseObjectCOMLib::ILayerObjectPtr viewPointLayer;//视点图层对象
std::string azimuth;//方位角参数
//加载视点图层
BaseObjectCOMLib::ILayerObjectPtr Cf4c2ViewPointLayerDlg::loadViewPointLayer(bool state)
{
    ConfigOptionsCOMLib::ILayerOptionsPtr tlo = (ConfigOptionsCOMLib::ILayerOptionsPtr)map->CreateLayerOptions("ViewPointLayer");//创建图层配置对象,任意名称
    tlo->AddConfig("LayerOptionsName", "ViewPointLayerOptions");//图层配置对象名称, ViewPointLayerOptions代表视点图层数据配置
    if(state){
        tlo->AddConfig("Auto", "1");//是否自动获取当前场景视点。1-自动获取,0-手动设置。默认值1
    }else{
        tlo->AddConfig("Auto", "0");//是否自动获取当前场景视点。
        tlo->AddConfig("Azimuth", "0.51214");//方位角设置 
        tlo->AddConfig("Pitch", "-0.386951");//俯仰角设置 
        tlo->AddConfig("Range", "52.23");//距离设置     
        tlo->AddConfig("WorldPos", "120.218178872,30.2095159402,34.642997");//目标位置设置,为经纬度坐标 
        tlo->AddConfig("FlyTime","1");//飞行定位的时间,单位为妙
        //tlo->AddConfig("IsGeoPoint","false");//是否使用目标点定位,false会使用观察点进行定位,默认为true
    }
    BaseObjectCOMLib::ILayerObjectPtr viewPointLayer = map->CreateLayer("ViewPointLayer", tlo);//创建视点图层,第一项参数为ViewPointLayer
    map->AddLayer(viewPointLayer);//添加图层
    return viewPointLayer;
}

//创建视点图层(获取)
void Cf4c2ViewPointLayerDlg::OnBnClickedcreateautoviewpointlayer()
{
    if(viewPointLayer)
    {
        return;
    }
    viewPointLayer = loadViewPointLayer(TRUE);//加载视点图层
    viewPointLayer->Locate();//定位图层。如要获取视点信息结果,需先调用该接口
}

//获取视点图层参数
void Cf4c2ViewPointLayerDlg::OnBnClickedgetviewpointlayerinfo()
{
    if(!viewPointLayer)
    {
        return;
    }
    ConfigOptionsCOMLib::ILayerOptionsPtr result = viewPointLayer->GetLayerResult();//获取图层结果
    std::string DataSourceTypeName = result->GetConfigValueByKey("DataSourceTypeName");//获取数据源类型
    if(DataSourceTypeName == "ViewPointLayer")
    {
        std::string geoPos = result->GetConfigValueByKey("GeoPos");//目标点坐标
        azimuth = result->GetConfigValueByKey("Azimuth");//方位角
        std::string pitch = result->GetConfigValueByKey("Pitch");//俯仰角
        std::string range = result->GetConfigValueByKey("Range");//与目标点距离
        std::cout << "geoPos:" << geoPos << "\n"<< "Azimuth: " << azimuth<< std::endl;
        std::cout << "Pitch:" << pitch << "\n"<< "Range: " << range<< std::endl;
    }
}

//创建视点图层(设置)
void Cf4c2ViewPointLayerDlg::OnBnClickedcreatemanualviewpointlayer()
{
    if(viewPointLayer)
    {
        return;
    }
    viewPointLayer = loadViewPointLayer(FALSE);//加载视点图层
    viewPointLayer->Locate();//定位图层。如要获取视点信息结果,需先调用该接口
}

//更新视点图层
void Cf4c2ViewPointLayerDlg::OnBnClickedupdateviewpointlayer()
{
    if(viewPointLayer){
        azimuth += 0.5;
        ConfigOptionsCOMLib::ILayerOptionsPtr tlo = (ConfigOptionsCOMLib::ILayerOptionsPtr)map->CreateLayerOptions("ViewPointLayer");//创建图层配置对象,任意名称
        tlo->AddConfig("LayerOptionsName", "ViewPointLayerOptions");//图层配置对象名称, ViewPointLayerOptions代表视点图层数据配置
        tlo->AddConfig("Auto", "0");//是否自动获取当前场景视点。
        tlo->AddConfig("Azimuth", azimuth.c_str());//方位角设置 
        tlo->AddConfig("Pitch", "-0.386951");//俯仰角设置 
        tlo->AddConfig("Range", "52.23");//距离设置     
        tlo->AddConfig("WorldPos", "120.218178872,30.2095159402,34.642997");//位置设置,为经纬度坐标
        viewPointLayer->UpdateLayerOptions(tlo);//更新图层
        viewPointLayer->Locate();//定位图层
    }
}

//定位视点图层
void Cf4c2ViewPointLayerDlg::OnBnClickedlocateviewpointlayer()
{
    if(viewPointLayer){
        viewPointLayer->Locate();//定位图层
    }
}

//删除视点图层
void Cf4c2ViewPointLayerDlg::OnBnClickedremoveviewpointlayer()
{
    if(viewPointLayer){
        map->RemoveLayer(viewPointLayer);//移除图层
        viewPointLayer = NULL;
    }
}

C#调用

ILayerObject viewPointLayer;
double azimuth = 0.51214;
//创建视点图层
private void createautoviewpointlayer_Click(object sender, EventArgs e)
{
    if (viewPointLayer == null)
    {
        var tlo = map.CreateLayerOptions("ViewPointLayer");//创建图层配置对象,任意名称
        tlo.AddConfig("LayerOptionsName", "ViewPointLayerOptions");//图层配置对象名称, ViewPointLayerOptions代表视点图层数据配置
        tlo.AddConfig("Auto", "1");//是否自动获取当前场景视点。1-自动获取,0-手动设置。默认值1  
        viewPointLayer = map.CreateLayer("ViewPointLayer", tlo);//创建视点图层,第一项参数为ViewPointLayer
        map.AddLayer(viewPointLayer);//添加图层
        viewPointLayer.Locate();//定位图层。如要获取视点信息结果,需先调用该接口
    }
    else
    {
        MessageBox.Show("图层已存在,无需重复创建!");
    }
}
//获取视点图层参数
private void getViewPointLayerInfo_Click(object sender, EventArgs e)
{
    if (viewPointLayer != null )
    {
        var result = viewPointLayer.GetLayerResult();//获取图层结果
        if (result.GetConfigValueByKey("DataSourceTypeName") == "ViewPointLayer")
        {
            var geoPos = result.GetConfigValueByKey("GeoPos");//目标点坐标
            var azimuth1 = result.GetConfigValueByKey("Azimuth");//方位角
            var pitch = result.GetConfigValueByKey("Pitch");//俯仰角
            var range = result.GetConfigValueByKey("Range");//与目标点距离
            MessageBox.Show("GeoPos:" + geoPos + " Azimuth:" + azimuth1 + " Pitch:" + pitch +
                " Range:" + range);
        }
    }
    else
    {
        MessageBox.Show("图层为空,无法获取信息!");
    }
}
//创建视点图层(设置)
private void createmanualviewpointlayer_Click(object sender, EventArgs e)
{
    if (viewPointLayer == null)
    {
        var tlo = map.CreateLayerOptions("ViewPointLayer");//创建图层配置对象,任意名称
        tlo.AddConfig("LayerOptionsName", "ViewPointLayerOptions");//图层配置对象名称, ViewPointLayerOptions代表视点图层数据配置
        tlo.AddConfig("Auto", "0");//是否自动获取当前场景视点。
        tlo.AddConfig("Azimuth", "0.51214");//方位角设置 
        tlo.AddConfig("Pitch", "-0.386951");//俯仰角设置 
        tlo.AddConfig("Range", "52.23");//距离设置     
        tlo.AddConfig("WorldPos", "120.218178872,30.2095159402,34.642997");//目标位置设置,为经纬度坐标 
        tlo.AddConfig("FlyTime","1");//飞行定位的时间,单位为妙
        //tlo.AddConfig("IsGeoPoint","false");//是否使用目标点定位,false会使用观察点进行定位,默认为true
        viewPointLayer = map.CreateLayer("ViewPointLayer", tlo);//创建视点图层,第一项参数为ViewPointLayer
        map.AddLayer(viewPointLayer);//添加图层
        viewPointLayer.Locate();//定位图层。如要获取视点信息结果,需先调用该接口
    }
    else
    {
        MessageBox.Show("图层已存在,无需重复创建!");
    }
}
//更新视点图层
private void updateViewPointLayer_Click(object sender, EventArgs e)
{
    if (viewPointLayer != null)
    {
        azimuth += 0.5;
        var tlo = map.CreateLayerOptions("ViewPointLayer");//创建图层配置对象,任意名称
        tlo.AddConfig("LayerOptionsName", "ViewPointLayerOptions");//图层配置对象名称, ViewPointLayerOptions代表视点图层数据配置
        tlo.AddConfig("Auto", "0");//是否自动获取当前场景视点。
        tlo.AddConfig("Azimuth", azimuth);//方位角设置 
        tlo.AddConfig("Pitch", "-0.386951");//俯仰角设置 
        tlo.AddConfig("Range", "52.23");//距离设置     
        tlo.AddConfig("WorldPos", "120.218178872,30.2095159402,34.642997");//位置设置,为经纬度坐标 
        viewPointLayer.UpdateLayerOptions(tlo);//更新图层
        viewPointLayer.Locate();//定位图层
    }
    else
    {
        MessageBox.Show("图层为空,无法更新!");
    }
}
//定位视点图层
private void locateViewPointLayer_Click(object sender, EventArgs e)
{
    if (viewPointLayer!=null)
    {
        viewPointLayer.Locate();//定位图层
    }
    else
    {
        MessageBox.Show("图层为空,无法定位!");
    }
}
//删除视点图层
private void removeViewPointLayer_Click(object sender, EventArgs e)
{
    if (viewPointLayer!=null)
    {
        map.RemoveLayer(viewPointLayer);//移除图层
        viewPointLayer = null;
    }
    else
    {
        MessageBox.Show("图层为空,无法删除!");
    }
}

results matching ""

    No results matching ""