前提: 模型本身有地理位置信息,模型本身就能顯示在地球表面了(而不是在地表下的球心或其他奇奇怪怪的位置)
以下是將tileset的位置調(diào)整到北京(在WGS84坐標(biāo)系下)的正確代碼:
var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url: 'path/to/your/tileset'
}));
tileset.readyPromise.then(function() {
// 獲取tileset的中心點(diǎn)坐標(biāo)
var boundingSphere = tileset.boundingSphere;
var center = boundingSphere.center;
// 將中心點(diǎn)坐標(biāo)轉(zhuǎn)換為WGS84坐標(biāo)系下的經(jīng)緯度
var cartographic = Cesium.Cartographic.fromCartesian(center);
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
// 將經(jīng)緯度調(diào)整為北京的經(jīng)緯度
var beijingLongitude = 116.4074;
var beijingLatitude = 39.9042;
// 計(jì)算tileset的平移量,并將其應(yīng)用到modelMatrix中
var translation = Cesium.Cartesian3.fromDegrees(beijingLongitude, beijingLatitude);
var centerNew = Cesium.Cartesian3.fromDegrees(longitude, latitude);
var translationVector = Cesium.Cartesian3.subtract(translation, centerNew, new Cesium.Cartesian3());
tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translationVector);
});
在以上代碼中,我們首先獲取tileset的中心點(diǎn)坐標(biāo),并將其轉(zhuǎn)換為WGS84坐標(biāo)系下的經(jīng)緯度。然后,我們將經(jīng)緯度調(diào)整為北京的經(jīng)緯度,并計(jì)算tileset的平移量。最后,我們將平移量應(yīng)用到tileset的modelMatrix中,以將其位置調(diào)整到北京。文章來源:http://www.zghlxwxcb.cn/news/detail-517882.html
需要注意的是,以上代碼假設(shè)tileset在WGS84坐標(biāo)系下。如果tileset在其他坐標(biāo)系下,則需要進(jìn)行相應(yīng)的坐標(biāo)系轉(zhuǎn)換。文章來源地址http://www.zghlxwxcb.cn/news/detail-517882.html
到了這里,關(guān)于【Cesium】調(diào)整3DTile/tileset的位置到某個(gè)經(jīng)緯度/某個(gè)地點(diǎn)/城市的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!