当前位置:   article > 正文

cesium vue大屏 全套代码查看_vue2+cesium+天地图

vue2+cesium+天地图

安装 cesium

npm install cesium


一,加载3d地图

1,加载 3DTiles 数据

  1. let tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
  2. url: '3d地址',
  3. skipLevelOfDetail: true,
  4. baseScreenSpaceError: 1024,
  5. skipScreenSpaceErrorFactor: 1,
  6. skipLevels: 0,
  7. immediatelyLoadDesiredLevelOfDetail: false,
  8. loadSiblings: false,
  9. cullWithChildrenBounds: true,
  10. maximumMemoryUsage: 1024 * 8,
  11. dynamicScreenSpaceError: true,
  12. dynamicScreenSpaceErrorDensity: 0.00278,
  13. dynamicScreenSpaceErrorFactor: 4.0,
  14. dynamicScreenSpaceErrorHeightFalloff: 0.25
  15. }));
  16. tileset.readyPromise.then(function (tileset) {
  17. //高度偏差,正数为向上偏,负数为向下偏,根据真实的模型位置不断进行调整
  18. //计算tileset的绑定范围
  19. var boundingSphere = tileset.boundingSphere;
  20. //计算中心点位置
  21. var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
  22. //console.log('cartographic - ' + itm.url, cartographic);
  23. //计算中心点位置坐标
  24. var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height);
  25. //偏移后的三维坐标
  26. var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, (cartographic.height * 1 + 高度));
  27. var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
  28. //tileset.modelMatrix转换
  29. tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
  30. });

如果3d文件特别多,超过几十G,可以设置 内存、最大屏幕空间误差等等。 加载过最大41G的3d文件也没出现奔溃。
2,加载其他的3d文件,如gltf

  1. var position = Cesium.Cartesian3.fromDegrees(
  2. that.gltfLng, that.gltfLat, that.gltfHgt
  3. );
  4. var heading = Cesium.Math.toRadians(that.gltfRotationZ);
  5. var pitch = 0;
  6. var roll = 0;
  7. var headingPositionRoll = new Cesium.HeadingPitchRoll(heading, pitch, roll);
  8. var orientation1 = Cesium.Transforms.headingPitchRollQuaternion(
  9. position,
  10. headingPositionRoll
  11. );
  12. viewer.entities.add({
  13. id: "whole",
  14. position: position,
  15. name: "whole",
  16. orientation: orientation1,
  17. model: {
  18. uri: "gltf",
  19. scale: 0.9,
  20. shadows: Cesium.ShadowMode.ENABLED,
  21. heightReference: Cesium.HeightReference.NONE,
  22. dequantizeInShader: false,
  23. },
  24. });

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号