赞
踩
前提: 模型本身有地理位置信息,模型本身就能显示在地球表面了(而不是在地表下的球心或其他奇奇怪怪的位置)
以下是将tileset的位置调整到北京(在WGS84坐标系下)的正确代码:
var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ url: 'path/to/your/tileset' })); tileset.readyPromise.then(function() { // 获取tileset的中心点坐标 var boundingSphere = tileset.boundingSphere; var center = boundingSphere.center; // 将中心点坐标转换为WGS84坐标系下的经纬度 var cartographic = Cesium.Cartographic.fromCartesian(center); var longitude = Cesium.Math.toDegrees(cartographic.longitude); var latitude = Cesium.Math.toDegrees(cartographic.latitude); // 将经纬度调整为北京的经纬度 var beijingLongitude = 116.4074; var beijingLatitude = 39.9042; // 计算tileset的平移量,并将其应用到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的中心点坐标,并将其转换为WGS84坐标系下的经纬度。然后,我们将经纬度调整为北京的经纬度,并计算tileset的平移量。最后,我们将平移量应用到tileset的modelMatrix中,以将其位置调整到北京。
需要注意的是,以上代码假设tileset在WGS84坐标系下。如果tileset在其他坐标系下,则需要进行相应的坐标系转换。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。