1.相机高度获取方法
function getHeight() {
if (viewer) {
var scene = viewer.scene;
var ellipsoid = scene.globe.ellipsoid;
var height = ellipsoid.cartesianToCartographic(viewer.camera.position).height;
return height;
}
}
console.log(getHeight());
2.相机高度缩放高度范围
viewer.scene.screenSpaceCameraController.minimumZoomDistance = 0;//相机高度缩放高度范围
viewer.scene.screenSpaceCameraController.maximumZoomDistance = 2800;//相机高度缩放高度范围
3.相机视角各个值的获取
console.log(viewer.scene.camera.heading);
console.log(viewer.scene.camera.pitch);
console.log(viewer.scene.camera.roll);
console.log(viewer.scene.camera.position)
var initialPosition = new Cesium.Cartesian3(-2704200.415014977, 4702023.785328262, 3345501.4084866922); // 相机的位置
var orientation = {
heading: 6.283185307179586,
// 视角
pitch: -1.5686521559334161,
roll: 0,
};
var homeCameraView = {
destination: initialPosition, // 相机的位置
orientation: orientation,
};
viewer.scene.camera.setView(homeCameraView);
4.定位多个点
// 倾斜摄影数据上添加lable的方法
putLables(_datas, _parent) {
let _this = this;
for (let i = 0; i < _datas.length; i++) {
let data = _datas[i];
let entity = _this.viewer.entities.add({
//参数顺序:经度、纬度
position: Cesium.Cartesian3.fromDegrees(
data.lon,
data.lat
//data.height
), //标签的位置
parent: _parent,
id: "measure_tip" + data.id,
code: data.type,
billboard: {
//图标
show: true,
image: data.pic,
scaleByDistance: new Cesium.NearFarScalar(2000, 1, 10000, 0.5), //当摄像头和Billboard之间距离小于2000的时候,就按照2000时候的值1处理(这里如果不是1,而是0.5,那小于2000时候的比例就是0.5了)。而当大于8000的时候,就会按照0(其实就是8000对应的比例值)缩放。
disableDepthTestDistance: Number.POSITIVE_INFINITY, //广告牌的文字不进行深度检测
},
label: {
text: data.name,
font: "0.18rem/0.36rem Microsoft YaHei",
show: false,
showBackground: true, //是否显示背景颜色
backgroundColor: new Cesium.Color.fromBytes(53, 111, 185, 255),
backgroundPadding: new Cesium.Cartesian2(20, 10),
style: Cesium.LabelStyle.FILL,
fillColor: Cesium.Color.fromCssColorString("#fff"),
// eyeOffset: new Cesium.Cartesian3(0, 0, -10000),
//outlineColor: Cesium.Color.fromCssColorString('#fff'),
//distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 1500),
scaleByDistance: new Cesium.NearFarScalar(2000, 1, 8000, 0.8),
//heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,//防止label 显示隐藏到地底下
outlineWidth: 3,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
pixelOffset: new Cesium.Cartesian2(0, -20), //此属性为设置偏移量
disableDepthTestDistance: Number.POSITIVE_INFINITY, //广告牌的文字不进行深度检测
},
type: data.id, //自定义属性
});
const nametooltip = document.createElement("div");
nametooltip.id = "measure_tip" + data.id;
nametooltip.className = "tip-class1";
nametooltip.innerHTML = data.name;
document.getElementById("container").appendChild(nametooltip);
}
},
5.围绕中心点旋转
viewer.trackedEntity = entity;