windMap2D.vue 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. <template>
  2. <div id="loading" class="dataLoading" v-if="loading">
  3. <span class="loadText">数据加载中...</span>
  4. </div>
  5. <div class="mapBox">
  6. <div id="cesiumContainer" style="width: 100%; height: 100vh"></div>
  7. <div :class="!menuComTStyB ? 'menuComTSty' : 'menuComT'" v-if="0">
  8. <menuCom
  9. :showbasemap="false"
  10. :showwindspeed="false"
  11. :showcloud="false"
  12. :showrainfall="false"
  13. :showtemperature="false"
  14. :showcity="false"
  15. :showwind="false"
  16. :showexit="true"
  17. :showwindModel="true"
  18. @handleWindModel="showwindmodel"
  19. @handleInit="handleInitView"
  20. @handleExit="switchLayer"
  21. />
  22. </div>
  23. <el-drawer
  24. v-model="windDrawer"
  25. direction="rtl"
  26. class="windModelDrawer"
  27. :before-close="handleClose"
  28. >
  29. <template #header>
  30. <h3 style="font-weight: bold">{{ windDrawerHeader }}</h3>
  31. </template>
  32. <template #default>
  33. <div class="windDrawerCla">
  34. <div class="line" v-if="!showModelMsg">
  35. <div class="leftContent">
  36. <span>{{ windDrawerTitle }}</span>
  37. </div>
  38. </div>
  39. <div class="jcxx" v-if="showBasicMsg">
  40. <windHome :modelValItem="modelVal" />
  41. </div>
  42. <div class="spjk" v-if="showVideoMsg">
  43. <!-- <iframe
  44. src="/public/static/windVideo.mp4"
  45. frameborder="0"
  46. style="width: 100%; height: 100%"
  47. ></iframe> -->
  48. <video ref="videoPlayer" controls width="95%" muted autoplay>
  49. <source src="/static/windVideo.mp4" type="video/mp4" />
  50. </video>
  51. </div>
  52. <div class="gzck" v-if="showProblemMsg">
  53. <windPro />
  54. </div>
  55. <div class="third" v-if="showModelMsg">
  56. <ModelUnpack
  57. :modelUnpackType="modelUnpackType"
  58. :showModelMsg="showModelMsg"
  59. />
  60. </div>
  61. </div>
  62. </template>
  63. </el-drawer>
  64. <comModelDialog
  65. :showcomModelDia="showcomModelDia"
  66. :modelVal="modelVal"
  67. @showDia="showComDia"
  68. />
  69. <windView
  70. v-if="showWindDetail"
  71. @coverOnChange="coverOnChange"
  72. :currentHeight="currentHeight"
  73. @showDetail="menuComTSty"
  74. @backStations="backStations"
  75. />
  76. </div>
  77. </template>
  78. <script>
  79. import * as Cesium from "../../Cesium";
  80. import "../../Cesium/Widgets/widgets.css";
  81. import fjMYLonLatJson from "../fjLonLatJson/fj_MY.json"; //迈越风电场
  82. import fjWHZLonLatJson from "../fjLonLatJson/fj_WHZ.json"; //京能旺海庄
  83. import fjYPLLonLatJson from "../fjLonLatJson/fj_YPL.json"; //京能营盘梁
  84. import fjSMSLonLatJson from "../fjLonLatJson/fj_SMS.json"; //京能苏木山
  85. import allStationJson from "./allStationJson.json";
  86. import basicGeoJson from "../../assets/geoJson/basic.json";
  87. import comModelDialog from "@/components/comModelDialog.vue";
  88. import windView from "./windView.vue";
  89. import menuCom from "../menuCom.vue";
  90. import cloudJson from "/public/static/exportData/cloud/layer.json";
  91. import rainJson from "/public/static/exportData/rain/layer.json";
  92. import tempJson from "/public/static/exportData/tmp/layer.json";
  93. // import bw from "@/assets/windimgs/fanSvg/bw.svg"
  94. //风场展示图标
  95. import fc from "@/assets/windimgs/fanSvg/fc.png";
  96. //火电展示图标
  97. import hd from "@/assets/windimgs/fanSvg/hd.png";
  98. //光伏电站展示图标
  99. import gf from "@/assets/windimgs/fanSvg/gf.png";
  100. //故障
  101. import gz from "@/assets/windimgs/fanSvg/gz.svg";
  102. //待机
  103. import dj from "@/assets/windimgs/fanSvg/dj.svg";
  104. //检修
  105. import jx from "@/assets/windimgs/fanSvg/jx.svg";
  106. //限电
  107. import xd from "@/assets/windimgs/fanSvg/xd.svg";
  108. //离线
  109. import lx from "@/assets/windimgs/fanSvg/lx.svg";
  110. //受累
  111. import sl from "@/assets/windimgs/fanSvg/sl.svg";
  112. //动图使用柱子和扇叶
  113. import bwzhu from "@/assets/windimgs/fanSvg/bwzhu.svg";
  114. import bwshan from "@/assets/windimgs/fanSvg/bwshan.png";
  115. import windHome from "@/components/windHome/index.vue";
  116. import windPro from "@/components/windProDetail/windProblem.vue";
  117. import ModelUnpack from "@/components/modelUnpack.vue";
  118. import { WindLayer } from "cesium-wind";
  119. import windGridData from "./windGridData.json";
  120. import AdvancedBillboardGenerator from "@/tools/lightsign.js";
  121. export default {
  122. name: "windMap2D",
  123. components: {
  124. comModelDialog,
  125. windView,
  126. menuCom,
  127. windHome,
  128. windPro,
  129. ModelUnpack,
  130. },
  131. data() {
  132. return {
  133. loading: true,
  134. showAllWindFromStation: [],
  135. restLatLon: [
  136. {
  137. longitude: 114.48789,
  138. latitude: 35.32916,
  139. name: "MYFDC",
  140. },
  141. {
  142. longitude: 112.88355172,
  143. latitude: 40.46617836,
  144. name: "JNWHZ",
  145. },
  146. {
  147. longitude: 112.5270545,
  148. latitude: 40.35920334,
  149. name: "JNYPL",
  150. },
  151. {
  152. longitude: 112.69922452,
  153. latitude: 40.31857399,
  154. name: "JNSMS",
  155. },
  156. ],
  157. viewer: null,
  158. windLayer: null, // 风场图
  159. windLayerTimmer: null, // 风场图计时器
  160. cloudImagesLayer: [], // 卫星云图
  161. cloudLayer: null, // 卫星云图
  162. cloudintervalId: null,
  163. rainImagesLayer: [], // 降雨图
  164. rainLayer: null, // 降雨图
  165. rainintervalId: null, // 降雨图
  166. tempImagesLayer: [], //温度图
  167. temperatureLayer: null, //温度图
  168. tempintervalId: null, //温度图
  169. showcomModelDia: false,
  170. currentHeight: 0,
  171. modelVal: null,
  172. menuComTStyB: false,
  173. modelUnpackType: "fengji",
  174. windDrawer: false,
  175. windDrawerTitle: "",
  176. windDrawerHeader: "",
  177. showBasicMsg: false,
  178. showVideoMsg: false,
  179. showProblemMsg: false,
  180. showModelMsg: false,
  181. showWindDetail: true,
  182. allStationentitys: [],
  183. allWindEntitys: [],
  184. urlTiles: "/public/static/tiles/{z}/{x}/{y}.jpg",
  185. };
  186. },
  187. mounted() {
  188. this.initCesium();
  189. setTimeout(() => {
  190. this.loading = false;
  191. }, 1000);
  192. },
  193. methods: {
  194. async initCesium() {
  195. const box = document.getElementById("cesiumContainer");
  196. const viewer = new Cesium.Viewer(box, {
  197. geocoder: false, // 地址搜索控件
  198. homeButton: false, // 返回地图初始位置控件
  199. infoBox: false, // 地图默认的信息控件
  200. sceneModePicker: false, // 场景模式切换控件
  201. baseLayerPicker: false, // 底图切换控件
  202. navigationHelpButton: false, // 帮助控件
  203. animation: false, // 动画控制控件
  204. timeline: false, // 时间线控件
  205. fullscreenButton: false, // 全屏按钮控件
  206. // imageryProvider: true, // 是否显示 Cesium 默认地图的底图
  207. vrButton: false,
  208. selectionIndicator: false,
  209. shouldAnimate: true,
  210. });
  211. const imageryProvider = new Cesium.UrlTemplateImageryProvider({
  212. // minimumLevel: 11,
  213. maximumLevel: 18,
  214. // url: this.urlTiles,
  215. // url: "/static/ditu/{z}/{x}/{y}.png",
  216. url: "https://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
  217. credit: "影像地图",
  218. });
  219. imageryProvider.alpha = 0.55; // 透明度
  220. imageryProvider.brightness = 1; // 亮度
  221. imageryProvider.contrast = 1; // 对比度
  222. viewer.imageryLayers.addImageryProvider(imageryProvider);
  223. viewer._cesiumWidget._creditContainer.style.display = "none";
  224. // this.csceneElliposid(viewer)
  225. this.viewer = viewer;
  226. // 展示场站
  227. // this.showAllStation(viewer)
  228. // 展示风机
  229. this.showWindFromStation(viewer);
  230. this.initGeoJsonData();
  231. },
  232. // 初始化 geoJson 数据
  233. async initGeoJsonData() {
  234. // 创建GeoJSON数据源
  235. await new Cesium.GeoJsonDataSource.load(basicGeoJson, {
  236. stroke: Cesium.Color.GRAY, // 边界线颜色
  237. fill: Cesium.Color.BLACK.withAlpha(0), // 填充颜色
  238. strokeWidth: 1, // 边界线宽度
  239. markerSymbol: "?", // 点要素的符号
  240. clampToGround: true, // 贴地
  241. }).then((dataSource) => {
  242. // 添加到视图
  243. this.viewer.dataSources.add(dataSource);
  244. var entities = dataSource.entities.values;
  245. for (let i = 0; i < entities.length; i++) {
  246. let entity = entities[i];
  247. entity.polygon.hierarchy.getValue(Cesium.JulianDate.now()).positions;
  248. //单独设置线条样式
  249. var positions = entity.polygon.hierarchy._value.positions;
  250. entity.polyline = {
  251. positions: positions,
  252. width: 1,
  253. outline: false,
  254. };
  255. }
  256. // 添加中文标签图层
  257. const labelLayer = new Cesium.LabelCollection();
  258. this.viewer.scene.primitives.add(labelLayer);
  259. const cities = [];
  260. basicGeoJson?.features?.forEach((ele) => {
  261. if (Array.isArray(ele.properties.centroid)) {
  262. const name = ele.properties.name;
  263. const lon = ele.properties.centroid[0];
  264. const lat = ele.properties.centroid[1];
  265. cities.push({ name, lon, lat });
  266. }
  267. });
  268. cities.forEach((city, index) => {
  269. labelLayer.add({
  270. id: index,
  271. name: "cityLabel",
  272. position: Cesium.Cartesian3.fromDegrees(city.lon, city.lat, 10),
  273. text: city.name,
  274. font: 'bold 14px "Microsoft YaHei", sans-serif',
  275. fillColor: Cesium.Color.fromCssColorString("#000"),
  276. outlineColor: Cesium.Color.WHITE,
  277. outlineWidth: 2,
  278. style: Cesium.LabelStyle.FILL_AND_OUTLINE,
  279. pixelOffset: new Cesium.Cartesian2(0, 0), // 设置为0
  280. horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // 水平居中
  281. verticalOrigin: Cesium.VerticalOrigin.CENTER, // 垂直居中
  282. });
  283. });
  284. });
  285. },
  286. backStations() {
  287. this.showWindDetail = false;
  288. this.allWindEntitys.forEach(({ entity, handler }) => {
  289. this.viewer.entities.remove(entity); // 移除实体
  290. if (!handler.isDestroyed()) {
  291. handler.destroy(); // 销毁事件处理器(关键!)
  292. }
  293. });
  294. this.allWindEntitys = [];
  295. if (this.viewer && this.viewer.destroy) {
  296. this.viewer.destroy();
  297. this.viewer = null;
  298. }
  299. // this.initCesium();
  300. // this.showAllStation(this.viewer)
  301. },
  302. // 展示所有风场
  303. showAllStation(viewer) {
  304. allStationJson.station.forEach((e, index) => {
  305. if (e.energytype === "Wind") {
  306. this.showStationFn(viewer, e, index, fc);
  307. } else if (e.energytype === "Fire") {
  308. this.showStationFn(viewer, e, index, hd);
  309. } else {
  310. this.showStationFn(viewer, e, index, gf);
  311. }
  312. });
  313. this.resetAllStationViewport();
  314. },
  315. // 根据状态展示不同颜色风机贴图
  316. showStationFn(viewer, e, index, images) {
  317. const position = Cesium.Cartesian3.fromDegrees(e.longitude, e.latitude);
  318. const entity = viewer.entities.add({
  319. id: index,
  320. position, // 模型位置
  321. billboard: {
  322. image: images, // 也可以是 SVG 路径,如 'icon.svg'
  323. scale: 0.5,
  324. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  325. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  326. // 模型贴地
  327. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  328. },
  329. label: {
  330. text: e.plantname,
  331. font: "14px sans-serif",
  332. fillColor: Cesium.Color.fromBytes(255, 255, 255),
  333. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  334. },
  335. });
  336. let that = this;
  337. const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  338. handler.setInputAction(function (movement) {
  339. var position = movement.position;
  340. var pickedObject = viewer.scene.pick(position);
  341. if (pickedObject && pickedObject.id.id === index) {
  342. console.log("你点击了标签或模型!", entity);
  343. console.log("选中风场或新能源场", e.plantname);
  344. that.showWindDetail = true;
  345. that.allStationentitys.forEach(({ entity, handler }) => {
  346. viewer.entities.remove(entity); // 移除实体
  347. if (!handler.isDestroyed()) {
  348. handler.destroy(); // 销毁事件处理器(关键!)
  349. }
  350. });
  351. that.allStationentitys = [];
  352. that.showWindFromStation(viewer);
  353. }
  354. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  355. that.allStationentitys.push({ entity, handler });
  356. },
  357. // 展示所选风场的风机
  358. showWindFromStation(viewer) {
  359. let stationName = this.$route.query.nameEn;
  360. let fjLonLatJson = [];
  361. if (stationName === "MYFDC") {
  362. fjLonLatJson = fjMYLonLatJson;
  363. } else if (stationName === "JNWHZ") {
  364. fjLonLatJson = fjWHZLonLatJson;
  365. } else if (stationName === "JNYPL") {
  366. fjLonLatJson = fjYPLLonLatJson;
  367. } else if (stationName === "JNSMS") {
  368. fjLonLatJson = fjSMSLonLatJson;
  369. }
  370. fjLonLatJson.data.forEach((e, index) => {
  371. if (e.status) {
  372. if (e.status === 1) {
  373. this.showStatuswind(viewer, e, dj);
  374. } else if (e.status === 2) {
  375. this.showStatuswind(viewer, e, gz);
  376. } else if (e.status === 3) {
  377. this.showStatuswind(viewer, e, jx);
  378. } else if (e.status === 4) {
  379. this.showStatuswind(viewer, e, xd);
  380. } else if (e.status === 5) {
  381. this.showStatuswind(viewer, e, lx);
  382. } else if (e.status === 6) {
  383. this.showStatuswind(viewer, e, sl);
  384. } else {
  385. //并网风机
  386. this.showAnimatewind(viewer, e);
  387. }
  388. }
  389. });
  390. this.resetWindViewport();
  391. },
  392. // 根据状态展示不同颜色风机贴图
  393. showStatuswind(viewer, e, type, index) {
  394. this.addSvg(
  395. viewer,
  396. type,
  397. e.longitude,
  398. e.latitude,
  399. e,
  400. Math.random().toFixed(4) * 10000
  401. );
  402. },
  403. // 风机柱与扇叶分开展示转动效果贴图
  404. showAnimatewind(viewer, e, index) {
  405. this.addSvgs(
  406. viewer,
  407. bwshan,
  408. e.longitude,
  409. e.latitude,
  410. e,
  411. Math.random().toFixed(3) * 1000
  412. );
  413. this.addSvg(
  414. viewer,
  415. bwzhu,
  416. e.longitude,
  417. e.latitude,
  418. e,
  419. Math.random().toFixed(3) * 2000
  420. );
  421. },
  422. //添加svg或png贴图
  423. addSvg(viewer, uri, lon, lat, val, index) {
  424. let that = this;
  425. let ids = that.generateUniqueId(val.id);
  426. const position = Cesium.Cartesian3.fromDegrees(lon, lat);
  427. // 使用高级灯牌生成器
  428. const advancedGenerator = new AdvancedBillboardGenerator();
  429. let statusItems = [];
  430. const statusArray = [
  431. { label: "风速", value: "10m/s" },
  432. { label: "状态", value: "测试" },
  433. { label: "转速", value: "1000p" },
  434. { label: "功率", value: "50kW" },
  435. // { label: "其他参数A", value: "...." },
  436. // { label: "其他参数B", value: "...." },
  437. // { label: "其他参数C", value: "...." },
  438. // { label: "其他参数D", value: "...." },
  439. // { label: "其他参数E", value: "...." },
  440. // { label: "其他参数F", value: "...." },
  441. ];
  442. // for (let i = 0; i <= this.randomNum(1, 9); i++) {
  443. // statusItems.push(statusArray[i]);
  444. // }
  445. statusItems = statusArray;
  446. console.log("statusItems====>>>>", statusItems);
  447. // const billboardImage = advancedGenerator.generateAdvancedBillboard({
  448. // title: val.name,
  449. // statusItems,
  450. // borderGradient: ["#00e5ff", "#2979ff"],
  451. // });
  452. // const entityxy = viewer.entities.add({
  453. // name: val.name,
  454. // position,
  455. // billboard: {
  456. // image: billboardImage,
  457. // scale: 1,
  458. // verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // 原来已经是CENTER,现在改为BOTTOM
  459. // pixelOffset: new Cesium.Cartesian2(80, -50), // 原来是-20,现在改为30,向上移动
  460. // eyeOffset: new Cesium.Cartesian3(0, 0, 0), // 保持固定大小
  461. // // heightReference: Cesium.HeightReference.NONE,
  462. // },
  463. // });
  464. const btn = document.getElementById("windBtn");
  465. btn.addEventListener("click", function (event) {
  466. entityxy.show = !entityxy.show;
  467. });
  468. const entity = viewer.entities.add({
  469. id: ids,
  470. position, // 模型位置
  471. billboard: {
  472. image: uri, // 也可以是 SVG 路径,如 'icon.svg'
  473. scale: 0.5,
  474. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  475. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  476. // 模型贴地
  477. // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  478. },
  479. // label: {
  480. // // text: val.name ? val.name : val.plantname,
  481. // text: `${val.name}\n风速: 10m/s\n状态: 测试`,
  482. // font: '14px sans-serif',
  483. // fillColor: Cesium.Color.fromBytes(255, 255, 255),
  484. // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  485. // pixelOffset: val.name === 'F10号风机' ? new Cesium.Cartesian2(50, -20) : new Cesium.Cartesian2(0, 20)
  486. // }
  487. });
  488. // 创建事件处理器
  489. const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  490. handler.setInputAction(function (movement) {
  491. var position = movement.position;
  492. var pickedObject = viewer.scene.pick(position);
  493. if (pickedObject && pickedObject.id.id === ids) {
  494. console.log("你点击了标签或模型!", entity);
  495. console.log("标签或模型数据!", val);
  496. that.modelVal = val;
  497. // 找到实体,显示包含实体信息的弹框
  498. that.showRightClickPopup(position, val);
  499. return;
  500. }
  501. }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  502. this.allWindEntitys.push({ entity, handler });
  503. },
  504. randomNum(minNum, maxNum) {
  505. switch (arguments.length) {
  506. case 1:
  507. return parseInt(Math.random() * minNum + 1, 10);
  508. case 2:
  509. return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
  510. default:
  511. return 0;
  512. }
  513. },
  514. //添加svg或png贴图
  515. addSvgs(viewer, uri, lon, lat, val, index) {
  516. let that = this;
  517. let ids = that.generateUniqueId(val.id);
  518. const position = Cesium.Cartesian3.fromDegrees(lon, lat);
  519. const entity = viewer.entities.add({
  520. id: ids,
  521. position, // 模型位置
  522. billboard: {
  523. image: uri, // 也可以是 SVG 路径,如 'icon.svg'
  524. scale: 0.5,
  525. pixelOffset: new Cesium.Cartesian2(0, -15),
  526. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  527. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  528. // 模型贴地
  529. // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  530. // 核心:使用 CallbackProperty 实现旋转动画
  531. rotation: new Cesium.CallbackProperty(function (time) {
  532. // 每 3 秒转一圈(可调速度)
  533. const seconds = time.secondsOfDay;
  534. const angle = Cesium.Math.toRadians(((seconds % 3) * -360) / 3); // 每3秒一圈
  535. return angle;
  536. }, false),
  537. // 确保绕中心旋转
  538. rotationAlignment: Cesium.HeightReference.CENTER,
  539. alignedAxis: Cesium.Cartesian3.UNIT_Z,
  540. },
  541. });
  542. // 创建事件处理器
  543. const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  544. handler.setInputAction(function (movement) {
  545. var position = movement.position;
  546. var pickedObject = viewer.scene.pick(position);
  547. if (pickedObject && pickedObject.id.id === ids) {
  548. console.log("你点击了标签或模型!", entity);
  549. console.log("标签或模型数据!", val);
  550. that.modelVal = val;
  551. // 找到实体,显示包含实体信息的弹框
  552. that.showRightClickPopup(position, val);
  553. return;
  554. }
  555. }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  556. this.allWindEntitys.push({ entity, handler });
  557. },
  558. // 右键展示元素
  559. showRightClickPopup(screenPosition, val) {
  560. // 创建或获取弹框元素
  561. var popup = document.getElementById("rightClickPopup");
  562. if (!popup) {
  563. popup = document.createElement("div");
  564. popup.id = "rightClickPopup";
  565. popup.style.position = "absolute";
  566. // popup.style.backgroundColor = 'white';
  567. popup.style.border = "1px solid rgba(255, 255, 255, 0.2)";
  568. popup.style.borderRadius = "4px";
  569. popup.style.padding = "10px";
  570. popup.style.boxShadow = "0 2px 10px rgba(0,0,0,0.2)";
  571. popup.style.backdropFilter = `blur(10px)`;
  572. popup.style.zIndex = "1000";
  573. popup.style.pointerEvents = "auto"; // 确保弹框可交互
  574. // 添加一个最小宽度,避免内容过短
  575. popup.style.minWidth = "100px";
  576. // 可选:添加箭头指向点击点
  577. // 这需要更复杂的 CSS 或额外的 DOM 元素
  578. document.body.appendChild(popup);
  579. }
  580. // <span class="popup-menu-item" data-message-type="model" style="cursor:pointer">模型解构</span>
  581. let content = `
  582. <div style="display: flex;gap: 10px;flex-direction: column;text-align: center;color: #fff">
  583. <span class="popup-menu-item" data-message-type="basic" style="cursor:pointer">基本信息</span>
  584. <span class="popup-menu-item" data-message-type="video" style="cursor:pointer">视频监控</span>
  585. <span class="popup-menu-item" data-message-type="problem" style="cursor:pointer">故障详情</span>
  586. </div>
  587. `;
  588. // 设置弹框内容
  589. popup.innerHTML = content;
  590. // --- 关键修正:准确计算弹框位置 ---
  591. // 1. 获取 Cesium 画布 (Canvas) 相对于视口 (viewport) 的位置
  592. var canvas = this.viewer.scene.canvas;
  593. var canvasRect = canvas.getBoundingClientRect();
  594. // console.log('Canvas Rect:', canvasRect); // 调试用
  595. // 2. 计算弹框左上角在页面中的绝对 X 坐标
  596. // screenPosition.x 是相对于画布左上角的 X 偏移
  597. // canvasRect.left 是画布左上角相对于浏览器视口左上角的 X 偏移
  598. // window.pageXOffset 是页面水平滚动的距离
  599. var popupLeft = canvasRect.left + screenPosition.x + window.pageXOffset;
  600. // 3. 计算弹框左上角在页面中的绝对 Y 坐标
  601. var popupTop = canvasRect.top + screenPosition.y + window.pageYOffset;
  602. // --- 可选:添加偏移量,避免完全覆盖鼠标指针 ---
  603. // 例如,向下和向右偏移 10px
  604. var offsetX = 10;
  605. var offsetY = 10;
  606. popupLeft += offsetX;
  607. popupTop += offsetY;
  608. // --- 可选:边界检查,防止弹框超出屏幕 ---
  609. var popupWidth = popup.offsetWidth || 150; // 确保有宽度
  610. var popupHeight = popup.offsetHeight || 50; // 确保有高度
  611. var windowWidth = window.innerWidth;
  612. var windowHeight = window.innerHeight;
  613. // 如果弹框右边会超出窗口,则左移
  614. if (popupLeft + popupWidth > windowWidth) {
  615. popupLeft = windowWidth - popupWidth - 10; // 靠右留 10px 边距
  616. }
  617. // 如果弹框底边会超出窗口,则上移
  618. if (popupTop + popupHeight > windowHeight) {
  619. popupTop = windowHeight - popupHeight - 10; // 靠下留 10px 边距
  620. }
  621. // 如果左边超出 (不太可能,但安全起见)
  622. if (popupLeft < 0) popupLeft = 10;
  623. // 如果顶边超出
  624. if (popupTop < 0) popupTop = 10;
  625. // --- 设置最终位置 ---
  626. popup.style.left = popupLeft + "px";
  627. popup.style.top = popupTop + "px";
  628. // console.log('Popup Position:', { left: popupLeft, top: popupTop }); // 调试用
  629. // 显示弹框
  630. popup.style.display = "block";
  631. // --- 隐藏弹框的逻辑 (保持不变) ---
  632. function hidePopup(event) {
  633. // 检查点击是否发生在弹框内部,如果是,则不隐藏
  634. if (event && popup.contains(event.target)) {
  635. return;
  636. }
  637. popup.style.display = "none";
  638. document.removeEventListener("click", hidePopup);
  639. document.removeEventListener("keydown", keyDownHandler);
  640. }
  641. function keyDownHandler(event) {
  642. if (event.key === "Escape") {
  643. hidePopup();
  644. }
  645. }
  646. let that = this;
  647. that.showBasicMsg = false;
  648. that.showVideoMsg = false;
  649. that.showProblemMsg = false;
  650. that.showModelMsg = false;
  651. function popupMenuItemClick(event) {
  652. // 检查点击的是否是菜单项
  653. if (event.target.classList.contains("popup-menu-item")) {
  654. event.stopPropagation(); // 阻止冒泡,防止弹框立即关闭
  655. var messageType = event.target.dataset.messageType; // 获取 data-message-type
  656. console.log("点击了菜单项:", messageType);
  657. // 调用您的 showMessage 函数
  658. that.showMessage(messageType, val);
  659. hidePopup();
  660. // 可选:执行后关闭弹框
  661. // hideRightClickPopup();
  662. }
  663. }
  664. // 移除旧的监听器(避免重复绑定)
  665. document.removeEventListener("click", hidePopup);
  666. document.removeEventListener("click", popupMenuItemClick);
  667. document.removeEventListener("keydown", keyDownHandler);
  668. // 添加新的监听器
  669. document.addEventListener("click", hidePopup);
  670. document.addEventListener("click", popupMenuItemClick);
  671. document.addEventListener("keydown", keyDownHandler);
  672. },
  673. showMessage(type, val) {
  674. console.log("type===>>>", type);
  675. this.windDrawer = true;
  676. this.windDrawerHeader = val.name + "数据详情";
  677. if (type === "basic") {
  678. this.windDrawerTitle = "基础信息";
  679. this.showBasicMsg = true;
  680. } else if (type === "video") {
  681. this.windDrawerTitle = "视频监控";
  682. this.showVideoMsg = true;
  683. } else if (type === "problem") {
  684. this.windDrawerTitle = "故障查看";
  685. this.showProblemMsg = true;
  686. }
  687. // else {
  688. // this.windDrawerTitle = '模型解构'
  689. // this.showModelMsg = true
  690. // }
  691. },
  692. showwindmodel() {
  693. this.windDrawer = true;
  694. this.showBasicMsg = false;
  695. this.showVideoMsg = false;
  696. this.showProblemMsg = false;
  697. this.windDrawerHeader = "风机模型可视化解构说明";
  698. this.showModelMsg = true;
  699. },
  700. handleClose() {
  701. this.windDrawer = false;
  702. this.showBasicMsg = false;
  703. this.showVideoMsg = false;
  704. this.showProblemMsg = false;
  705. this.showModelMsg = false;
  706. },
  707. showComDia(val) {
  708. this.showcomModelDia = val;
  709. this.modelVal = null;
  710. },
  711. csceneElliposid(viewer) {
  712. let that = this;
  713. // 获取 scene 和 ellipsoid
  714. var scene = viewer.scene;
  715. var labels = viewer.scene.primitives.add(new Cesium.LabelCollection());
  716. // 创建 ScreenSpaceEventHandler
  717. var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
  718. // 监听左键点击事件
  719. handler.setInputAction(async (click) => {
  720. // 获取点击位置的笛卡尔坐标
  721. var position = click.position;
  722. if (!position) return;
  723. // 使用 globe.pick 获取包含地形高度的坐标
  724. var ray = viewer.camera.getPickRay(position);
  725. var cartesian = viewer.scene.globe.pick(ray, viewer.scene);
  726. if (cartesian) {
  727. // 转换为地理坐标
  728. var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
  729. var longitude = Cesium.Math.toDegrees(cartographic.longitude);
  730. var latitude = Cesium.Math.toDegrees(cartographic.latitude);
  731. var height = cartographic.height;
  732. // 格式化坐标
  733. var text = `经度: ${longitude.toFixed(6)}°\n纬度: ${latitude.toFixed(
  734. 6
  735. )}°`;
  736. // 创建一个标签
  737. var label = labels.add({
  738. position: cartesian,
  739. text: text,
  740. font: "14px monospace",
  741. fillColor: Cesium.Color.fromCssColorString("#1d70df"),
  742. // style: Cesium.LabelStyle.FILL_AND_OUTLINE,
  743. // outlineColor: Cesium.Color.BLACK,
  744. outlineWidth: 2,
  745. verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // 标签在点的上方
  746. pixelOffset: new Cesium.Cartesian2(0, -20), // 向上偏移一点
  747. disableDepthTest: true, // 让标签始终可见(即使在地球背面)
  748. scale: 0.8,
  749. });
  750. // 5秒后移除标签
  751. setTimeout(function () {
  752. labels.remove(label);
  753. }, 5000);
  754. console.log(
  755. `点击坐标: ${longitude.toFixed(6)}, ${latitude.toFixed(
  756. 6
  757. )}, ${height.toFixed(2)}m`
  758. );
  759. }
  760. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  761. },
  762. generateUniqueId(prefix = "id") {
  763. let idCounter = 0;
  764. return `${prefix}-${Date.now()}-${Math.random()
  765. .toString(36)
  766. .substr(2, 9)}-${idCounter++}`;
  767. },
  768. handleInitView() {
  769. if (this.showWindDetail) {
  770. this.resetWindViewport();
  771. } else {
  772. this.resetAllStationViewport();
  773. }
  774. },
  775. // 重置所有风场视角
  776. resetAllStationViewport() {
  777. this.viewer.camera.flyTo({
  778. destination: Cesium.Cartesian3.fromDegrees(
  779. 114.502778,
  780. 35.326667,
  781. 3000000
  782. ),
  783. orientation: {
  784. heading: Cesium.Math.toRadians(0),
  785. pitch: Cesium.Math.toRadians(-90),
  786. roll: 0.0,
  787. },
  788. duration: 3.0,
  789. });
  790. },
  791. // 重置风场中所有风机视角
  792. resetWindViewport() {
  793. let fromLon = this.$route.query.longitude * 1;
  794. let fromLat = this.$route.query.latitude * 1;
  795. let fromheight = this.$route.query.height * 1;
  796. let fromname = this.$route.query.nameEn;
  797. // 设置镜头到指定的经纬度(度)、高度(米)
  798. this.viewer.camera.setView({
  799. destination: Cesium.Cartesian3.fromDegrees(
  800. fromLon, // 经度 (degrees)
  801. fromLat, // 纬度 (degrees)
  802. fromheight // 高度 (meters)
  803. ),
  804. orientation: {
  805. heading: Cesium.Math.toRadians(0.0), // 偏航角 (方向,0 指向北方)
  806. pitch: Cesium.Math.toRadians(-90.0), // 俯仰角 (-90 是垂直向下)
  807. roll: 0.0, // 翻滚角
  808. },
  809. });
  810. // 目标位置:经度、纬度、高度
  811. // const targetLon = 114.48789;
  812. // const targetLat = 35.32916;
  813. let targetLon = null;
  814. let targetLat = null;
  815. this.restLatLon.forEach((it) => {
  816. if (it.name === fromname) {
  817. targetLon = it.longitude;
  818. targetLat = it.latitude;
  819. }
  820. });
  821. const targetHeight = 5000;
  822. const draggableHeightTolerance = 5000; // 允许拖拽的高度范围:20,000 ~ 30,000
  823. const minHeight = 5000; // 最低高度
  824. const maxHeight = 10000; // 最高高度
  825. const allowedOffsetDegrees = 0.2; // 允许拖拽的最大偏移(经纬度)
  826. const minLon = targetLon - allowedOffsetDegrees;
  827. const maxLon = targetLon + allowedOffsetDegrees;
  828. const minLat = targetLat - allowedOffsetDegrees;
  829. const maxLat = targetLat + allowedOffsetDegrees;
  830. let that = this;
  831. that.viewer.camera.flyTo({
  832. destination: Cesium.Cartesian3.fromDegrees(
  833. targetLon,
  834. targetLat,
  835. targetHeight
  836. ),
  837. orientation: {
  838. heading: Cesium.Math.toRadians(0),
  839. pitch: Cesium.Math.toRadians(-90),
  840. roll: 0.0,
  841. },
  842. duration: 3.0,
  843. complete: function () {
  844. console.log('飞入完成,启用拖拽限制逻辑');
  845. enableHeightBasedDragControl();
  846. }
  847. });
  848. // ===== 控制逻辑:根据高度决定是否允许拖拽 =====
  849. function enableHeightBasedDragControl() {
  850. that.viewer.scene.preUpdate.addEventListener(function (scene, time) {
  851. const camera = that.viewer.camera;
  852. const posCartographic = camera.positionCartographic;
  853. if (!posCartographic) return;
  854. const currentHeight = posCartographic.height;
  855. that.currentHeight = currentHeight;
  856. const currentLon = Cesium.Math.toDegrees(posCartographic.longitude);
  857. const currentLat = Cesium.Math.toDegrees(posCartographic.latitude);
  858. // === 第一步:限制相机高度不能超出 [10000, 100000] ===
  859. if (currentHeight < minHeight) {
  860. // 强制拉高到 minHeight,但保持当前水平视角
  861. const newPos = Cesium.Cartesian3.fromDegrees(
  862. currentLon,
  863. currentLat,
  864. minHeight
  865. );
  866. camera.setView({
  867. destination: newPos,
  868. orientation: {
  869. heading: camera.heading,
  870. pitch: camera.pitch,
  871. roll: camera.roll,
  872. },
  873. });
  874. return; // 避免后续逻辑冲突
  875. }
  876. if (currentHeight > maxHeight) {
  877. const newPos = Cesium.Cartesian3.fromDegrees(
  878. currentLon,
  879. currentLat,
  880. maxHeight
  881. );
  882. camera.setView({
  883. destination: newPos,
  884. orientation: {
  885. heading: camera.heading,
  886. pitch: camera.pitch,
  887. roll: camera.roll,
  888. },
  889. });
  890. return;
  891. }
  892. // if (currentHeight < (maxHeight-700000)) {
  893. // that.cancleAllLayer();
  894. // }
  895. // === 第二步:判断是否在“可拖拽高度区间” ===
  896. const isInDraggableRange =
  897. currentHeight >= targetHeight - draggableHeightTolerance &&
  898. currentHeight <= targetHeight + draggableHeightTolerance;
  899. if (isInDraggableRange) {
  900. // ✅ 允许拖拽,但限制在指定范围内
  901. const correctedLon = Cesium.Math.clamp(currentLon, minLon, maxLon);
  902. const correctedLat = Cesium.Math.clamp(currentLat, minLat, maxLat);
  903. if (
  904. Math.abs(correctedLon - currentLon) > 1e-8 ||
  905. Math.abs(correctedLat - currentLat) > 1e-8
  906. ) {
  907. // 越界了,纠正位置,保留当前高度和视角
  908. camera.setView({
  909. destination: Cesium.Cartesian3.fromDegrees(
  910. correctedLon,
  911. correctedLat,
  912. currentHeight
  913. ),
  914. orientation: {
  915. heading: camera.heading,
  916. pitch: camera.pitch,
  917. roll: camera.roll,
  918. },
  919. });
  920. }
  921. } else {
  922. // ❌ 不在可拖拽高度:禁止平移,强制回正到目标点
  923. const correctedPosition = Cesium.Cartesian3.fromDegrees(
  924. targetLon,
  925. targetLat,
  926. currentHeight // 保留当前缩放高度
  927. );
  928. camera.setView({
  929. destination: correctedPosition,
  930. orientation: {
  931. heading: camera.heading,
  932. pitch: camera.pitch,
  933. roll: camera.roll,
  934. },
  935. });
  936. }
  937. });
  938. }
  939. },
  940. coverOnChange(val) {
  941. if (val.value === "风场") {
  942. this.switchWindLayer(val.check);
  943. } else if (val.value === "云层") {
  944. this.switchCloudLayer(val.check);
  945. } else if (val.value === "降雨") {
  946. this.switchRainLayer(val.check);
  947. } else if (val.value === "温度") {
  948. this.switchTemperatureLayerr(val.check);
  949. }
  950. },
  951. // 提供控制函数以便在需要时停止循环
  952. stopCycling(intervalId) {
  953. if (intervalId) {
  954. clearInterval(intervalId);
  955. intervalId = null;
  956. console.log("循环已停止");
  957. }
  958. },
  959. // 切换风场图显隐
  960. switchWindLayer() {
  961. this.viewer.scene.screenSpaceCameraController.enableZoom = true;
  962. if (this.rainLayer || this.rainImagesLayer.length > 0) {
  963. this.removeRainLayer();
  964. this.stopCycling(this.rainintervalId);
  965. }
  966. if (this.cloudLayer || this.cloudImagesLayer.length > 0) {
  967. this.removeCloudLayer();
  968. this.stopCycling(this.cloudintervalId);
  969. }
  970. if (this.temperatureLayer || this.tempImagesLayer.length > 0) {
  971. this.removeTemperatureLayer();
  972. this.stopCycling(this.tempintervalId);
  973. }
  974. if (this.windLayer) {
  975. this.removeWindLayer();
  976. } else {
  977. this.showWindLayer();
  978. }
  979. },
  980. // 添加风场图
  981. async showWindLayer() {
  982. if (!this.windLayer) {
  983. this.windLayer = new WindLayer(windGridData, {
  984. particleSize: 2.0,
  985. particleOpacity: 0.6,
  986. particleSpeed: 0.01,
  987. maxVelocity: 25, // 风速最大值(用于颜色映射和速度缩放)
  988. minVelocity: 0, // 风速最小值阈值(低于此值不显示粒子)
  989. colorScale: [
  990. "rgb(36,104, 180)",
  991. "rgb(60,157, 194)",
  992. "rgb(128,205,193)",
  993. "rgb(151,218,168)",
  994. "rgb(198,231,181)",
  995. "rgb(238,247,217)",
  996. "rgb(255,238,159)",
  997. "rgb(252,217,125)",
  998. "rgb(255,182,100)",
  999. "rgb(252,150,75)",
  1000. "rgb(250,112,52)",
  1001. "rgb(245,64,32)",
  1002. "rgb(237,45,28)",
  1003. "rgb(220,24,32)",
  1004. "rgb(180,0,35)",
  1005. ], // 颜色强度缩放
  1006. frameRate: 15,
  1007. fadeOpacity: 0.995,
  1008. particleAge: 150,
  1009. maxAge: 60,
  1010. globalAlpha: 0.8,
  1011. velocityScale: 1 / 30, // 粒子移动速度缩放因子(控制动画快慢)
  1012. paths: 500,
  1013. lineWidth: 2,
  1014. });
  1015. this.windLayer.addTo(this.viewer);
  1016. }
  1017. },
  1018. // 切换卫星云图显隐
  1019. switchCloudLayer(val) {
  1020. if (this.windLayer) {
  1021. this.removeWindLayer();
  1022. }
  1023. if (this.rainLayer || this.rainImagesLayer.length > 0) {
  1024. this.removeRainLayer();
  1025. this.stopCycling(this.rainintervalId);
  1026. }
  1027. if (this.temperatureLayer || this.tempImagesLayer.length > 0) {
  1028. this.removeTemperatureLayer();
  1029. this.stopCycling(this.tempintervalId);
  1030. }
  1031. if (!val || this.cloudLayer || this.cloudImagesLayer.length > 0) {
  1032. this.removeCloudLayer();
  1033. this.stopCycling(this.cloudintervalId);
  1034. } else {
  1035. this.showCloudLayer();
  1036. }
  1037. },
  1038. // 切换降雨图显隐
  1039. switchRainLayer() {
  1040. this.viewer.scene.screenSpaceCameraController.enableZoom = true;
  1041. if (this.windLayer) {
  1042. this.removeWindLayer();
  1043. }
  1044. if (this.cloudLayer || this.cloudImagesLayer.length > 0) {
  1045. this.removeCloudLayer();
  1046. this.stopCycling(this.cloudintervalId);
  1047. }
  1048. if (this.temperatureLayer || this.tempImagesLayer.length > 0) {
  1049. this.removeTemperatureLayer();
  1050. this.stopCycling(this.tempintervalId);
  1051. }
  1052. if (this.rainLayer || this.rainImagesLayer.length > 0) {
  1053. this.removeRainLayer();
  1054. this.stopCycling(this.rainintervalId);
  1055. } else {
  1056. this.showRainLayer();
  1057. }
  1058. },
  1059. // 切换温度图显隐
  1060. switchTemperatureLayerr() {
  1061. this.viewer.scene.screenSpaceCameraController.enableZoom = true;
  1062. if (this.windLayer) {
  1063. this.removeWindLayer();
  1064. }
  1065. if (this.cloudLayer || this.cloudImagesLayer.length > 0) {
  1066. this.removeCloudLayer();
  1067. this.stopCycling(this.cloudintervalId);
  1068. }
  1069. if (this.rainLayer || this.rainImagesLayer.length > 0) {
  1070. this.removeRainLayer();
  1071. this.stopCycling(this.rainintervalId);
  1072. }
  1073. if (this.temperatureLayer || this.tempImagesLayer.length > 0) {
  1074. this.removeTemperatureLayer();
  1075. this.stopCycling(this.tempintervalId);
  1076. } else {
  1077. this.showTemperatureLayer();
  1078. }
  1079. },
  1080. // 显示云图
  1081. showCloudLayer() {
  1082. const imageUrls = [];
  1083. cloudJson.forEach((it) => {
  1084. imageUrls.push("/public/static" + it.path);
  1085. });
  1086. this.showeveryTypeImagesLayer(
  1087. imageUrls,
  1088. this.cloudintervalId,
  1089. this.cloudImagesLayer
  1090. );
  1091. },
  1092. //显示降雨图
  1093. showRainLayer() {
  1094. const imageUrls = [];
  1095. rainJson.forEach((it) => {
  1096. imageUrls.push("/public/static" + it.path);
  1097. });
  1098. this.showeveryTypeImagesLayer(
  1099. imageUrls,
  1100. this.rainintervalId,
  1101. this.rainImagesLayer
  1102. );
  1103. this.csceneElliposid(this.viewer, "rain");
  1104. },
  1105. //显示温度图
  1106. showTemperatureLayer() {
  1107. const imageUrls = [];
  1108. tempJson.forEach((it) => {
  1109. imageUrls.push("/public/static" + it.path);
  1110. });
  1111. this.showeveryTypeImagesLayer(
  1112. imageUrls,
  1113. this.tempintervalId,
  1114. this.tempImagesLayer
  1115. );
  1116. this.csceneElliposid(this.viewer, "temp");
  1117. },
  1118. async showeveryTypeImagesLayer(imageUrls, intervalId, ImagesLayers) {
  1119. // 存储所有图片图层的数组
  1120. let imageLayers = [];
  1121. // 当前显示的图片索引
  1122. let currentImageIndex = -1; // 初始为-1,表示没有图片显示
  1123. // 创建所有图片图层并添加到Viewer,初始时全部隐藏
  1124. await imageUrls.forEach((url) => {
  1125. const provider = new Cesium.SingleTileImageryProvider({
  1126. url: url,
  1127. // url: URL.createObjectURL(url),
  1128. rectangle: Cesium.Rectangle.fromDegrees(-180.0, -90.0, 180.0, 90.0), // 全球覆盖
  1129. tileWidth: 1440, // 根据你的图片实际宽度修改
  1130. tileHeight: 721,
  1131. // 如果你的图片只覆盖特定区域,请修改rectangle参数
  1132. });
  1133. const Layer = this.viewer.imageryLayers.addImageryProvider(provider);
  1134. Layer.alpha = 0.8; // 透明度
  1135. Layer.brightness = 1; // 亮度
  1136. Layer.contrast = 1; // 对比度
  1137. Layer.show = false; // 初始隐藏
  1138. imageLayers.push(Layer);
  1139. ImagesLayers.push(Layer);
  1140. });
  1141. function showNextImage() {
  1142. // 隐藏当前图片
  1143. if (currentImageIndex >= 0 && currentImageIndex < imageLayers.length) {
  1144. imageLayers[currentImageIndex].show = false;
  1145. }
  1146. // 计算下一张图片的索引
  1147. currentImageIndex = (currentImageIndex + 1) % imageLayers.length;
  1148. // 显示下一张图片
  1149. imageLayers[currentImageIndex].show = true;
  1150. // imageLayers[currentImageIndex + 1].show = true;
  1151. console.log("当前显示图片: " + imageUrls[currentImageIndex]);
  1152. }
  1153. // 设置切换间隔(毫秒),例如每5秒切换一次
  1154. const intervalMs = 5000;
  1155. intervalId = setInterval(showNextImage, intervalMs);
  1156. // 初始显示第一张图片
  1157. showNextImage();
  1158. },
  1159. // 移除风场图
  1160. removeWindLayer() {
  1161. if (this.windLayer) {
  1162. // this.windLayer.destroy();
  1163. this.windLayer.remove();
  1164. this.windLayer = null;
  1165. }
  1166. },
  1167. // 移除卫星云图
  1168. removeCloudLayer() {
  1169. if (this.cloudLayer) {
  1170. this.tagMsg = null;
  1171. this.viewer.imageryLayers.remove(this.cloudLayer);
  1172. this.cloudLayer = null;
  1173. }
  1174. if (this.cloudImagesLayer.length > 0) {
  1175. this.cloudImagesLayer.forEach((it) => {
  1176. this.viewer.imageryLayers.remove(it);
  1177. });
  1178. this.cloudImagesLayer = [];
  1179. }
  1180. if (this.imageryProviderV) {
  1181. this.viewer.imageryLayers.remove(this.imageryProviderV);
  1182. this.imageryProviderV = null;
  1183. }
  1184. },
  1185. // 移除降雨图
  1186. removeRainLayer() {
  1187. if (this.rainLayer) {
  1188. this.tagMsg = null;
  1189. this.viewer.imageryLayers.remove(this.rainLayer);
  1190. this.rainLayer = null;
  1191. this.setMapImageryProvider();
  1192. this.handlerAction.removeInputAction(
  1193. Cesium.ScreenSpaceEventType.LEFT_CLICK
  1194. );
  1195. }
  1196. if (this.rainImagesLayer.length > 0) {
  1197. this.rainImagesLayer.forEach((it) => {
  1198. this.viewer.imageryLayers.remove(it);
  1199. });
  1200. this.rainImagesLayer = [];
  1201. }
  1202. if (this.imageryProviderV) {
  1203. this.viewer.imageryLayers.remove(this.imageryProviderV);
  1204. this.imageryProviderV = null;
  1205. }
  1206. },
  1207. // 移除温度图
  1208. removeTemperatureLayer() {
  1209. if (this.temperatureLayer) {
  1210. this.tagMsg = null;
  1211. this.viewer.imageryLayers.remove(this.temperatureLayer);
  1212. this.temperatureLayer = null;
  1213. this.setMapImageryProvider();
  1214. this.handlerAction.removeInputAction(
  1215. Cesium.ScreenSpaceEventType.LEFT_CLICK
  1216. );
  1217. }
  1218. if (this.tempImagesLayer.length > 0) {
  1219. this.tempImagesLayer.forEach((it) => {
  1220. this.viewer.imageryLayers.remove(it);
  1221. });
  1222. this.tempImagesLayer = [];
  1223. }
  1224. if (this.imageryProviderV) {
  1225. this.viewer.imageryLayers.remove(this.imageryProviderV);
  1226. this.imageryProviderV = null;
  1227. }
  1228. },
  1229. //取消所有图层加载
  1230. cancleAllLayer() {
  1231. if (this.windLayer) {
  1232. this.removeWindLayer();
  1233. }
  1234. if (this.rainLayer || this.rainImagesLayer.length > 0) {
  1235. this.removeRainLayer();
  1236. this.stopCycling(this.rainintervalId);
  1237. }
  1238. if (this.cloudLayer || this.cloudImagesLayer.length > 0) {
  1239. this.removeCloudLayer();
  1240. this.stopCycling(this.cloudintervalId);
  1241. }
  1242. if (this.temperatureLayer || this.tempImagesLayer.length > 0) {
  1243. this.removeTemperatureLayer();
  1244. this.stopCycling(this.tempintervalId);
  1245. }
  1246. },
  1247. switchLayer() {
  1248. this.$router.push({
  1249. path: "/",
  1250. });
  1251. },
  1252. menuComTSty(val) {
  1253. this.menuComTStyB = val;
  1254. },
  1255. },
  1256. };
  1257. </script>
  1258. <style lang="less" scoped>
  1259. .dataLoading {
  1260. width: 100vw;
  1261. height: 100vh;
  1262. background: rgba(0, 0, 0, 0.5);
  1263. z-index: 999;
  1264. position: fixed;
  1265. .loadText {
  1266. position: absolute;
  1267. top: 50%;
  1268. left: 50%;
  1269. transform: translate(-50%, -50%);
  1270. background: rgba(255, 255, 255, 0.7);
  1271. padding: 15px 20px;
  1272. border-radius: 6px;
  1273. color: black;
  1274. font-size: 14px;
  1275. font-weight: bold;
  1276. }
  1277. }
  1278. .mapBox {
  1279. width: 100%;
  1280. height: 100%;
  1281. position: relative;
  1282. box-sizing: content-box;
  1283. overflow: hidden;
  1284. .menuComT {
  1285. position: fixed;
  1286. bottom: 400px;
  1287. left: 20px;
  1288. }
  1289. .menuComTSty {
  1290. position: fixed;
  1291. bottom: 20px;
  1292. left: 20px;
  1293. }
  1294. }
  1295. </style>
  1296. <style lang="less">
  1297. .el-overlay {
  1298. background-color: transparent !important;
  1299. .windModelDrawer {
  1300. width: 80% !important;
  1301. backdrop-filter: blur(15px) !important;
  1302. background: rgba(255, 255, 255, 0.8) !important;
  1303. border-radius: 10px 0 0 10px !important;
  1304. .el-drawer__body {
  1305. overflow: hidden;
  1306. padding-top: 0;
  1307. }
  1308. }
  1309. }
  1310. .windDrawerCla {
  1311. .line {
  1312. display: flex;
  1313. flex-direction: row;
  1314. align-items: center;
  1315. justify-content: space-between;
  1316. width: 100%;
  1317. margin-bottom: 10px;
  1318. .leftContent {
  1319. width: 242px;
  1320. height: 41px;
  1321. display: flex;
  1322. align-items: center;
  1323. background: url("@/assets/cesiumImg/title_left_bg.png") no-repeat;
  1324. span {
  1325. font-size: 16px;
  1326. font-family: Microsoft YaHei;
  1327. font-weight: 400;
  1328. color: #ffffff;
  1329. margin-left: 25px;
  1330. }
  1331. }
  1332. }
  1333. .jcxx,
  1334. .gzck {
  1335. height: 100%;
  1336. }
  1337. .spjk,
  1338. .third {
  1339. height: 80vh;
  1340. }
  1341. }
  1342. </style>