# 插件的应用

This project is supported by bit >

# 线面绘制插件

# 线面插件的引用

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

# 线面插件的应用

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

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

# 绘制线

//绘制线
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);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# 绘制面

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

//绘制面
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);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# 指北针比例尺插件

# 指北针比例尺引用

<!--1).引用插件css文件 -->
<link href="Plugins/Navigation/Navigation.css" rel="stylesheet" type="text/css"/>
<!-- 如果想改变插件的位置修改该css文件即可 -->

<!--2).引用插件javascript文件 -->
<script type="text/javascript" src="Plugins/Navigation/viewerNavigationMixin.js"></script>

### 指北针比例尺应用
<!--3).将插件引入到场景中 -->
1
2
3
4
5
6
7
8
9

# 初始化指北针比例尺

viewer.extend(LSGlobe.viewerNavigationMixin);
1

# 量测插件

# 量测插件的引用

<!--1).引用插件css文件 -->
<link href="Plugins/Measure/Measure.css" rel="stylesheet" type="text/css"/>
<!-- 如果想改变插件的位置修改该css文件即可 -->

<!--2).引用插件javascript文件 -->
<script type="text/javascript" src="Plugins/Measure/Measure.js"></script>
1
2
3
4
5
6

# 初始化量测插件

//3).将插件引入到场景中
viewer.extend(LSGlobe.viewerMeasureMixin);
viewer.measureEditer.viewModel.editerVisible = false;//量测控件是否显示
//4).插件的使用
//空间距离测量
viewer.measureEditer.viewModel.Distance();
//空间面积测量
viewer.measureEditer.viewModel.AreaMeasure();
//空间高度测量(三角量测)
viewer.measureEditer.viewModel.HeightMeasure();
//坐标测量
viewer.measureEditer.viewModel.Point();
//清空所有量测的结果
viewer.measureEditer.viewModel.ClearAll();
//重置量测状态
viewer.measureEditer.viewModel.ResetState();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 模型编辑插件

模型编辑插件的使用主要为了在构建场景时快速的调整模型位置,所以模型编辑插件只能对实景三维模型和人工模型有效果,其中实景三维模型只能进行模型的左右和上下移动,人工模型可以进行模型和上下左右移动,还可进行模型绕z轴旋转

# 模型编辑引用

<!-- 1).引用插件css文件 -->
<link href="Plugins/EditBoxGeometry/EditBoxGeometry.css" rel="stylesheet" type="text/css"/>
<!-- 如果想改变插件的位置修改该css文件即可 -->

<!--2).引用插件javascript文件 -->
<script type="text/javascript" src="Plugins/EditBoxGeometry/EditBoxGeometry.js"></script>

1
2
3
4
5
6
7

# 模型编辑应用

//初始化模型平移插件
viewer.extend(LSGlobe.viewerEditBoxGeometryMixin);

//插件的使用
//1).添加对象
//添加某个想要编辑对象到插件中开始编辑(对象必须是人工或实景三维模型)
viewer.boxEditBoxGeometry.viewModel.editObject = "获取到的人工或者实景三维对象";
//2).设置平移模式
//只能上下左右平移的对象
viewer.boxEditBoxGeometry.viewModel.move();
//即能上下左右平移也可绕z轴旋转(人工模型)
viewer.boxEditBoxGeometry.viewModel.all();
//3).在球中拖动编辑框编辑刚刚插入的编辑对象
//4).编辑状态的保存
//模型平移结果在保存场景json的时候(viewer.toJSON())自动保存
//5).点击到编辑模型框的外面自动结束编辑状态
//插件的常用接口
//隐藏xyz轴、缩放
viewer.boxEditBoxGeometry.viewModel.cancel();
//xyz轴显示隐藏
viewer.boxEditBoxGeometry.viewModel.showAxis=true
//提示文字的显示隐藏
viewer.boxEditBoxGeometry.viewModel.showTooltip=false;
//z轴平移圆锥显隐
viewer.boxEditBoxGeometry.viewModel._showCylinder=true;
//获取模型的底部高度
viewer.boxEditBoxGeometry.viewModel.bottomHeight
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

# 大矢量数据加载插件

参照前面矢量数据的预览功能

# 水面插件

参照前面水面功能功能

上次更新: 2021/2/1 上午11:19:39