CesiumScene.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div id="container" class="box">
  3. <div id="cesiumContainer"></div>
  4. </div>
  5. </template>
  6. <script>
  7. var Cesium = require("cesium/Cesium");
  8. var widgets = require("cesium/Widgets/widgets.css");
  9. import wtTree from "../../public/static/fj";
  10. export default {
  11. name: "cesiumPage",
  12. data() {
  13. return {
  14. publicPath: process.env.BASE_URL,
  15. url: "http://localhost:8888/tiles",
  16. // url: "http://localhost:8889",
  17. initPosition: [106.0231304, 37.73323706, 0],
  18. viewer: null,
  19. };
  20. },
  21. mounted() {
  22. this.viewer = new Cesium.Viewer("cesiumContainer", {
  23. animation: false, //是否显示动画控件
  24. shouldAnimate: true,
  25. homeButton: false, //是否显示Home按钮
  26. fullscreenButton: false, //是否显示全屏按钮
  27. baseLayerPicker: false, //是否显示图层选择控件
  28. geocoder: false, //是否显示地名查找控件http://localhost:8080/#/cesiumScene
  29. timeline: false, //是否显示时间线控件
  30. sceneModePicker: false, //是否显示投影方式控件
  31. navigationHelpButton: false, //是否显示帮助信息控件
  32. infoBox: false, //是否显示点击要素之后显示的信息
  33. requestRenderMode: true, //启用请求渲染模式
  34. scene3DOnly: false, //每个几何实例将只能以3D渲染以节省GPU内存
  35. sceneMode: 3, //初始场景模式 1 2D模式 2 2D循环模式 3 3D模式 Cesium.SceneMode
  36. fullscreenElement: document.body, //全屏时渲染的HTML元素 暂时没发现用处
  37. imageryProvider: new Cesium.TileMapServiceImageryProvider({
  38. url: this.url,
  39. fileExtension: "jpg",
  40. maximumLevel: 13,
  41. }),
  42. baseLayerPicker: false,
  43. });
  44. // 雨雪天气添加
  45. var scene = this.viewer.scene;
  46. // scene.postProcessStages.add(Cesium.PostProcessStageLibrary.createSnowStage())
  47. // scene.postProcessStages.add(Cesium.PostProcessStageLibrary.createRainStage())
  48. scene.skyAtmosphere.hueShift = -0.8;
  49. scene.skyAtmosphere.saturationShift = -0.7;
  50. scene.skyAtmosphere.brightnessShift = -0.33;
  51. scene.fog.density = 0.001;
  52. scene.fog.minimumBrightness = 0.8;
  53. //jeojson 加载宁夏地图
  54. Cesium.Math.setRandomNumberSeed(0);
  55. var promise = this.viewer.dataSources.add(
  56. Cesium.GeoJsonDataSource.load(
  57. `${this.publicPath}static/mapgeoJsonnx.json`,
  58. {
  59. stroke: Cesium.Color.RAD,
  60. fill: Cesium.Color.TRANSPARENT,
  61. strokeWidth: 3,
  62. markerSymbol: "?",
  63. }
  64. )
  65. );
  66. this.viewer._cesiumWidget._creditContainer.style.display = "none";
  67. var position = Cesium.Cartesian3.fromDegrees(117.48, 30.67, 0);
  68. },
  69. methods: {
  70. addFengjiModel(position) {
  71. var hpRoll = new Cesium.HeadingPitchRoll(0.0, 0.0, 0.0);
  72. var origin = Cesium.Cartesian3.fromDegrees(106.0231304, 37.73323706, 0);
  73. var orientation = Cesium.Transforms.headingPitchRollQuaternion(
  74. position,
  75. hpRoll
  76. );
  77. var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
  78. origin,
  79. hpRoll
  80. );
  81. var model = this.viewer.scene.primitives.add(
  82. Cesium.Model.fromGltf({
  83. url: `${this.publicPath}static/WT01.glb`,
  84. modelMatrix: modelMatrix,
  85. minimumPixelSize: 150,
  86. // 模型最大刻度
  87. maximumSize: 150,
  88. //设置模型最大放大大小
  89. maximumScale: 200,
  90. scale: 0.05,
  91. runAnimations: true, //是否运行模型中的动画效果
  92. })
  93. );
  94. },
  95. },
  96. };
  97. </script>
  98. <!-- Add "scoped" attribute to limit CSS to this component only -->
  99. <style scoped>
  100. html,
  101. body,
  102. #cesiumContainer {
  103. width: 100%;
  104. height: 100%;
  105. margin: 0;
  106. padding: 0;
  107. overflow: hidden;
  108. }
  109. .box {
  110. height: 100%;
  111. }
  112. </style>