Cesium 采集地形高度,采集模型高度 (异步方法,适合数据较多的时候) | 您所在的位置:网站首页 › 等高线高度范围 › Cesium 采集地形高度,采集模型高度 (异步方法,适合数据较多的时候) |
阅前须知: 1. 该文章适合采集大量点的高度(异步采集),采集效率一般,应避免频繁使用; 2. 如果采集单点高度(同步采集),请参考API:scene类下的 sampleHeight 和 clampToHeight,适合采集单点。 Scene - Cesium Documentation 正文开始 Demo主要功能: 1. 采集地形高度(地形:viewer.terrainProvider) 2. 采集模型高度(3DTile,model,entity等) (其中this.cartesianToCartographic方法:极坐标转为笛卡尔坐标,可参考cesium坐标转换:不同坐标系之间的相互转换_Gisleung的博客-CSDN博客) /** * 采集高度 * @param {*} cartesians:笛卡尔坐标组成的数组 * @param {*} type:'terrain' 获取地形高度,'model'获取模型高度 * @returns 采集结果:笛卡尔坐标组成的数组 */ getHeightByType(cartesians, type) { if (type === 'model') { return new Promise(async resolve => { try { let promise = viewer.scene.clampToHeightMostDetailed(cartesians) promise.then(updatedCartesians => resolve(updatedCartesians)) } catch (e) { resolve(false) } }) } else if (type = 'terrain') { // 首先将cartesians转为positions let positions = [] cartesians.forEach(cartesian => { positions.push(this.cartesianToCartographic(cartesian)) }) let terrain = viewer.terrainProvider return new Promise(async resolve => { try { // 当前场景中没有使用地形 if (!terrain) resolve(false) const promise = Cesium.sampleTerrainMostDetailed(terrain, positions); promise.then(updatedPositions => { let resultCartesians = [] updatedPositions.forEach(position => { if (position) { // 采集成功,转为笛卡尔坐标 resultCartesians.push(this.cartographicToCartesian(position)) } else { // postion为undefined时,说明该位置采集失败 // resultCartesians.push(position) } }) resolve(resultCartesians) }) } catch (e) { resolve(false) } }) } },简单使用: const cartesian1 = new Cesium.Cartesian3.fromDegrees(102.837, 24.276, 60000) const cartesian2 = new Cesium.Cartesian3.fromDegrees(101.837, 23.276, 60000) this.getHeightByType([cartesian1, cartesian2], 'model').then(results => { console.log('demo: 拾取结果:', results) }) |
CopyRight 2018-2019 实验室设备网 版权所有 |