Skip to content

矩形绘制

可视域分析需要额外调用接口,需要引用插件 ViewshedAnalysis.js 和 ViewshedAnalysis.css

HTML
<script src="SDK/Plugins/VectorEditor/RectangleEditor.js"></script>

绘制可视域分析开始

JavaScript
// drawDataSource存储
        var drawDataSource;
        var promise = viewer.dataSources.add(new LSGlobe.GeoJsonDataSource("drawDataSource"), {/*attachPolygon:true*/});
        promise.then(function (dataSource) {
            drawDataSource = dataSource;
        }).otherwise(function (error) {

        });

        //初始化标绘插件对象
        oVectorEditor = new LSGlobe.RectangleEditor(viewer);

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

        //在结束绘制同时取消编辑状态
        oVectorEditor.drawStoppedEvent.addEventListener(function (entity) {
            console.log('drawStoppedEvent', entity)
        });

        //绘制矩形
        oVectorEditor.material = LSGlobe.Color.fromCssColorString("blue");
        oVectorEditor.classificationType = undefined; //TERRAIN:贴地表,CESIUM_3D_TILE:贴模型,BOTH贴模型贴地表,undefined:空间线
        drawDataSource.editable = true; //drawDataSource.entites中集合可以再次编辑

        oVectorEditor.editStoppedEvent.addEventListener(fnEndPolyRectangleEdit);

        $("#polyRectangle").click(function () {
            initVectorEditerParams()

            oVectorEditor.startDrawing();
   
        })

删除绘制监听

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

示例代码 code

code示例地址

Released under the MIT License.