# 高频代码

This project is supported by bit >

# 打标绘点(以标注为例)

var handler11 = new LSGlobe.ScreenSpaceEventHandler(viewer.scene.canvas);
handler11.setInputAction(function (movement) {
        //获取的坐标上添加标绘点,具体的坐标获取参照坐标转换
        var Pos = scene.pickGlobe(movement.position);
        viewer.entities.add({
            //标注的坐标 x,y,z 经度纬度和高度的值
            position: new LSGlobe.Cartesian3(Pos.x, Pos.y, Pos.z),
            label: {
                text: "标注",
                //标注文字描述
                font: "32px Microsoft YaHei",
                //标注文字大小、字体
                style: LSGlobe.LabelStyle.FILL_AND_OUTLINE,
                outlineWidth: 6,
                translucencyByDistance: new LSGlobe.NearFarScalar(1.5e2, 1.0, 1.5e5, 0.0),
                //根据告诉改变透明度
                horizontalOrigin: LSGlobe.HorizontalOrigin.LEFT,
                pixelOffset: new LSGlobe.Cartesian2(15, -15),
                disableDepthTestDistance: 0,
                //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡
                scale: 0.5
            },
            billboard: {
                image: "http://uatonline.wish3d.com/GEMarker/1.png",
                //标注图标路径
                width: 64,
                height: 64,
                disableDepthTestDistance: 0,
                //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡
                scale: 0.5,
                translucencyByDistance: new LSGlobe.NearFarScalar(1.5e2, 1.0, 1.5e5, 0.0),
            },
            //标注唯一标识
            show: true //标绘点对象的true显示,false隐藏属性
        });
    },
    LSGlobe.ScreenSpaceEventType.LEFT_CLICK)
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
28
29
30
31
32
33
34
35
36
37

# 获取许可码和许可服务路径

//api_url :是Earth访问域名的host
var licenseCode, licenseUrl;
$.ajax ({
	url : api_url + "/wish3dearth/api/access/v1.0.0/getHardWareCode",
    type : "get",
    async : false,
    success:function(result){
    	if(result.code == 0){
    		licenseCode = result.data;
        	licenseUrl = api_url + "/wish3dearth/api/access/v1.0.0";
    	}else{
    		console.log(result);
    	}
    },
    error : function (err){
    	console.log(err);
    }
});

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# 拾取场景对象

var handler = new LSGlobe.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(movement) {
    viewer.scene.useDepthPicking = false;
    var aPickObj = scene.drillPick(movement.position);
    viewer.scene.useDepthPicking = true;
    for (var i = 0; i < aPickObj.length; i++) {
        var posit = aPickObj[i];
        if (posit.id && posit.id.billboard && posit.id.label) {
            //posit.id就是标会点对象
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12

# 获取当前的相机位置信息

# 获取当前相机的信息

var oPos=viewer.camera.position;
var oDirection=viewer.camera.direction;
var oUp=viewer.camera.up;
1
2
3

# 定位指定位置

 viewer.camera.flyTo({
            duration:1.5,//时长
            destination: new LSGlobe.Cartesian3(oPos.x, oPos.y, oPos.z),
            orientation: {
                direction: new LSGlobe.Cartesian3(oDirection.x, oDirection.y,oDirection.z),
                up: new LSGlobe.Cartesian3(oUp.x, oUp.y, oUp.z)
            }
        })
1
2
3
4
5
6
7
8
上次更新: 2020/12/8 下午2:51:52