实现效果如下:
功能菜单如下:
加载倾斜影像核心代码:
var palaceTileset = new Cesium.Cesium3DTileset({
url: 'http://127.0.0.1:9002/tileset.json',
//控制切片视角显示的数量,可调整性能
maximumScreenSpaceError: 0.1,
maximumNumberOfLoadedTiles: 10000,
})
//添加到场景
viewer.scene.primitives.add(palaceTileset);
//控制模型的位置
palaceTileset.readyPromise.then(function (palaceTileset) {
viewer.scene.primitives.add(palaceTileset);
var terrainProvider = new Cesium.EllipsoidTerrainProvider();
viewer.terrainProvider = terrainProvider;
var heightOffset = -370; //改变3Dtiles的高度
var boundingSphere = palaceTileset.boundingSphere;
var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);
var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
palaceTileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
viewer.zoomTo(palaceTileset, new Cesium.HeadingPitchRange(0.5, -0.2, palaceTileset.boundingSphere.radius *
1.0));
});
无人机特定方向飞行(按钮实现):
function jxuTime() {
// 创建 SampledPositionProperty 对象
var positionProperty = new Cesium.SampledPositionProperty();
// 添加一系列位置和时间样本
positionProperty.addSample(Cesium.JulianDate.now(), Cesium.Cartesian3.fromDegrees(108.927007, 34.256505, 50));
positionProperty.addSample(Cesium.JulianDate.addSeconds(Cesium.JulianDate.now(), 5, new Cesium.JulianDate()), Cesium.Cartesian3.fromDegrees(108.929620, 34.252350, 50));
// 创建实体并设置模型
var entity = viewer.entities.add({
name: 'plane',
position: positionProperty,
model: {
uri: ".//Apps//SampleData//image2d//air.glb",
scale: 2,
minimumPixelSize: 128,
maximumScale: 2000,
runAnimations: true,
clampAnimations: true,
show: true
}
});
}
电子围栏:
//绘制电子围栏
function GetRoute4() {
function PolylineTrailLinkMaterialProperty(color, duration) {
this._definitionChanged = new Cesium.Event();
this._color = undefined;
this._colorSubscription = undefined;
this.color = color;
this.duration = duration;
this._time = (new Date()).getTime();
}
Object.defineProperties(PolylineTrailLinkMaterialProperty.prototype, {
isConstant: {
get: function () {
return false;
}
},
definitionChanged: {
get: function () {
return this._definitionChanged;
}
},
color: Cesium.createPropertyDescriptor('color')
});
PolylineTrailLinkMaterialProperty.prototype.getType = function (time) {
return 'PolylineTrailLink';
}
PolylineTrailLinkMaterialProperty.prototype.getValue = function (time, result) {
if (!Cesium.defined(result)) {
result = {};
}
result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
result.image = Cesium.Material.PolylineTrailLinkImage;
result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
return result;
}
PolylineTrailLinkMaterialProperty.prototype.equals = function (other) {
return this === other || (other instanceof PolylineTrailLinkMaterialProperty && Property.equals(this._color, other._color))
};
Cesium.PolylineTrailLinkMaterialProperty = PolylineTrailLinkMaterialProperty;
Cesium.Material.PolylineTrailLinkType = 'PolylineTrailLink';
Cesium.Material.PolylineTrailLinkImage = "../Cesium-1.75/img/colors1.png";//图片
Cesium.Material.PolylineTrailLinkSource = "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
{\n\
czm_material material = czm_getDefaultMaterial(materialInput);\n\
vec2 st = materialInput.st;\n\
vec4 colorImage = texture2D(image, vec2(fract(st.s - time), st.t));\n\
material.alpha = colorImage.a * color.a;\n\
material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
return material;\n\
}"/*"czm_material czm_getMaterial(czm_materialInput materialInput)\n\
{\n\
czm_material material = czm_getDefaultMaterial(materialInput);\n\
vec2 st = materialInput.st;\n\
vec4 colorImage = texture2D(image, vec2(fract(st.t - time), st.t));\n\
material.alpha = colorImage.a * color.a;\n\
material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
return material;\n\
}" //从下向上*/
// 着色器从上到下
/* "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
{\n\
czm_material material = czm_getDefaultMaterial(materialInput);\n\
vec2 st = materialInput.st;\n\
vec4 colorImage = texture2D(image, vec2(fract(-(st.t + time)), st.t));\n\
material.alpha = colorImage.a * color.a;\n\
material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
return material;\n\
}"
//顺时针
"czm_material czm_getMaterial(czm_materialInput materialInput)\n\
{\n\
czm_material material = czm_getDefaultMaterial(materialInput);\n\
vec2 st = materialInput.st;\n\
vec4 colorImage = texture2D(image, vec2(fract(-(st.s + time)), st.t));\n\
material.alpha = colorImage.a * color.a;\n\
material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
return material;\n\
}";
//逆时针
"czm_material czm_getMaterial(czm_materialInput materialInput)\n\
{\n\
czm_material material = czm_getDefaultMaterial(materialInput);\n\
vec2 st = materialInput.st;\n\
vec4 colorImage = texture2D(image, vec2(fract(st.s - time), st.t));\n\
material.alpha = colorImage.a * color.a;\n\
material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
return material;\n\
}"
*/
Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineTrailLinkType, {
fabric: {
type: Cesium.Material.PolylineTrailLinkType,
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 0.9),
image: Cesium.Material.PolylineTrailLinkImage,
time: 2
},
source: Cesium.Material.PolylineTrailLinkSource
},
translucent: function (material) {
return true;
}
})
three = viewer.entities.add({
name: 'yscNoNeedEntity',
wall: {
positions: Cesium.Cartesian3.fromDegreesArrayHeights([
108.92536, 34.25199, 130.0,//左下
108.92990, 34.25200, 130.0,//右下
108.92973, 34.25477, 130.0,//右上
108.92510, 34.25476, 130.0,//左上
108.92536, 34.25199, 130.0,//左下
]),
material: new Cesium.PolylineTrailLinkMaterialProperty(Cesium.Color.BLUE, 3000),
}
})
viewer.flyTo(three)
}
下次再续写吧,忙了!