Skip to content
On this page

Focused Pragmatic

ZhongKeTuXin

Open Innovate

线面绘制插件

线面插件的引用

HTML
<!-- 在引入LSGlobe.js后引用插件javascript文件 -->
<script type="text/javascript" src="Plugins/VectorEditor/VectorEditor.js"></script>

线面插件的应用

使用前需要初始化标会插件

JavaScript
//初始化标绘插件对象
var oVectorEditor = new LSGlobe.VectorEditor(viewer);
//在结束绘制同时取消编辑状态
oVectorEditor._endDrawEvent.addEventListener(function () {
    oVectorEditor.endEdit();
});

绘制线

JavaScript
//绘制线
oVectorEditor.lineWidth = 5;//线宽
oVectorEditor.color = LSGlobe.Color.fromCssColorString("#FF0000");//线颜色
oVectorEditor.lineType = LSGlobe.LineTypeLSGlobe.LineType.SOLID//SOLID:实线,DASH:虚线,DOT:浮点,DASHDOT:-.-.-,DASHDOTDOT:-..-..
oVectorEditor.classificationType = undefined//TERRAIN:贴地表,CESIUM_3D_TILE:贴模型,BOTH贴模型贴地表,undefined:空间线
drawDataSource.editable = true; //drawDataSource.entites中集合可以再次编辑
oVectorEditor._endEditEvent.addEventListener(fnEndPolylineEdit);

var fnEndPolylineEdit = function(entity) {
    //检测标绘集合中是否已经含有该entity
    if (!drawDataSource.entities.getById(entity.id)) {
        //添加到场景中
        drawDataSource.entities.add(entity);
        //也可以扩展其他功能,如向树节点添加节点等
    }else{
        //修改当前entity,参照标绘编辑--线编辑
    }
    viewer.entities.removeById(sEntityGuid);
}
oVectorEditor.drawPolyline();

//如需要删除该回调可以用删除监听接口
oVectorEditor._endEditEvent.removeEventListener(fnEndPolylineEdit);

绘制面

标绘面功能在我们场景中使用比较广,如单体化、压平、裁剪、水面等都有用到。此处主要介绍怎样绘出面,拿到面怎样扩展我们可以参照前面单体化、压平、裁剪、水面的接口,进行下一步的操作。

JavaScript
//绘制面
oVectorEditor.lineWidth = 1;//线宽(仅空间面支持,且只有1有效)
oVectorEditor.color = LSGlobe.Color.fromCssColorString("#FF0000");//面颜色
oVectorEditor.classificationType = undefined//TERRAIN:贴地表,CESIUM_3D_TILE:贴模型,BOTH贴模型贴地表,undefined:空间线
oVectorEditor.outlinecolor = LSGlobe.Color.fromCssColorString("rgba(255,255,255,0)");

oVectorEditor._endEditEvent.addEventListener(fnEndPolygonEdit);

var fnEndPolygonEdit = function(entity) {
    //检测标绘集合中是否已经含有该entity
    if (!drawDataSource.entities.getById(entity.id)) {
        //添加到场景中
        drawDataSource.entities.add(entity);
        //也可以扩展其他功能,如向树节点添加节点等
    }else{
        //修改当前entity,参照标绘编辑--线编辑
    }
    viewer.entities.removeById(sEntityGuid);

    var positions = entity.polygon.hierarchy.getValue().positions//拿到面的点参照对应接口,可以进行压平、裁剪、水面
}
oVectorEditor.drawPolygon();

//如需要删除该回调可以用删除监听接口
oVectorEditor._endEditEvent.removeEventListener(fnEndPolygonEdit);

示例代码 code

code示例地址

Released under the MIT License.