index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. const Nightscape = {
  2. GeoJsonLayerList: [],
  3. liudongGntities: [],
  4. routesGroupByAirline: {},
  5. tiyuchangdg: [],
  6. tiyuchangdg1: [],
  7. tiyuchangdg2: [],
  8. tiyuchangdg3: [],
  9. dgdsq: null,
  10. tycindex: 0,
  11. t: 0,
  12. //打开夜景
  13. openNightSwitch() {
  14. store.state.isNightSwitch = true;
  15. this.startNight(true);
  16. },
  17. closNightSwitch() {
  18. store.state.isNightSwitch = false;
  19. this.startNight(false);
  20. },
  21. //夜景开关
  22. startNight(isNight) {
  23. let that = this;
  24. scene.globe.show = true;
  25. viewer.scene.hdrEnabled = isNight;
  26. viewer.scene.bloomEffect.show = false;
  27. // 是否开启夜景
  28. if (!isNight) {
  29. if (this.dgdsq) {
  30. clearTimeout(this.dgdsq);
  31. }
  32. if (scene.layers.find("白天")) scene.layers.find("白天").visible = true;
  33. if (scene.layers.find("夜晚")) scene.layers.find("夜晚").visible = false;
  34. scene.sun.show = true;
  35. this.clearLightSource(true, true);
  36. scene.skyAtmosphere.show = true;
  37. this.switchLight(true); //白天
  38. this.setHypsometric(false); //夜景材质
  39. viewer.imageryLayers.remove(this.imageLayer);
  40. } else {
  41. scene.sun.show = false;
  42. if (scene.layers.find("白天")) scene.layers.find("白天").visible = false;
  43. if (scene.layers.find("夜晚")) scene.layers.find("夜晚").visible = true;
  44. // 泛光线底纹
  45. let roadLine1 = Cesium.GeoJsonDataSource.load(window.NightLightUrl.csfgx);
  46. roadLine1
  47. .then(function (dataSource) {
  48. viewer.dataSources.add(dataSource);
  49. that.GeoJsonLayerList.push(dataSource);
  50. let lines_1 = dataSource.entities.values;
  51. for (let i = 0; i < lines_1.length; i++) {
  52. let line = lines_1[i];
  53. line.polyline.material = new Cesium.PolylineGlowMaterialProperty({
  54. //设置Glow材质
  55. glowPower: 0.005,
  56. color: Cesium.Color.ORANGE.withAlpha(0.9),
  57. });
  58. line.polyline.width = 50;
  59. }
  60. })
  61. .otherwise(function (error) {
  62. window.alert(error);
  63. });
  64. let roadLine2 = Cesium.GeoJsonDataSource.load(window.NightLightUrl.csfgx);
  65. //泛光亮线
  66. roadLine2
  67. .then(function (dataSource) {
  68. viewer.dataSources.add(dataSource);
  69. that.GeoJsonLayerList.push(dataSource);
  70. let lines_1 = dataSource.entities.values;
  71. for (let i = 0; i < lines_1.length; i++) {
  72. let line = lines_1[i];
  73. line.polyline.material = new Cesium.PolylineGlowMaterialProperty({
  74. //设置Glow材质
  75. glowPower: 0.001,
  76. color: Cesium.Color.white,
  77. });
  78. line.polyline.width = 5;
  79. }
  80. })
  81. .otherwise(function (error) {
  82. window.alert(error);
  83. });
  84. //地标灯光
  85. Cesium.loadJson(window.NightLightUrl.yshdg).then((response) => {
  86. let features = response.features;
  87. features.forEach((element) => {
  88. let p = element.geometry.coordinates;
  89. var SpotLightPos3 = new Cesium.Cartesian3.fromDegrees(
  90. p[0],
  91. p[1],
  92. p[2] + 20
  93. );
  94. // var SpotLightPos32 = new Cesium.Cartesian3.fromDegrees(
  95. // p[0],
  96. // p[1],
  97. // p[2]
  98. // );
  99. var SpotLightOptions3 = {
  100. cutoffDistance: 100,
  101. color: new Cesium.Color(18 / 255, 80 / 255, 193 / 255, 1),
  102. decay: 2,
  103. intensity: 1,
  104. };
  105. let SpotLight33 = new Cesium.PointLight(
  106. SpotLightPos3,
  107. // SpotLightPos32,
  108. SpotLightOptions3
  109. );
  110. scene.addLightSource(SpotLight33);
  111. });
  112. });
  113. // 体育场灯光
  114. Cesium.loadJson(window.NightLightUrl.tycdg).then((response) => {
  115. let features = response.features;
  116. features.forEach((element, indx) => {
  117. let p = element.geometry.coordinates;
  118. var SpotLightPos3 = new Cesium.Cartesian3.fromDegrees(
  119. p[0],
  120. p[1],
  121. p[2] + 10
  122. );
  123. var SpotLightOptions3 = {
  124. cutoffDistance: 150,
  125. color: new Cesium.Color(245 / 255, 250 / 255, 216 / 255, 0.51),
  126. decay: 1,
  127. intensity: 1,
  128. };
  129. let SpotLight33 = new Cesium.PointLight(
  130. SpotLightPos3,
  131. // SpotLightPos32,
  132. SpotLightOptions3
  133. );
  134. that.tiyuchangdg.push(SpotLight33);
  135. scene.addLightSource(SpotLight33);
  136. });
  137. let sd = that.splitArray(that.tiyuchangdg);
  138. that.tiyuchangdg1 = sd[0];
  139. that.tiyuchangdg2 = sd[1];
  140. that.tiyuchangdg3 = sd[2];
  141. });
  142. // // 道路灯光
  143. Cesium.loadJson(window.NightLightUrl.dldg).then((response) => {
  144. let features = response.features;
  145. features.forEach((element) => {
  146. let p = element.geometry.coordinates;
  147. var SpotLightPos3 = new Cesium.Cartesian3.fromDegrees(
  148. p[0],
  149. p[1],
  150. p[2] + 40
  151. );
  152. var SpotLightOptions3 = {
  153. cutoffDistance: 130,
  154. color: new Cesium.Color(209 / 255, 209 / 255, 147 / 255, 0.5),
  155. decay: 1,
  156. intensity: 1,
  157. };
  158. let SpotLight33 = new Cesium.PointLight(
  159. SpotLightPos3,
  160. // SpotLightPos32,
  161. SpotLightOptions3
  162. );
  163. scene.addLightSource(SpotLight33);
  164. });
  165. });
  166. // 草坪灯光
  167. Cesium.loadJson(window.NightLightUrl.cpdg).then((response) => {
  168. let features = response.features;
  169. features.forEach((element) => {
  170. let p = element.geometry.coordinates;
  171. var SpotLightPos3 = new Cesium.Cartesian3.fromDegrees(
  172. p[0],
  173. p[1],
  174. p[2] + 20
  175. );
  176. var SpotLightOptions3 = {
  177. cutoffDistance: 90,
  178. color: new Cesium.Color(209 / 255, 209 / 255, 147 / 255, 1),
  179. decay: 1,
  180. intensity: 1,
  181. };
  182. let SpotLight33 = new Cesium.PointLight(
  183. SpotLightPos3,
  184. // SpotLightPos32,
  185. SpotLightOptions3
  186. );
  187. scene.addLightSource(SpotLight33);
  188. });
  189. });
  190. this.loadldx();
  191. this.switchLight(false);
  192. scene.skyAtmosphere.show = false;
  193. this.setHypsometric(true); //夜景
  194. this.imageLayer = viewer.imageryLayers.addImageryProvider(
  195. new Cesium.SingleTileImageryProvider({
  196. url: "static/images/zt/Nightscape/BlackMarble_2016-1.jpg",
  197. })
  198. );
  199. this.imageLayer.alpha = 0.5;
  200. if (this.dgdsq) {
  201. clearTimeout(dgdsq);
  202. }
  203. this.dgdsq = setInterval(function () {
  204. that.tycindex += 1;
  205. that.t += 0.2;
  206. if (that.t > 1) {
  207. that.t = 0;
  208. }
  209. let rgb = that.lerpColor("5,33,232", "232,222,5", that.t);
  210. let isch = false;
  211. if (that.tiyuchangdg1.length > that.tycindex) {
  212. that.tiyuchangdg1[that.tycindex].color = new Cesium.Color(
  213. rgb.r / 255,
  214. rgb.g / 255,
  215. rgb.b / 255,
  216. 0.51
  217. );
  218. isch = true;
  219. }
  220. if (that.tiyuchangdg2.length > that.tycindex) {
  221. that.tiyuchangdg2[that.tycindex].color = new Cesium.Color(
  222. rgb.r / 255,
  223. rgb.g / 255,
  224. rgb.b / 255,
  225. 0.51
  226. );
  227. isch = true;
  228. }
  229. if (that.tiyuchangdg3.length > that.tycindex) {
  230. that.tiyuchangdg3[that.tycindex].color = new Cesium.Color(
  231. rgb.r / 255,
  232. rgb.g / 255,
  233. rgb.b / 255,
  234. 0.51
  235. );
  236. isch = true;
  237. }
  238. if (!isch) {
  239. that.tycindex = 0;
  240. }
  241. }, 1000 * 1);
  242. }
  243. },
  244. //设置环境光
  245. switchLight(isDayLight) {
  246. if (isDayLight) {
  247. //设置环境光(白天)
  248. scene.lightSource.ambientLightColor = new Cesium.Color(
  249. 0.65,
  250. 0.65,
  251. 0.65,
  252. 1
  253. );
  254. } else {
  255. //设置环境光(夜晚)
  256. // scene.lightSource.ambientLightColor = new Cesium.Color(0.3, 0.3, 0.3, 1);
  257. // 添加光源
  258. // this.addLightSource({
  259. // gyType: "点光源",
  260. // cartesian: new Cesium.Cartesian3.fromDegrees(
  261. // 109.51762123055649,
  262. // 18.308419781897452,
  263. // 20.784050116021502
  264. // ),
  265. // gyDecay: 5,
  266. // gyDistance: 300,
  267. // gyColor: "rgba(255,255,255,1)",
  268. // gyIntensity: 5,
  269. // });
  270. // this.addLightSource({
  271. // gyType: "点光源",
  272. // cartesian: new Cesium.Cartesian3.fromDegrees(
  273. // 109.51604504373526,
  274. // 18.30819674716975,
  275. // 15.12013402227458
  276. // ),
  277. // gyDecay: 1,
  278. // gyDistance: 200,
  279. // gyColor: "rgba(255,255,255,1)",
  280. // gyIntensity: 2,
  281. // });
  282. // this.addLightSource({
  283. // gyType: "点光源",
  284. // cartesian: new Cesium.Cartesian3.fromDegrees(
  285. // 109.51119765783854,
  286. // 18.311007882958762,
  287. // 15.514382420330742
  288. // ),
  289. // gyDecay: 1,
  290. // gyDistance: 200,
  291. // gyColor: "rgba(255,255,255,1)",
  292. // gyIntensity: 2,
  293. // });
  294. // this.addLightSource({
  295. // gyType: "点光源",
  296. // cartesian: new Cesium.Cartesian3.fromDegrees(
  297. // 109.5109719906024,
  298. // 18.312138464239744,
  299. // 15.514382420330742
  300. // ),
  301. // gyDecay: 1,
  302. // gyDistance: 200,
  303. // gyColor: "rgba(255,255,255,1)",
  304. // gyIntensity: 2,
  305. // });
  306. // this.addLightSource({
  307. // gyType: "点光源",
  308. // cartesian: new Cesium.Cartesian3.fromDegrees(
  309. // 109.5155257151904,
  310. // 18.312710967602822,
  311. // 15.0056539031313925
  312. // ),
  313. // gyDecay: 1,
  314. // gyDistance: 200,
  315. // gyColor: "rgba(255,255,255,1)",
  316. // gyIntensity: 2,
  317. // });
  318. // this.addLightSource({
  319. // gyType: "点光源",
  320. // cartesian: new Cesium.Cartesian3.fromDegrees(
  321. // 109.51794125594411,
  322. // 18.310599330540743,
  323. // 14.172257598338254
  324. // ),
  325. // gyDecay: 1,
  326. // gyDistance: 200,
  327. // gyColor: "rgba(255,255,255,1)",
  328. // gyIntensity: 2,
  329. // });
  330. //操场光源
  331. this.addLightSource({
  332. gyType: "点光源",
  333. cartesian: new Cesium.Cartesian3.fromDegrees(
  334. 109.51144104226398,
  335. 18.311654492261003,
  336. 24.172257598338254
  337. ),
  338. gyDecay: 2,
  339. gyDistance: 200,
  340. gyColor: "rgba(255,255,255,1)",
  341. gyIntensity: 2,
  342. });
  343. // 新增直射光1--西南侧光
  344. var position = new Cesium.Cartesian3.fromDegrees(
  345. 108.64028472779978,
  346. 17.253899597841926,
  347. 10
  348. );
  349. var targetPosition1 = new Cesium.Cartesian3.fromDegrees(
  350. 108.98714556856183,
  351. 17.660729210061046,
  352. 10
  353. );
  354. var dirLightOptions = {
  355. targetPosition: targetPosition1,
  356. color: new Cesium.Color(220 / 255, 230 / 255, 240 / 255, 0.5),
  357. intensity: 1,
  358. };
  359. this.directionalLight_1 &&
  360. scene.removeLightSource(this.directionalLight_1);
  361. this.directionalLight_1 = new Cesium.DirectionalLight(
  362. position,
  363. dirLightOptions
  364. );
  365. scene.addLightSource(this.directionalLight_1);
  366. //新增直射光1--东北侧光
  367. var position3 = new Cesium.Cartesian3.fromDegrees(
  368. 110.1833740842942,
  369. 19.23480287256715,
  370. 10
  371. );
  372. var targetPosition3 = new Cesium.Cartesian3.fromDegrees(
  373. 109.92243671490641,
  374. 18.823627245617516,
  375. 10
  376. );
  377. var dirLightOptions3 = {
  378. targetPosition: targetPosition3,
  379. color: new Cesium.Color(220 / 255, 223 / 255, 227 / 255, 0.5),
  380. intensity: 1.5,
  381. };
  382. this.directionalLight_3 &&
  383. scene.removeLightSource(this.directionalLight_3);
  384. this.directionalLight_3 = new Cesium.DirectionalLight(
  385. position3,
  386. dirLightOptions3
  387. );
  388. scene.addLightSource(this.directionalLight_3);
  389. //新增直射光1--顶光
  390. var position4 = new Cesium.Cartesian3.fromDegrees(
  391. 109.5264539133307,
  392. 18.2736162462657,
  393. 500
  394. );
  395. var targetPosition4 = new Cesium.Cartesian3.fromDegrees(
  396. 109.5264539133307,
  397. 18.2736162462657,
  398. 400
  399. );
  400. var dirLightOptions4 = {
  401. targetPosition: targetPosition4,
  402. color: Cesium.Color.SILVER.withAlpha(0.5),
  403. intensity: 0.1,
  404. };
  405. this.directionalLight_4 &&
  406. scene.removeLightSource(this.directionalLight_4);
  407. this.directionalLight_4 = new Cesium.DirectionalLight(
  408. position4,
  409. dirLightOptions4
  410. );
  411. scene.addLightSource(this.directionalLight_4);
  412. }
  413. },
  414. //设置白膜自发光纹理
  415. setHypsometric(isShow = true) {
  416. if (isShow) {
  417. scene.layers.layerQueue.forEach((layer) => {
  418. let hyp = null;
  419. let LayerName = window.NightViewLayerName.find((c) => c == layer.name);
  420. if (LayerName) {
  421. // 关掉边框线
  422. layer.style3D.fillStyle = Cesium.FillStyle.Fill;
  423. hyp = new Cesium.HypsometricSetting();
  424. hyp.emissionTextureArray = [
  425. {
  426. url: "static/images/zt/Nightscape/Texture05.jpg",
  427. USpeed: 0.5,
  428. VSpeed: 0,
  429. UTiling: 1,
  430. VTiling: 1,
  431. },
  432. {
  433. url: "static/images/zt/Nightscape/Texture01.jpg",
  434. USpeed: 0.5,
  435. VSpeed: 0,
  436. UTiling: 1,
  437. VTiling: 1,
  438. },
  439. {
  440. url: "static/images/zt/Nightscape/build008.JPG",
  441. USpeed: 0,
  442. VSpeed: 0,
  443. UTiling: 1,
  444. VTiling: 3,
  445. },
  446. {
  447. url: "static/images/zt/Nightscape/build129.JPG",
  448. USpeed: 0,
  449. VSpeed: 0,
  450. UTiling: 1,
  451. VTiling: 3,
  452. },
  453. {
  454. url: "static/images/zt/Nightscape/build216.JPG",
  455. USpeed: 0,
  456. VSpeed: 0,
  457. UTiling: 1,
  458. VTiling: 3,
  459. },
  460. // {
  461. // url: "static/images/zt/Nightscape/HighRiseNight0008_4_S.jpg",
  462. // USpeed: 0,
  463. // VSpeed: 0,
  464. // UTiling: 1,
  465. // VTiling: 1,
  466. // },
  467. // {
  468. // url: "static/images/zt/Nightscape/HighRiseNight0016_3_L.jpg",
  469. // USpeed: 0,
  470. // VSpeed: 0,
  471. // UTiling: 1,
  472. // VTiling: 1,
  473. // },
  474. // {
  475. // url: "static/images/zt/Nightscape/HighRiseNight0020_L.jpg",
  476. // USpeed: 0,
  477. // VSpeed: 0,
  478. // UTiling: 1,
  479. // VTiling: 1,
  480. // },
  481. ];
  482. layer.hypsometricSetting = {
  483. hypsometricSetting: hyp,
  484. };
  485. }
  486. });
  487. } else {
  488. scene.layers.layerQueue.forEach((layer) => {
  489. layer.hypsometricSetting = {
  490. hypsometricSetting: undefined,
  491. };
  492. layer.style3D.fillStyle = Cesium.FillStyle.Fill;
  493. // 刷新场景
  494. // layer.refresh();
  495. });
  496. }
  497. },
  498. /**
  499. * 流动线
  500. */
  501. loadldx() {
  502. let that = this;
  503. Cesium.loadJson(window.NightLightUrl.dlzxx).then((jsonData) => {
  504. debugger;
  505. jsonData.features.forEach((route) => {
  506. let list = route.geometry.coordinates.flat(Infinity);
  507. debugger;
  508. let dl = viewer.entities.add({
  509. // 用于打底的线
  510. polyline: {
  511. positions: Cesium.Cartesian3.fromDegreesArrayHeights(list),
  512. width: 5, // 线的宽度,像素为单位
  513. material: Cesium.Color.BLACK.withAlpha(0.3),
  514. },
  515. });
  516. this.liudongGntities.push(dl);
  517. let dls = viewer.entities.add({
  518. id: route.properties.OBJECTID,
  519. polyline: {
  520. positions: Cesium.Cartesian3.fromDegreesArrayHeights(list),
  521. width: 4.0,
  522. material: new Cesium.PolylineTrailMaterialProperty({
  523. outlineColor: Cesium.Color.WHITE,
  524. outlineWidth: 3,
  525. color: Cesium.Color.fromCssColorString("rgba(127, 255, 0, 1)"),
  526. trailLength: 0.3,
  527. period: 4.0,
  528. }),
  529. },
  530. });
  531. this.liudongGntities.push(dls);
  532. });
  533. });
  534. },
  535. /**
  536. * 添加光源
  537. * @param {} gyData
  538. */
  539. addLightSource(gyData) {
  540. switch (gyData.gyType) {
  541. case "点光源":
  542. let option = {
  543. color: Cesium.Color.fromCssColorString(gyData.gyColor),
  544. cutoffDistance: Number(gyData.gyDistance),
  545. decay: Number(gyData.gyDecay),
  546. intensity: Number(gyData.gyIntensity),
  547. };
  548. let pointLight = new Cesium.PointLight(gyData.cartesian, option);
  549. scene.addLightSource(pointLight);
  550. break;
  551. case "聚光灯":
  552. let spotLightOptions = {
  553. color: Cesium.Color.fromCssColorString(gyData.gyColor),
  554. distance: Number(gyData.gyDistance),
  555. decay: Number(gyData.gyDecay),
  556. intensity: Number(gyData.gyIntensity),
  557. angle: Cesium.Math.toRadians(Number(gyData.gyangle)),
  558. };
  559. let spotLight = new Cesium.SpotLight(
  560. gyData.cartesian[0],
  561. gyData.cartesian[1],
  562. spotLightOptions
  563. );
  564. scene.addLightSource(spotLight);
  565. break;
  566. case "直射光":
  567. let directionalLightOptions = {
  568. targetPosition: gyData.cartesian[1],
  569. color: Cesium.Color.fromCssColorString(gyData.gyColor),
  570. intensity: Number(gyData.gyIntensity),
  571. };
  572. let directionalLight = new Cesium.DirectionalLight(
  573. gyData.cartesian[0],
  574. directionalLightOptions
  575. );
  576. scene.addLightSource(directionalLight);
  577. break;
  578. default:
  579. break;
  580. }
  581. },
  582. /**
  583. * 删除灯光
  584. * @param isAllRemoveLightSource 是否删除所有灯光
  585. */
  586. clearLightSource(isAllRemoveLightSource = false) {
  587. if (isAllRemoveLightSource) {
  588. while (scene.lightSource.pointLight.values.length > 0) {
  589. scene.removeLightSource(scene.lightSource.pointLight.values[0]);
  590. }
  591. while (scene.lightSource.spotLight.values.length > 0) {
  592. scene.removeLightSource(scene.lightSource.spotLight.values[0]);
  593. }
  594. while (scene.lightSource.directionalLight.values.length > 0) {
  595. scene.removeLightSource(scene.lightSource.directionalLight.values[0]);
  596. }
  597. this.GeoJsonLayerList.forEach((element) => {
  598. viewer.dataSources.remove(element);
  599. });
  600. this.liudongGntities.forEach((element) => {
  601. viewer.entities.remove(element);
  602. });
  603. }
  604. },
  605. lerpColor(startColor, endColor, t) {
  606. // 解析颜色字符串为数组
  607. let start = startColor.split(",").map(Number);
  608. let end = endColor.split(",").map(Number);
  609. // 计算渐变后的颜色值
  610. let r = start[0] + (end[0] - start[0]) * t;
  611. let g = start[1] + (end[1] - start[1]) * t;
  612. let b = start[2] + (end[2] - start[2]) * t;
  613. // 返回结果为字符串格式
  614. return { r, g, b };
  615. },
  616. splitArray(arr) {
  617. let chunkSize = Math.ceil(arr.length / 3); // 计算每个子数组应该有的元素数量
  618. let result = [];
  619. for (let i = 0; i < arr.length; i += chunkSize) {
  620. let chunk = arr.slice(i, i + chunkSize); // 使用slice方法获取子数组
  621. // 如果需要,可以将子数组中的元素按特定顺序重新排列
  622. // 例如,如果你想保持每组的元素顺序与原始数组中的顺序相同,但分成三个子数组
  623. // 则不需要额外的逻辑,因为slice已经按照顺序返回了元素
  624. result.push(chunk); // 将子数组添加到结果数组中
  625. }
  626. // 如果需要,你可以对结果数组中的每个子数组进行额外的处理
  627. // 例如,按照你给出的例子,我们需要将每个子数组的元素重新排序
  628. result = result.map((chunk, index) => {
  629. // 根据索引确定每个子数组中元素的最终位置
  630. return chunk
  631. .map((value, i) => {
  632. // 使用模运算来确定元素在最终数组中的位置
  633. let finalIndex = (i + index) % 3;
  634. // 如果最终索引小于子数组的长度,则返回当前值,否则返回undefined(但在这个例子中,不会有undefined)
  635. return finalIndex < chunkSize ? value : undefined;
  636. })
  637. .filter((value) => value !== undefined); // 过滤掉undefined值(如果有的话)
  638. });
  639. // 但是,在这个特定的例子中,我们不需要上面的重新排序步骤
  640. // 因为我们只需要简单地按照原始数组的顺序将元素分配给三个子数组
  641. return result;
  642. },
  643. };
  644. export default Nightscape;