2.4.1 几何图形绘制


几何图形绘制

几何图形绘制是指在三维空间内进行简单的几何图形绘制的功能。

CooRun SDK支持绘制矩形、圆、多边形和线四种类型。其中,矩形和圆是在同一个水平面上进行绘制的。

几何图形绘制主要包括添加(创建)、更新、显隐、删除和获取结果5种操作。

注意:可创建空的绘制图层,也可创建预设的绘制图层,如需创建预设绘制图层,则IsLoad, IsActive, Points 三个参数需要同时配置。

下图是几何图形绘制效果:

  

参数说明

几何图形绘制可配置的参数如下表所示:

配置项 配置说明 值类型 备注
LayerOptionsName 图层配置对象名称 string 分析图层需配置为:AnalysisLayerOptions
DataSourceTypeName 数据源类型 string as_draw2dobject代表几何图形绘制
DrawType 绘制类型 int 几何图形的绘制类型。0-矩形; 1-圆; 2-多边形; 3-线。默认为0
PointColor 点颜色 R,G,B,A 颜色取值范围在0-1.0之间,如 "0.9,0.8,0.8,1.0"
PointSize 点大小 float 点大小取值范围在1-10之间
DrawLineColor 线颜色 R,G,B,A 颜色取值范围在0-1.0之间,如 "0.9,0.8,0.8,1.0"
DrawFaceColor 绘制面颜色 R,G,B,A 颜色取值范围在0-1.0之间,如 "0.9,0.8,0.8,1.0"
VisibleLine 是否显示线 bool 同时控制顶点和线的显示状态。默认为false
VisibleFace 是否显示面 bool 默认为false
SplitPointNum 圆分割数量 int 该值确定圆外围形状,数值越大越接近于圆。可以通过该方式绘制4、6、8等多边形形状。默认为0
LiftUp 抬高高度 float 将绘制结果整体抬高高度。该值是为了避免闪面而设定的。单位m,默认0.0
IsLoad 是否初始化加载点 bool 默认为false
IsActive 是否激活分析 bool 默认为true,表示是否可操作场景进行绘制
Points 坐标点集 x,y,z列表 需传入经度,纬度,高程坐标集,中间用;分隔,并以;结尾
IsWorld 是否世界坐标点 bool 传入的坐标是否是世界坐标。true-世界坐标,false-经纬度坐标。默认为true

获取结果说明

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

配置项 配置说明 值类型 备注
DataSourceTypeName 数据源类型 string as_draw2dobject代表几何图形绘制
ClickPoints 关键点坐标 x,y,z列表 鼠标点击场景形成的关键点的经度,纬度,高程坐标列表,中间用;分隔,并以;结尾
DrawType 绘制类型 int 几何图形的绘制类型。0-矩形; 1-圆; 2-多边形; 3-线。默认为0

代码调用示例

Javascript调用

var layerMap = [null, null, null, null];
var mySelect = document.getElementById("Select");
var loadState = false;
//绘制几何
function addGeometry(loadState) {
    //创建图层配置信息
    if(layerMap[mySelect.selectedIndex] == null){
        var value = mySelect.options[mySelect.selectedIndex].value;
        var tlo = map.CreateLayerOptions("draw2dcircle");//创建图层配置对象,任意名称
        tlo.AddConfig("LayerOptionsName", "AnalysisLayerOptions");//图层配置对象名称, AnalysisLayerOptions代表分析图层数据配置
        tlo.AddConfig("DataSourceTypeName", "as_draw2dobject");//数据源类型,as_draw2dobject代表2D几何图形
        tlo.AddConfig("PointColor", "0.0,0.0,1.0,1.0");//点颜色
        tlo.AddConfig("PointSize", "5");//点大小
        tlo.AddConfig("DrawLineColor", "1.0,1.0,0.0,1.0");//线颜色(RGBA)
        tlo.AddConfig("DrawFaceColor", "1,0,0,0.3");//面颜色(RGBA)
        tlo.AddConfig("VisibleLine", "true");//是否显示线框(顶点和线框是同时显示/隐藏的)
        tlo.AddConfig("VisibleFace", "true");//是否显示面
        tlo.AddConfig("SplitPointNum", "10");//圆分割数量。当绘制类型为圆时起效
        tlo.AddConfig("DrawType", value);//绘制类型。0-矩形,1-圆,2-多边形,3-线 
        tlo.AddConfig("LiftUp", "0.1");//抬高高度。
        //下列三个配置可选
        if(loadState){
            tlo.AddConfig("IsLoad","true" );//是否加载点坐标
            tlo.AddConfig("IsActive","false" );//是否激活绘制
            tlo.AddConfig("IsWorld","false" ); //传入的点位是否为世界坐标,true为世界坐标,false为经纬度坐标
            tlo.AddConfig("Points","120.205420708,30.2416892474,15.07;120.20489575,30.2417527978,0;"); //点坐标
        }
        var geoLayer = map.CreateLayer("AnalysisLayer", tlo);//创建分析图层,第一项参数为AnalysisLayer
        map.AddLayer(geoLayer);//添加图层
        layerMap[mySelect.selectedIndex] = geoLayer;
    }else{
        alert("该类型图层已创建,请勿重复创建!");
    }
}
//更新几何
function updateGeometry(){
    if(layerMap[mySelect.selectedIndex] != null){
        var tlo = map.CreateLayerOptions("draw2dcircle");//创建图层配置对象,任意名称
        tlo.AddConfig("LayerOptionsName", "AnalysisLayerOptions");//图层配置对象名称, AnalysisLayerOptions代表分析图层数据配置
        tlo.AddConfig("DataSourceTypeName", "as_draw2dobject");//数据源类型,as_draw2dobject代表2D几何图形
        tlo.AddConfig("DrawLineColor", "1.0,0.0,1.0,1.0");//线颜色(RGBA)
        tlo.AddConfig("DrawFaceColor", "0,1,0,0.3");//面颜色(RGBA)
        tlo.AddConfig("LiftUp", "100");//抬高高度
        layerMap[mySelect.selectedIndex].UpdateLayerOptions(tlo);//更新图层
    }else{
        alert("图层为空,请创建后更新!");
    }
}
//获取几何结果
function getGeometryResult(){
    if(layerMap[mySelect.selectedIndex] != null){
        var result = layerMap[mySelect.selectedIndex].GetLayerResult();//获取图层结果
        if(result.GetConfigValueByKey("DataSourceTypeName") == "as_draw2dobject"){
            var drawType = result.GetConfigValueByKey("DrawType");//获取绘制类型
            var points = result.GetConfigValueByKey("ClickPoints");//获取关键点集
            alert("DrawType:" + drawType + "  Points:" + points);
        }
    }else{
        alert("图层为空,请创建后更新!");
    }
}
//删除几何
function removeGeometry() {
    if(layerMap[mySelect.selectedIndex] != null){
        map.RemoveLayer(layerMap[mySelect.selectedIndex]);//删除图层
        layerMap[mySelect.selectedIndex] = null;
    }
}

C++调用

BaseObjectCOMLib::ILayerObjectPtr draw2dobjectMeasure;//几何绘制图层对象
String value;
//设置下拉框的值
void Cf3c0Draw2dobjectDlg::OnCbnSetfocusCombo1()
{
    m_combo.ResetContent();//清空下拉框
    m_combo.AddString(L"园");
    m_combo.AddString(L"矩形");
    m_combo.AddString(L"多边形");
    m_combo.AddString(L"折线");
    m_combo.SetCurSel(-1);
}
//获取下拉框的值
void Cf3c0Draw2dobjectDlg::OnCbnSelchangeCombo1()
{
    CString m_paramname;
    m_combo.GetLBText(m_combo.GetCurSel(),m_paramname);
    value = CT2A(m_paramname.GetBuffer());
    if(value == "矩形")
    {
        value = "0";
    }
    else if(value == "园")
    {
        value = "1";
    }
    else if(value == "多边形")
    {
        value = "2";
    }
    else if(value == "折线")
    {
        value = "3";
    }
}
//绘制几何
void Cf3c0Draw2dobjectDlg::OnBnClickedaddgeometry()
{
    if(draw2dobjectMeasure)
    {
        OnBnClickedremovegeometry();
    }
    ConfigOptionsCOMLib::ILayerOptionsPtr tlo = (ConfigOptionsCOMLib::ILayerOptionsPtr)map->CreateLayerOptions(""); //创建图层配置对象,任意名称
    tlo->AddConfig("LayerOptionsName", "AnalysisLayerOptions");//图层配置对象名称, AnalysisLayerOptions代表分析图层数据配置
    tlo->AddConfig("DataSourceTypeName", "as_draw2dobject");//数据源类型,as_draw2dobject代表2D几何图形
    tlo->AddConfig("PointColor", "0.0,0.0,1.0,1.0");//点颜色
    tlo->AddConfig("PointSize", "5");//点大小
    tlo->AddConfig("DrawLineColor", "1.0,1.0,0.0,1.0");//线颜色(RGBA)
    tlo->AddConfig("DrawFaceColor", "1,0,0,0.3");//面颜色(RGBA)
    tlo->AddConfig("VisibleLine", "true");//是否显示线框(顶点和线框是同时显示/隐藏的)
    tlo->AddConfig("VisibleFace", "true");//是否显示面
    tlo->AddConfig("SplitPointNum", "10");//圆分割数量。当绘制类型为圆时起效
    tlo->AddConfig("DrawType", value.c_str());//绘制类型。0-矩形,1-圆,2-多边形,3-线 
    tlo->AddConfig("LiftUp", "0.1");//抬高高度。
    draw2dobjectMeasure = map->CreateLayer("AnalysisLayer", tlo);//创建分析图层,第一项参数为AnalysisLayer
    map->AddLayer(draw2dobjectMeasure);//添加图层
}
//更新几何
void Cf3c0Draw2dobjectDlg::OnBnClickedupdategeometry()
{
    if(!draw2dobjectMeasure)
    {
        return;
    }
    ConfigOptionsCOMLib::ILayerOptionsPtr tlo = (ConfigOptionsCOMLib::ILayerOptionsPtr)map->CreateLayerOptions(""); //创建图层配置对象,任意名称
    tlo->AddConfig("LayerOptionsName", "AnalysisLayerOptions");//图层配置对象名称, AnalysisLayerOptions代表分析图层数据配置
    tlo->AddConfig("DataSourceTypeName", "as_draw2dobject");//数据源类型,as_draw2dobject代表2D几何图形
    tlo->AddConfig("DrawLineColor", "1.0,0.0,1.0,1.0");//线颜色(RGBA)
    tlo->AddConfig("DrawFaceColor", "0,1,0,0.3");//面颜色(RGBA)
    tlo->AddConfig("LiftUp", "100");//抬高高度
    draw2dobjectMeasure->UpdateLayerOptions(tlo);//更新图层
}
//获取几何结果
void Cf3c0Draw2dobjectDlg::OnBnClickedgetgeometryresult()
{
    if(!draw2dobjectMeasure)
    {
        return;
    }
    ConfigOptionsCOMLib::ILayerOptionsPtr opt = draw2dobjectMeasure->GetLayerResult();
    std::string DataSourceTypeName = opt->GetConfigValueByKey("DataSourceTypeName");//获取数据源类型
    if(DataSourceTypeName == "as_draw2dobject")
    {
        CString DrawType = opt->GetConfigValueByKey("DrawType");//获取绘制类型
        CString Points = opt->GetConfigValueByKey("ClickPoints");//获取关键点集
        MessageBox(L"DrawType:"+ DrawType+ L"\r\nPoints:"+Points);
    }
}

//删除几何
void Cf3c0Draw2dobjectDlg::OnBnClickedremovegeometry()
{
    if(!draw2dobjectMeasure)
    {
        return;
    }
    map->RemoveLayer(draw2dobjectMeasure);//删除图层
    draw2dobjectMeasure = NULL;
}

C#调用

ILayerObject[] layerMap = new ILayerObject[4];//几何图层
int selectedIndex;
//绘制几何
private void addGeometry_Click(object sender, EventArgs e)
{
    Console.WriteLine("Text:" + comboBox1.SelectedItem.ToString());
    switch (comboBox1.SelectedItem.ToString())
    {
        case "矩形":
            selectedIndex = 0;
            break;
        case "圆":
            selectedIndex = 1;
            break;
        case "多边形":
            selectedIndex = 2;
            break;
        case "折线":
            selectedIndex = 3;
            break;
    }
    loadGeometry();
}
//创建几何图形绘制图层
private void loadGeometry()
{
    //创建图层配置信息
    if (layerMap[selectedIndex] == null)
    {
        ILayerOptions tlo = map.CreateLayerOptions("draw2dcircle");//创建图层配置对象,任意名称
        tlo.AddConfig("LayerOptionsName", "AnalysisLayerOptions");//图层配置对象名称, AnalysisLayerOptions代表分析图层数据配置
        tlo.AddConfig("DataSourceTypeName", "as_draw2dobject");//数据源类型,as_draw2dobject代表2D几何图形
        tlo.AddConfig("PointColor", "0.0,0.0,1.0,1.0");//点颜色
        tlo.AddConfig("PointSize", "5");//点大小
        tlo.AddConfig("DrawLineColor", "1.0,1.0,0.0,1.0");//线颜色(RGBA)
        tlo.AddConfig("DrawFaceColor", "1,0,0,0.3");//面颜色(RGBA)
        tlo.AddConfig("VisibleLine", "true");//是否显示线框(顶点和线框是同时显示/隐藏的)
        tlo.AddConfig("VisibleFace", "true");//是否显示面
        tlo.AddConfig("SplitPointNum", "10");//圆分割数量。当绘制类型为圆时起效
        tlo.AddConfig("DrawType", selectedIndex.ToString());//绘制类型。0-矩形,1-圆,2-多边形,3-线 
        tlo.AddConfig("LiftUp", "0.1");//抬高高度。
        //下列三个配置可选
        //tlo.AddConfig("IsLoad", "true");//是否加载点坐标
        //tlo.AddConfig("IsActive", "false");//是否激活绘制
        //tlo.AddConfig("IsWorld","false" ); //传入的点位是否为世界坐标,true为世界坐标,false为经纬度坐标
        //tlo.AddConfig("Points", "120.205420708,30.2416892474,15.07;120.20489575,30.2417527978,0;"); //点坐标
        ILayerObject geoLayer = map.CreateLayer("AnalysisLayer", tlo);//创建分析图层,第一项参数为AnalysisLayer
        map.AddLayer(geoLayer);//添加图层
        layerMap[selectedIndex] = geoLayer;
    }
    else
    {
        MessageBox.Show("该类型图层已创建,请勿重复创建!");
    }
}
//更新几何
private void updateGeometry_Click(object sender, EventArgs e)
{
    if (layerMap[selectedIndex] != null)
    {
        ILayerOptions tlo = map.CreateLayerOptions("draw2dcircle");//创建图层配置对象,任意名称
        tlo.AddConfig("LayerOptionsName", "AnalysisLayerOptions");//图层配置对象名称, AnalysisLayerOptions代表分析图层数据配置
        tlo.AddConfig("DataSourceTypeName", "as_draw2dobject");//数据源类型,as_draw2dobject代表2D几何图形
        tlo.AddConfig("DrawLineColor", "1.0,0.0,1.0,1.0");//线颜色(RGBA)
        tlo.AddConfig("DrawFaceColor", "0,1,0,0.3");//面颜色(RGBA)
        tlo.AddConfig("LiftUp", "100");//抬高高度
        layerMap[selectedIndex].UpdateLayerOptions(tlo);//更新图层
    }
    else
    {
        MessageBox.Show("图层为空,请创建后更新!");
    }
}
//获取结果
private void getGeometryResult_Click(object sender, EventArgs e)
{
    if (layerMap[selectedIndex] != null)
    {
        ILayerOptions result = layerMap[selectedIndex].GetLayerResult();//获取图层结果
        if (result.GetConfigValueByKey("DataSourceTypeName") == "as_draw2dobject")
        {
            string drawType = result.GetConfigValueByKey("DrawType");//获取绘制类型
            string points = result.GetConfigValueByKey("ClickPoints");//获取关键点集
            MessageBox.Show("DrawType:" + drawType + "  Points:" + points);
        }
    }
    else
    {
        MessageBox.Show("图层为空,请创建后更新!");
    }
}
//删除几何
private void removeGeometry_Click(object sender, EventArgs e)
{
    if (layerMap[selectedIndex] != null)
    {
        map.RemoveLayer(layerMap[selectedIndex]);//删除图层
        layerMap[selectedIndex] = null;
    }
}

results matching ""

    No results matching ""