Cesium(四)常⽤代码总结
1、阴影效果
viewer.shadows = true;
2、取消左键双击事件
鹿肉做法3、定位飞到某处
逢场作戏的意思
viewer.scene.camera.flyTo({ destination: rectangle });
4、开启灯光
ableLighting = true;
5、限制缩放距离
scene.screenSpaceCameraController.minimumZoomDistance = 100;
6、解决Cesium绘制⼏何图形被⾼程遮挡问题
viewer.scene.globe.depthTestAgainstTerrain = true;
7、point贴地
var point = ities.add({
position: worldPosition,
point: {
pixelSize: 10,
color: Cesium.Color.YELLOW,
//控制是否贴地
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
},
});
8、地球移动事件
});
});
9、取消Cesium版权信息
$(".cesium-widget-credits").remove();
10、⾃定义BaLayerPicker
var esriMap = new Cesium.ArcGisMapServerImageryProvider({
url:'/ArcGIS/rest/rvices/World_Imagery/MapServer',
enablePickFeatures:fal
日照灯塔风景区
});
//设置ProviderViewModel:
var esriMapModel = new Cesium.ProviderViewModel({
name:'esri Maps',
iconUrl:Cesium.buildModuleUrl('./Widgets/Images/ImageryProviders/esriWorldImagery.png'),
tooltip:'ArcGIS 地图服务',
creationFunction:function () {
return esriMap;
}
});
/
/只有⼀个
var providerViewModels = [];
providerViewModels.push(esriMapModel);
viewer.baLayerPicker.viewModel.imageryProviderViewModels = providerViewModels;
11、设置时间
// 设置时钟和时间线
领旗viewer.clock.shouldAnimate = true; // 当viewer开启后,启动动画
viewer.clock.startTime = Cesium.JulianDate.fromIso8601("2017-07-11T16:00:00Z");
viewer.clock.stopTime = Cesium.JulianDate.fromIso8601("2017-07-11T16:20:00Z");
viewer.clock.currentTime = Cesium.JulianDate.fromIso8601("2017-07-11T16:00:00Z");
viewer.clock.currentTime = Cesium.JulianDate.fromIso8601("2017-07-11T16:00:00Z");
viewer.clock.multiplier = 2; // 设置加速倍率
viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK_MULTIPLIER; // tick computation mode(还没理解具体含义) viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP; // 循环播放
To(viewer.clock.startTime, viewer.clock.stopTime); // 设置时间的可见范围
12、拾取
收麦子/**
* 返回对应窗⼝位置最上⾯⼀个Entity 如果该位置没有对象那么返回undefined
* @param {Cartesian2} windowPosition 窗⼝坐标
* @returns {Entity} 返回值
*/
function pickEntity(viewer, windowPosition) {
var picked = viewer.scene.pick(windowPosition);
if (defined(picked)) {
舞蹈社团活动记录var id = Cesium.defaultValue(picked.id, picked.primitive.id);
if (id instanceof Cesium.Entity) {
return id;
}
}
return undefined;
};
/**
*返回对应窗⼝位置所有Entity的列表如果该位置没有对象那么返回undefined
* 返回值按可视化顺序从前到后存储在数组⾥
*
* @param {Cartesian2} windowPosition 窗⼝位置
* @returns {Entity[]}
*/
function drillPickEntities(viewer, windowPosition) {
var i;
var entity;
var picked;
var pickedPrimitives = viewer.scene.drillPick(windowPosition);
var length = pickedPrimitives.length;
var result = [];
var hash = {};
for (i = 0; i < length; i++) {
picked = pickedPrimitives[i];
entity = Cesium.defaultValue(picked.id, picked.primitive.id);
if (entity instanceof Cesium.Entity &&
!Cesium.defined(hash[entity.id])) {
result.push(entity);
hash[entity.id] = true;
}
}
return result;
};
该代码出⾃:/p/8ae3624347cb
13、检测深度
//为fal时,没有⾼程遮挡效果
viewer.scene.globe.depthTestAgainstTerrain = fal;
//为true时,有⾼程遮挡效果
viewer.scene.globe.depthTestAgainstTerrain = true;
14、加载georver的WMS服务
var provider = new Cesium.WebMapServiceImageryProvider({
url: 'localhost:8080/georver/cite/wms',
layers: 'cite:city',
parameters: {
rvice : 'WMS',
format: 'image/png',
transparent: true,
}
});
viewer.imageryLayers.addImageryProvider(provider);
15、⾃定义credit
var viewer = new Cesium.Viewer('cesiumContainer');
var credit = new Cesium.Credit('Title', '../images/facility.gif', 'siumjs'); viewer.ditDisplay.addDefaultCredit(credit)
16、拾取
Scene.pick : 返回窗⼝坐标对应的图元的第⼀个对象。
Scene.drillPick :返回窗⼝坐标对应的所有对象列表。
Globe.pick : 返回⼀条射线和地形的相交位置点。
17、禁⽌缩放
viewer.ableZoom = fal;
18、控制时钟暂停与继续
pauOrContinue (state) {
this.viewer.clock.shouldAnimate = state
}
19、绕点飞⾏
var viewer = new Cesium.Viewer('cesiumContainer');
蝙蝠英文var options = {
lng: 117.1423291616,
lat: 39.0645831633,
height: 15.8,
heading: 0.0,
pitch: 0.0,
roll: 0.0
};
var position = Cesium.Cartesian3.fromDegrees(options.lng, options.lat, options.height);
// 相机看点的⾓度,如果⼤于0那么则是从地底往上看,所以要为负值,这⾥取-30度
var pitch = Radians(-30);
/
/ 给定飞⾏⼀周所需时间,⽐如10s, 那么每秒转动度数
var angle = 360 / 30;
// 给定相机距离点多少距离飞⾏,这⾥取值为5000m
var distance = 5000;
var startTime = Cesium.JulianDate.fromDate(new Date());
// var stopTime = Cesium.JulianDate.addSeconds(startTime, 10, new Cesium.JulianDate());
viewer.clock.startTime = startTime.clone(); // 开始时间
// viewer.clock.stopTime = stopTime.clone(); // 结速时间
viewer.clock.currentTime = startTime.clone(); // 当前时间
分享
viewer.clock.clockRange = Cesium.ClockRange.CLAMPED; // ⾏为⽅式
viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK; // 时钟设置为当前系统时间; 忽略所有其他设置。 // 相机的当前heading
var initialHeading = viewer.camera.heading;
var Exection = function TimeExecution() {
// 当前已经过去的时间,单位s
var delTime = dsDifference(viewer.clock.currentTime, viewer.clock.startTime); var heading = Radians(delTime * angle) + initialHeading;
viewer.scene.camera.tView({
destination :position, // 点的坐标
orientation:{
heading: heading,
pitch : pitch,
}
});
viewer.veBackward(distance);
if (pare(viewer.clock.currentTime, viewer.clock.stopTime) >= 0) {
veEventListener(Exection);
}
};
20、只让地球显⽰⼀块区域,其余裁剪
var coffeeBeltRectangle = Cesium.Rectangle.fromDegrees(-180.0, -23.43687, 180.0, 23.43687);
viewer.scene.globe.cartographicLimitRectangle = coffeeBeltRectangle;
21、关闭HDR
viewer.scene.highDynamicRange = fal;
22、防⽌进⼊地下
23、billboard显⽰不完整怎么解决?
24、gltf模型双⾯渲染
doubleSided改为true
25、开启debugShowFramesPerSecond
scene.debugShowFramesPerSecond = true;