绕点旋转、相机位置与视角控制。下面是该示例的核心 script 片段,供参考学习;完整可运行代码请进入在线 Demo 或查看仓库源码。
import * as Cesium from 'cesium'
import { initCesium } from '@/utils/cesiumPluginsExtends/index'
import { defaultStatic } from '../defaultStaticConf'
export default {
data () {
return {
posHeading: 0,
posPitch: 0,
posRoll: 0,
posAlt: 0,
posLat: 0,
posLon: 0,
cartesinaX: 0,
cartesinaY: 0,
cartesinaZ: 0,
cartesinaH: 0,
cartesinaP: 0,
cartesinaR: 0
}
},
mounted () {
this.initMap()
},
methods: {
async initMap () {
const tempData = [
{
type: 'UrlTemplateImageryProvider',
option: {
url: 'https://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}'
}
},
{
type: 'UrlTemplateImageryProvider',
option: {
url: 'https://webst03.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&style=7',
}
}
]
const { viewer,
base
} = new initCesium(
{
cesiumGlobal: Cesium,
containerId: 'cesiumContainer',
viewerConfig: {
infoBox: false,
shouldAnimate: true,
},
extraConfig: {
depthTest: true
},
MapImageryList: tempData,
defaultStatic
})
this.c_viewer = viewer;
this.base = base;
let tiles = await Cesium.Cesium3DTileset.fromUrl('static/data/3DTiles/building/tileset.json');
let tileset = this.c_viewer.scene.primitives.add(tiles)
tileset.style = new Cesium.Cesium3DTileStyle({
color: {
conditions: [
['${height} >= 300', 'rgba(0, 149, 251, 0.3)'],
['${height} >= 200', 'rgb(0, 149, 251, 0.3)'],
['${height} >= 100', 'rgb(0, 149, 251, 0.3)'],
['${height} >= 50', 'rgb(0, 149, 251, 0.3)'],
['${height} >= 25', 'rgb(0, 149, 251, 0.3)'],
['${height} >= 10', 'rgb(0, 149, 251, 0.3)'],
['${height} >= 5', 'rgb(0, 149, 251, 0.3)'],
['true', 'rgb(0, 149, 251, 0.3)'],
],
},
})
viewer.flyTo(tileset)
this.initCameraPos();
this.cameraModify();
},
initCameraPos () {
let position = this.base.getCameraPosition();
if (position) {
const { lon,
lat,
height,
heading,
pitch,
roll,
position: { x, y, z },
cameraHeading,
cameraPitch,
cameraRoll,
} = position;
this.posAlt = height;
this.posHeading = heading;
this.posPitch = pitch;
this.posRoll = roll;
this.posLat = lat;
this.posLon = lon;
this.cartesinaX = x;
this.cartesinaY = y;
this.cartesinaZ = z;
this.cartesinaH = cameraHeading;
this.cartesinaP = cameraPitch;
this.cartesinaR = cameraRoll;
} else {
console.log('can not get postion.')
}
},
cameraModify () {
this.c_viewer.scene.camera.moveEnd.addEventListener((move) => {
let position = this.base.getCameraPosition()
if (position) {
const { lon,
lat,
height,
heading,
pitch,
roll,
position: { x, y, z },
cameraHeading,
cameraPitch,
cameraRoll,
} = position;
this.posAlt = height;
this.posHeading = heading;
this.posPitch = pitch;
this.posRoll = roll;
this.posLat = lat;
this.posLon = lon;
this.cartesinaX = x;
this.cartesinaY = y;
this.cartesinaZ = z;
this.cartesinaH = cameraHeading;
this.cartesinaP = cameraPitch;
this.cartesinaR = cameraRoll;
} else {
console.log('can not get postion.')
}
});
}
},
beforeUnmount () {
this.c_viewer = null;
this.base = null;
}
}
安装:npm install cesium_dev_kit cesium