special-effects.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <script setup>
  2. import {
  3. inject
  4. } from "vue";
  5. const getMapInstance = inject("getMapInstance");
  6. jt3d = getMapInstance();
  7. </script>
  8. <template>
  9. <div class="jt-weather-effects">
  10. <el-collapse v-model="activeName" accordion>
  11. <el-collapse-item name="特效效果">
  12. <template #title>
  13. <span class='iconfont icon-tianqizitiku43' />天气特效
  14. </template>
  15. <el-row :gutter="20">
  16. <el-col :span="8" v-for="(item,index) in weather" @click="handleWeatherEffects(item.type,index)">
  17. <el-avatar shape="circle" style="width:70rem;height: 70rem;" :class="currentIndex===index?'selectStyle':'defaultStyle'">
  18. <i :class="[item.icon,currentIndex===index?'selectFontStyle':'']" />
  19. </el-avatar>
  20. <div style="margin-top: 5rem; font-size: 14rem;" :class="currentIndex===index?'selectFontStyle':''">{{item.label}}</div>
  21. </el-col>
  22. </el-row>
  23. </el-collapse-item>
  24. <el-collapse-item name="天空样式">
  25. <template #title>
  26. <span class='iconfont icon-tianqizitiku43' />天空样式
  27. </template>
  28. <el-row :gutter="20">
  29. <el-col :span="8" v-for="(item,index) in skybox" @click="handleSkybox(item.type,index)">
  30. <!-- <el-avatar :src="item.url" /> -->
  31. <el-avatar shape="circle" src="https://empty" style="width:70rem;height: 70rem;">
  32. <img :src="item.url" />
  33. </el-avatar>
  34. <div style="margin-top: 5rem; font-size: 14rem;" :class="currentIndex===index?'selectFontStyle':''">{{item.label}}</div>
  35. </el-col>
  36. </el-row>
  37. </el-collapse-item>
  38. <!-- <el-collapse-item name="粒子效果">
  39. <template #title>
  40. <span class='iconfont icon-tianqizitiku43' />粒子效果
  41. </template>
  42. <div class="el-collapse-item__content">
  43. <el-button color="rgb(20 136 255)" @click="ParticleSystem('add')">加载粒子效果</el-button>
  44. <el-button color="rgb(255 100 100)" @click="ParticleSystem('remove')"><span style="color: #fff;">清除粒子效果</span></el-button>
  45. </div>
  46. </el-collapse-item>
  47. <el-collapse-item name="热力图">
  48. <template #title>
  49. <span class='iconfont icon-tianqizitiku43' />热力图
  50. </template>
  51. <div class="el-collapse-item__content">
  52. <el-button color="rgb(20 136 255)" @click="HeatMap('add')">添加热力图</el-button>
  53. <el-button color="rgb(255 100 100)" @click="HeatMap('remove')"><span style="color: #fff;">清除热力图</span></el-button>
  54. </div>
  55. </el-collapse-item> -->
  56. </el-collapse>
  57. </div>
  58. </template>
  59. <script>
  60. let jt3d = undefined;
  61. export default {
  62. data() {
  63. return {
  64. activeName: "特效效果",
  65. currentIndex: -1,
  66. weather: [{
  67. label: '雨天',
  68. type: 'rain',
  69. number: 0,
  70. icon: 'iconfont icon-yu'
  71. },
  72. {
  73. label: '雪天',
  74. type: 'snow',
  75. number: 1,
  76. icon: 'iconfont icon-huaban'
  77. },
  78. {
  79. label: '雾天',
  80. type: 'fog',
  81. number: 2,
  82. icon: 'iconfont icon-tianqizitiku43'
  83. },
  84. {
  85. label: '关闭天气',
  86. type: 'remove',
  87. number: 3,
  88. icon: 'iconfont icon-cloudofftianqiguanbi'
  89. },
  90. ],
  91. skybox: [{
  92. label: '晚霞',
  93. type: '晚霞',
  94. number: 0,
  95. url: 'jt3dSDK/imgs/skybox/01/py.png'
  96. },
  97. {
  98. label: '蓝天',
  99. type: '蓝天',
  100. number: 1,
  101. url: 'jt3dSDK/imgs/skybox/03/py.jpg'
  102. },
  103. {
  104. label: '阴天',
  105. type: '阴天',
  106. number: 2,
  107. url: 'jt3dSDK/imgs/skybox/02/py.jpg'
  108. },
  109. {
  110. label: '蓝色星空',
  111. type: '蓝色星空',
  112. number: 3,
  113. url: 'jt3dSDK/imgs/skybox/05/pz.jpg'
  114. },
  115. {
  116. label: '紫色星空',
  117. type: '紫色星空',
  118. number: 4,
  119. url: 'jt3dSDK/imgs/skybox/04/ny.jpg'
  120. },
  121. ],
  122. }
  123. },
  124. props: {},
  125. watch: {},
  126. /* 方法 */
  127. methods: {
  128. /**
  129. * 天空盒子事件
  130. * @param {Object} type 天空盒子类型
  131. * @param {Object} index 第几个被选中
  132. */
  133. handleSkybox(type, index) {
  134. this.currentIndex = index;
  135. jt3d.SceneEffects.SkyBox.setGroundSkyBox({
  136. type: type
  137. });
  138. },
  139. /**
  140. * 天气特效事件
  141. * @param {Object} type 天气类型
  142. * @param {Object} index 第几个被选中
  143. */
  144. handleWeatherEffects(type, index) {
  145. this.currentIndex = index;
  146. switch (type) {
  147. case "rain": //雨天
  148. jt3d.SceneEffects.Weather.removeEffect();
  149. jt3d.SceneEffects.Weather.addRainEffect({
  150. tiltAngle: 0.3,
  151. rainSize: 0.5,
  152. rainSpeed: 70
  153. });
  154. break;
  155. case "snow": //雪天
  156. jt3d.SceneEffects.Weather.removeEffect();
  157. jt3d.SceneEffects.Weather.addSnowEffect();
  158. break;
  159. case "fog": //雾天
  160. jt3d.SceneEffects.Weather.removeEffect();
  161. jt3d.SceneEffects.Weather.addFogEffect();
  162. break;
  163. case "remove": //移除天气特效
  164. this.currentIndex = -1;
  165. jt3d.SceneEffects.Weather.removeEffect()
  166. break;
  167. }
  168. },
  169. /**
  170. * 粒子效果
  171. */
  172. ParticleSystem(type) {
  173. let options = {};
  174. // 初始化参数默认值
  175. options.duration = Cesium.defaultValue(options.duration, 2);
  176. options.heading = Cesium.defaultValue(options.heading, 0.5); //指向,默认值0.0(北)
  177. options.pitch = Cesium.defaultValue(options.pitch, -40); //俯仰角, 垂直向下。默认值-90(向下看)。
  178. options.range = Cesium.defaultValue(options.range, 150); //距目标点距离
  179. const position = {
  180. x: 121.554042,
  181. y: 37.395186,
  182. z: 25.60
  183. };
  184. // 定位到点
  185. let flyToPoint = jt3d.LocateUtil.flyToPoint({
  186. longitude: position.x,
  187. latitude: position.y,
  188. height: position.z,
  189. duration: options.duration,
  190. heading: options.heading,
  191. pitch: options.pitch,
  192. range: options.range,
  193. });
  194. flyToPoint.then(function() {
  195. // alert(1111)
  196. });
  197. if (type === "add") {
  198. const positionF = {
  199. x: 121.554042,
  200. y: 37.395186,
  201. z: 25.60
  202. };
  203. this.fireArr = [];
  204. this.waterArr = [];
  205. let fireEntity = jt3d.SceneEffects.ParticleSystem.createParticleFire([positionF.x, positionF.y, positionF.z])
  206. this.fireArr.push(fireEntity)
  207. const positionW = {
  208. x: 121.553975,
  209. y: 37.395075,
  210. z: 18.10
  211. };
  212. let waterEntity = jt3d.SceneEffects.ParticleSystem.createParticleWater([positionW.x, positionW.y, positionW.z])
  213. this.waterArr.push(waterEntity)
  214. }
  215. if (type === "remove") {
  216. for (var i = 0; i < this.fireArr.length; i++) {
  217. this.fireArr[i].remove()
  218. }
  219. for (var i = 0; i < this.waterArr.length; i++) {
  220. this.waterArr[i].remove()
  221. }
  222. }
  223. },
  224. /**
  225. * 热力图
  226. */
  227. HeatMap(type) {
  228. if (type === "add") {
  229. let viewer = this.viewer = window["viewer"];
  230. // 矩形坐标
  231. var bounds = {
  232. west: 121.563298,
  233. south: 37.284514,
  234. east: 121.565298,
  235. north: 37.286514,
  236. };
  237. // 初始化CesiumHeatmap
  238. var heatMap = this.heatMap = CesiumHeatmap.create(
  239. viewer, // 视图层
  240. bounds, // 矩形坐标
  241. // heatmap相应参数
  242. {
  243. backgroundColor: "rgba(0, 0, 0, 0)",
  244. radius: 50,
  245. maxOpacity: .5,
  246. minOpacity: 0,
  247. blur: .75
  248. }
  249. );
  250. //加载数据,生成热力图
  251. // 添加数据 最小值,最大值,数据集
  252. heatMap.setWGS84Data(0, 100, getData(300));
  253. viewer.zoomTo(viewer.entities);
  254. if (this._layer) {
  255. //移除热力图
  256. this.viewer.entities.remove(this.heatMap._layer);
  257. } else {
  258. this._layer = this.heatMap._layer;
  259. }
  260. // 数据格式:动态数据 [{x: -97.6433525165054, y: 45.61443064377248, value: 11.409122369106317}]
  261. function getData(length) {
  262. var data = [];
  263. for (var i = 0; i < length; i++) {
  264. var x = 121.563298 + Math.random() * (121.565298 - 121.563298);
  265. var y = 37.284514 + Math.random() * (37.286514 - 37.284514);
  266. var value = Math.random() * 100;
  267. data.push({
  268. x: x,
  269. y: y,
  270. value: value
  271. });
  272. }
  273. return data;
  274. }
  275. }
  276. if (type === "remove") {
  277. //移除热力图
  278. this.viewer.entities.remove(this.heatMap._layer);
  279. }
  280. }
  281. },
  282. mounted() {
  283. }
  284. };
  285. </script>
  286. <style lang="scss" scoped>
  287. .el-avatar{
  288. width: 70rem !important;
  289. height: 70rem !important;
  290. font-size: 14px !important;
  291. cursor: pointer;
  292. }
  293. ::v-deep .el-collapse-item__content {
  294. padding: 10rem;
  295. // padding-bottom: 0rem;
  296. overflow-y: hidden;
  297. }
  298. ::v-deep .el-collapse-item__header {
  299. background: url(@/assets/images/bg_collapse_title.png) no-repeat;
  300. background-size: 350rem 40rem;
  301. // background-color: rgb(22 90 190);
  302. // background-color: rgb(5 45 100 /60%);
  303. background-color: rgb(30 130 255);
  304. border-bottom: 0;
  305. }
  306. .el-col {
  307. padding: 10rem;
  308. // color: rgba(90, 172, 255, 1.0);
  309. color: #fff;
  310. }
  311. .jt-weather-effects {
  312. position: relative;
  313. .iconfont {
  314. padding: 0 10rem;
  315. }
  316. .el-collapse {
  317. --el-collapse-border-color: rgb(0 44 126 / 0%);
  318. --el-collapse-header-text-color: #ffffff;
  319. --el-collapse-header-font-size: 13rem;
  320. --el-collapse-content-bg-color: rgb(0 44 126 / 0%);
  321. --el-collapse-content-font-size: 13rem;
  322. --el-collapse-content-text-color: rgb(216 240 255);
  323. --el-collapse-header-height: 40rem;
  324. --el-collapse-header-bg-color: rgb(30 130 255);
  325. --el-fill-color-blank: rgb(0 44 126 / 68%);
  326. --el-text-color-regular: rgb(216 240 255);
  327. --el-border-color: rgb(35 135 255);
  328. .el-collapse-item__content {
  329. padding: 10rem;
  330. // padding-bottom: 0rem;
  331. }
  332. }
  333. i {
  334. display: inline-block;
  335. width: 100%;
  336. height: 36rem;
  337. line-height: 36rem;
  338. text-align: center;
  339. border-radius: 5rem;
  340. font-size: 40rem;
  341. // color: rgba(90, 172, 255, 1.0);
  342. color: #fff;
  343. transition: all .3s;
  344. -webkit-transition: all .3s
  345. }
  346. .selectStyle {
  347. // background: rgba(135, 182, 254, 0.5);
  348. background: rgb(0 44 126);
  349. }
  350. .defaultStyle {
  351. background: #ffffff00;
  352. }
  353. .selectFontStyle {
  354. // color: #fff;
  355. color: #55ffff;
  356. }
  357. }
  358. </style>