| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818 |
- <template>
- <div id="loading" class="dataLoading" v-if="loading">
- <span class="loadText">数据加载中...</span>
- </div>
- <div class="mapBox">
- <div id="cesiumContainer" style="width: 100%; height: 100vh"></div>
- <div :class="!menuComTStyB ? 'menuComTSty' : 'menuComT'" v-if="0">
- <menuCom
- :showbasemap="false"
- :showwindspeed="false"
- :showcloud="false"
- :showrainfall="false"
- :showtemperature="false"
- :showcity="false"
- :showwind="false"
- :showexit="true"
- :showwindModel="true"
- @handleWindModel="showwindmodel"
- @handleInit="handleInitView"
- @handleExit="switchLayer"
- />
- </div>
- <el-drawer
- v-model="windDrawer"
- direction="rtl"
- class="windModelDrawer"
- :before-close="handleClose"
- >
- <template #header>
- <h3 style="font-weight: bold">{{ windDrawerHeader }}</h3>
- </template>
- <template #default>
- <div class="windDrawerCla">
- <div class="line" v-if="!showModelMsg">
- <div class="leftContent">
- <span>{{ windDrawerTitle }}</span>
- </div>
- </div>
- <div class="jcxx" v-if="showBasicMsg">
- <windHome :modelValItem="modelVal" />
- </div>
- <div class="spjk" v-if="showVideoMsg">
- <!-- <iframe
- src="/public/static/windVideo.mp4"
- frameborder="0"
- style="width: 100%; height: 100%"
- ></iframe> -->
- <video ref="videoPlayer" controls width="95%" muted autoplay>
- <source src="/static/windVideo.mp4" type="video/mp4" />
- </video>
- </div>
- <div class="gzck" v-if="showProblemMsg">
- <windPro />
- </div>
- <div class="third" v-if="showModelMsg">
- <ModelUnpack
- :modelUnpackType="modelUnpackType"
- :showModelMsg="showModelMsg"
- />
- </div>
- </div>
- </template>
- </el-drawer>
- <comModelDialog
- :showcomModelDia="showcomModelDia"
- :modelVal="modelVal"
- @showDia="showComDia"
- />
- <!-- @backStations="backStations" -->
- <!-- <windView
- v-if="showWindDetail"
- @coverOnChange="coverOnChange"
- :currentHeight="currentHeight"
- :fjLonLatJsonArr="fjLonLatJsonArr.data"
- @showDetail="menuComTSty"
- @resetChangeWind="resetChangeWind"
- @initView="resetWindViewport"
- /> -->
- <windView2
- v-if="showWindDetail"
- :cesiumViewer="viewer"
- @coverOnChange="coverOnChange"
- :currentHeight="currentHeight"
- :fjLonLatJsonArr="fjLonLatJsonArr.data"
- @showDetail="menuComTSty"
- @resetChangeWind="resetChangeWind"
- />
- </div>
- </template>
- <script>
- import * as Cesium from "../../Cesium";
- import "../../Cesium/Widgets/widgets.css";
- import fjMYLonLatJson from "../fjLonLatJson/fj_MY.json"; //迈越风电场
- import fjWHZLonLatJson from "../fjLonLatJson/fj_WHZ.json"; //京能旺海庄
- import fjYPLLonLatJson from "../fjLonLatJson/fj_YPL.json"; //京能营盘梁
- import fjSMSLonLatJson from "../fjLonLatJson/fj_SMS.json"; //京能苏木山
- import wsRes from "../fjLonLatJson/wsRes.json"; // 模拟 ws 返回数据
- import allStationJson from "./allStationJson.json";
- import basicGeoJson from "../../assets/geoJson/basic.json";
- import comModelDialog from "@/components/comModelDialog.vue";
- import windView from "./windView.vue";
- import menuCom from "../menuCom.vue";
- import windView2 from "./windView2.vue";
- import cloudJson from "/public/static/exportData/cloud/layer.json";
- import rainJson from "/public/static/exportData/rain/layer.json";
- import tempJson from "/public/static/exportData/tmp/layer.json";
- // import bw from "@/assets/windimgs/fanSvg/bw.svg"
- //风场展示图标
- import fc from "@/assets/windimgs/fanSvg/fc.png";
- //火电展示图标
- import hd from "@/assets/windimgs/fanSvg/hd.png";
- //光伏电站展示图标
- import gf from "@/assets/windimgs/fanSvg/gf.png";
- //故障
- import gz from "@/assets/windimgs/fanSvg/gz.svg";
- //待机
- import dj from "@/assets/windimgs/fanSvg/dj.svg";
- //检修
- import jx from "@/assets/windimgs/fanSvg/jx.svg";
- //限电
- import xd from "@/assets/windimgs/fanSvg/xd.svg";
- //离线
- import lx from "@/assets/windimgs/fanSvg/lx.svg";
- //受累
- import sl from "@/assets/windimgs/fanSvg/sl.svg";
- //动图使用柱子和扇叶
- import bwzhu from "@/assets/windimgs/fanSvg/bwzhu.svg";
- import bwshan from "@/assets/windimgs/fanSvg/bwshan.png";
- import benchmark from "@/assets/cesiumImg/benchmark.png";
- import windHome from "@/components/windHome/index.vue";
- import windPro from "@/components/windProDetail/windProblem.vue";
- import ModelUnpack from "@/components/modelUnpack.vue";
- import { WindLayer } from "cesium-wind";
- import windGridData from "./windGridData.json";
- // import AdvancedBillboardGenerator from "@/tools/lightsign.js";
- // import { useWebSocket } from "@/tools/websocket.js";
- import webSocketService from "@/tools/ws.js";
- export default {
- name: "windMap2D",
- components: {
- comModelDialog,
- windView,
- menuCom,
- windHome,
- windPro,
- ModelUnpack,
- windView2
- },
- data() {
- return {
- loading: true,
- benchmark,
- showAllWindFromStation: [],
- restLatLon: [
- {
- longitude: 114.48789,
- latitude: 35.32916,
- name: "MYFDC",
- },
- {
- longitude: 112.88355172,
- latitude: 40.46617836,
- name: "JNWHZ",
- },
- {
- longitude: 112.5270545,
- latitude: 40.35920334,
- name: "JNYPL",
- },
- {
- longitude: 112.69922452,
- latitude: 40.31857399,
- name: "JNSMS",
- },
- ],
- fjLonLatJsonArr: [],
- viewer: null,
- windLayer: null, // 风场图
- windLayerTimmer: null, // 风场图计时器
- cloudImagesLayer: [], // 卫星云图
- cloudLayer: null, // 卫星云图
- cloudintervalId: null,
- rainImagesLayer: [], // 降雨图
- rainLayer: null, // 降雨图
- rainintervalId: null, // 降雨图
- tempImagesLayer: [], //温度图
- temperatureLayer: null, //温度图
- tempintervalId: null, //温度图
- showcomModelDia: false,
- currentHeight: 0,
- modelVal: null,
- menuComTStyB: false,
- modelUnpackType: "fengji",
- windDrawer: false,
- windDrawerTitle: "",
- windDrawerHeader: "",
- showBasicMsg: false,
- showVideoMsg: false,
- showProblemMsg: false,
- showModelMsg: false,
- showWindDetail: true,
- allStationentitys: [],
- allWindEntitys: [],
- urlTiles: "/public/static/tiles/{z}/{x}/{y}.jpg",
- zbLabelList: [],
- isFakeData: false,
- fakeDataTimmer: null,
- };
- },
- mounted() {
- this.initCesium();
- setTimeout(() => {
- this.loading = false;
- }, 1000);
- },
- unmounted() {
- clearInterval(this.fakeDataTimmer);
- this.fakeDataTimmer = null;
- },
- methods: {
- async initCesium() {
- const box = document.getElementById("cesiumContainer");
- const viewer = new Cesium.Viewer(box, {
- geocoder: false, // 地址搜索控件
- homeButton: false, // 返回地图初始位置控件
- infoBox: false, // 地图默认的信息控件
- sceneModePicker: false, // 场景模式切换控件
- baseLayerPicker: false, // 底图切换控件
- navigationHelpButton: false, // 帮助控件
- animation: false, // 动画控制控件
- timeline: false, // 时间线控件
- fullscreenButton: false, // 全屏按钮控件
- // imageryProvider: true, // 是否显示 Cesium 默认地图的底图
- vrButton: false,
- selectionIndicator: false,
- shouldAnimate: true,
- });
- const imageryProvider = new Cesium.UrlTemplateImageryProvider({
- // minimumLevel: 11,
- maximumLevel: 18,
- // url: this.urlTiles,
- url:
- import.meta.env.VITE_APP_ENV_NAME === "dev"
- ? "https://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}"
- : "/static/ditu/{z}/{x}/{y}.png",
- credit: "影像地图",
- });
- imageryProvider.alpha = 0.55; // 透明度
- imageryProvider.brightness = 1; // 亮度
- imageryProvider.contrast = 1; // 对比度
- viewer.imageryLayers.addImageryProvider(imageryProvider);
- viewer._cesiumWidget._creditContainer.style.display = "none";
- // this.csceneElliposid(viewer)
- this.viewer = viewer;
- // 展示场站
- // this.showAllStation(viewer)
- // 展示风机
- this.showWindFromStation(viewer);
- this.initGeoJsonData();
- },
- // 初始化 geoJson 数据
- async initGeoJsonData() {
- // 创建GeoJSON数据源
- await new Cesium.GeoJsonDataSource.load(basicGeoJson, {
- stroke: Cesium.Color.GRAY, // 边界线颜色
- fill: Cesium.Color.BLACK.withAlpha(0), // 填充颜色
- strokeWidth: 1, // 边界线宽度
- markerSymbol: "?", // 点要素的符号
- clampToGround: true, // 贴地
- }).then((dataSource) => {
- // 添加到视图
- this.viewer.dataSources.add(dataSource);
- var entities = dataSource.entities.values;
- for (let i = 0; i < entities.length; i++) {
- let entity = entities[i];
- entity.polygon.hierarchy.getValue(Cesium.JulianDate.now()).positions;
- //单独设置线条样式
- var positions = entity.polygon.hierarchy._value.positions;
- entity.polyline = {
- positions: positions,
- width: 1,
- outline: false,
- };
- }
- // 添加中文标签图层
- const labelLayer = new Cesium.LabelCollection();
- this.viewer.scene.primitives.add(labelLayer);
- const cities = [];
- basicGeoJson?.features?.forEach((ele) => {
- if (Array.isArray(ele.properties.centroid)) {
- const name = ele.properties.name;
- const lon = ele.properties.centroid[0];
- const lat = ele.properties.centroid[1];
- cities.push({ name, lon, lat });
- }
- });
- cities.forEach((city, index) => {
- labelLayer.add({
- id: index,
- name: "cityLabel",
- position: Cesium.Cartesian3.fromDegrees(city.lon, city.lat, 10),
- text: city.name,
- font: 'bold 14px "Microsoft YaHei", sans-serif',
- fillColor: Cesium.Color.fromCssColorString("#000"),
- outlineColor: Cesium.Color.WHITE,
- outlineWidth: 2,
- style: Cesium.LabelStyle.FILL_AND_OUTLINE,
- pixelOffset: new Cesium.Cartesian2(0, 0), // 设置为0
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // 水平居中
- verticalOrigin: Cesium.VerticalOrigin.CENTER, // 垂直居中
- });
- });
- });
- },
- backStations() {
- this.showWindDetail = false;
- this.allWindEntitys.forEach(({ entity, handler }) => {
- this.viewer.entities.remove(entity); // 移除实体
- if (!handler.isDestroyed()) {
- handler.destroy(); // 销毁事件处理器(关键!)
- }
- });
- this.allWindEntitys = [];
- if (this.viewer && this.viewer.destroy) {
- this.viewer.destroy();
- this.viewer = null;
- }
- // this.initCesium();
- // this.showAllStation(this.viewer)
- },
- resetChangeWind(data) {
- let that = this;
- that.viewer.camera.flyTo({
- destination: Cesium.Cartesian3.fromDegrees(
- data.longitude,
- data.latitude,
- 1000
- ),
- orientation: {
- heading: Cesium.Math.toRadians(0),
- pitch: Cesium.Math.toRadians(-90),
- roll: 0.0,
- },
- duration: 3.0,
- });
- },
- // 展示所有风场
- showAllStation(viewer) {
- allStationJson.station.forEach((e, index) => {
- if (e.energytype === "Wind") {
- this.showStationFn(viewer, e, index, fc);
- } else if (e.energytype === "Fire") {
- this.showStationFn(viewer, e, index, hd);
- } else {
- this.showStationFn(viewer, e, index, gf);
- }
- });
- this.resetAllStationViewport();
- },
- // 根据状态展示不同颜色风机贴图
- showStationFn(viewer, e, index, images) {
- const position = Cesium.Cartesian3.fromDegrees(e.longitude, e.latitude);
- const entity = viewer.entities.add({
- id: index,
- position, // 模型位置
- billboard: {
- image: images, // 也可以是 SVG 路径,如 'icon.svg'
- scale: 0.5,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- // 模型贴地
- heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
- },
- label: {
- text: e.plantname,
- font: "14px sans-serif",
- fillColor: Cesium.Color.fromBytes(255, 255, 255),
- heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
- },
- });
- let that = this;
- const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
- handler.setInputAction(function (movement) {
- var position = movement.position;
- var pickedObject = viewer.scene.pick(position);
- if (pickedObject && pickedObject.id.id === index) {
- console.log("你点击了标签或模型!", entity);
- console.log("选中风场或新能源场", e.plantname);
- that.showWindDetail = true;
- that.allStationentitys.forEach(({ entity, handler }) => {
- viewer.entities.remove(entity); // 移除实体
- if (!handler.isDestroyed()) {
- handler.destroy(); // 销毁事件处理器(关键!)
- }
- });
- that.allStationentitys = [];
- that.showWindFromStation(viewer);
- }
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
- that.allStationentitys.push({ entity, handler });
- },
- // 展示所选风场的风机
- showWindFromStation(viewer) {
- let stationName = this.$route.query.nameEn;
- let fjLonLatJson = [];
- this.fjLonLatJsonArr = [];
- let url = "";
- // 旺海庄:DHWH 苏木山:DHSM 营盘梁:DHYP 迈越:HZMY
- // if (stationName === "MYFDC") {
- // fjLonLatJson = fjMYLonLatJson;
- // url = "ws://10.121.128.117:8431/ws/HZMY";
- // } else if (stationName === "JNWHZ") {
- // fjLonLatJson = fjWHZLonLatJson;
- // url = "ws://10.121.128.117:8431/ws/DHWH";
- // } else if (stationName === "JNYPL") {
- // fjLonLatJson = fjYPLLonLatJson;
- // url = "ws://10.121.128.117:8431/ws/DHYP";
- // } else if (stationName === "JNSMS") {
- // fjLonLatJson = fjSMSLonLatJson;
- // url = "ws://10.121.128.117:8431/ws/DHSM";
- // }
- webSocketService.connect({
- url: `ws/${this.getWsUrl(stationName)}`,
- autoReconnect: true,
- maxReconnectAttempts: 5,
- reconnectInterval: 3000,
- onOpen: (event) => {
- console.log("✅ WebSocket 连接成功", event);
- },
- onError: (error) => {
- console.log("❌ WebSocket 错误:", error);
- return
- if (stationName === "MYFDC") {
- fjLonLatJson = JSON.parse(JSON.stringify(fjMYLonLatJson));
- } else if (stationName === "JNWHZ") {
- fjLonLatJson = JSON.parse(JSON.stringify(fjWHZLonLatJson));
- } else if (stationName === "JNYPL") {
- fjLonLatJson = JSON.parse(JSON.stringify(fjYPLLonLatJson));
- } else if (stationName === "JNSMS") {
- fjLonLatJson = JSON.parse(JSON.stringify(fjSMSLonLatJson));
- }
- let wtArray = JSON.parse(JSON.stringify(wsRes.windMachineList));
- this.isFakeData = true;
- this.fakeDataTimmer = setInterval(() => {
- fjLonLatJson.data.forEach((e) => {
- let fjItem =
- wtArray.find((findEle) => {
- return findEle.fjbh === e.fjbh;
- }) || {};
- const fjMix = Object.assign({}, e, fjItem);
- fjMix.status = this.getStatus(fjMix.fjzt);
- e = fjMix;
- if (e.status) {
- if (e.status === 1) {
- this.showStatuswind(viewer, e, dj);
- } else if (e.status === 2) {
- this.showStatuswind(viewer, e, gz);
- } else if (e.status === 3) {
- this.showStatuswind(viewer, e, jx);
- } else if (e.status === 4) {
- this.showStatuswind(viewer, e, xd);
- } else if (e.status === 5) {
- this.showStatuswind(viewer, e, lx);
- } else if (e.status === 6) {
- this.showStatuswind(viewer, e, sl);
- } else {
- //并网风机
- this.showAnimatewind(viewer, e);
- }
- }
- this.changeZb(fjMix);
- });
- this.fjLonLatJsonArr = fjLonLatJson;
- }, 1000);
- },
- });
- webSocketService.on("message", (res) => {
- if (stationName === "MYFDC") {
- fjLonLatJson = JSON.parse(JSON.stringify(fjMYLonLatJson));
- } else if (stationName === "JNWHZ") {
- fjLonLatJson = JSON.parse(JSON.stringify(fjWHZLonLatJson));
- } else if (stationName === "JNYPL") {
- fjLonLatJson = JSON.parse(JSON.stringify(fjYPLLonLatJson));
- } else if (stationName === "JNSMS") {
- fjLonLatJson = JSON.parse(JSON.stringify(fjSMSLonLatJson));
- }
- let wtArray = JSON.parse(JSON.stringify(res.windMachineList));
- fjLonLatJson.data.forEach((e) => {
- let fjItem =
- wtArray.find((findEle) => {
- return findEle.fjbh === e.fjbh;
- }) || {};
- const fjMix = Object.assign({}, e, fjItem);
- fjMix.status = this.getStatus(fjMix.fjzt);
- e = fjMix;
- if (e.status) {
- if (e.status === 1) {
- this.showStatuswind(viewer, e, dj);
- } else if (e.status === 2) {
- this.showStatuswind(viewer, e, gz);
- } else if (e.status === 3) {
- this.showStatuswind(viewer, e, jx);
- } else if (e.status === 4) {
- this.showStatuswind(viewer, e, xd);
- } else if (e.status === 5) {
- this.showStatuswind(viewer, e, lx);
- } else if (e.status === 6) {
- this.showStatuswind(viewer, e, sl);
- } else {
- //并网风机
- this.showAnimatewind(viewer, e);
- }
- }
- this.changeZb(fjMix);
- });
- this.fjLonLatJsonArr = fjLonLatJson;
- });
- // const ws = useWebSocket(url);
- // let wtArray = ws.messages.windMachineList;
- // this.fjLonLatJsonArr = fjLonLatJson;
- this.resetWindViewport();
- },
- getWsUrl(stationName) {
- let wsurl = "";
- if (stationName === "MYFDC") {
- wsurl = "HZMY";
- } else if (stationName === "JNWHZ") {
- wsurl = "DHWH";
- } else if (stationName === "JNYPL") {
- wsurl = "DHYP";
- } else if (stationName === "JNSMS") {
- wsurl = "DHSM";
- }
- return wsurl;
- },
- getStatus(sName) {
- let status = 0;
- if (/待机/.test(sName)) {
- status = 1;
- } else if (/故障/.test(sName)) {
- status = 2;
- } else if (/检修/.test(sName)) {
- status = 3;
- } else if (/限电/.test(sName)) {
- status = 4;
- } else if (/离线/.test(sName)) {
- status = 5;
- } else if (/受累/.test(sName)) {
- status = 6;
- } else if (/并网/.test(sName)) {
- status = 7;
- }
- return status;
- },
- // 根据状态展示不同颜色风机贴图
- showStatuswind(viewer, e, type, index) {
- this.addSvg(
- viewer,
- type,
- e.longitude,
- e.latitude,
- e,
- Math.random().toFixed(4) * 10000
- );
- },
- // 风机柱与扇叶分开展示转动效果贴图
- showAnimatewind(viewer, e, index) {
- this.addSvgs(
- viewer,
- bwshan,
- e.longitude,
- e.latitude,
- e,
- Math.random().toFixed(3) * 1000
- );
- this.addSvg(
- viewer,
- bwzhu,
- e.longitude,
- e.latitude,
- e,
- Math.random().toFixed(3) * 2000
- );
- },
- //添加svg或png贴图
- addSvg(viewer, uri, lon, lat, val, index) {
- let that = this;
- const findRes =
- that.zbLabelList.find((findEle) => {
- return findEle.fjbh === val.fjbh;
- }) || null;
- if (!findRes) {
- let ids = that.generateUniqueId(val.id);
- const position = Cesium.Cartesian3.fromDegrees(lon, lat);
- // 使用高级灯牌生成器
- // const advancedGenerator = new AdvancedBillboardGenerator();
- // let statusItems = [
- // {
- // label: "功率",
- // value: `${
- // this.isFakeData
- // ? this.randomNum(100, 1000)
- // : val.actualPower.toFixed(2)
- // }MW`,
- // },
- // {
- // label: "风速",
- // value: `${
- // this.isFakeData
- // ? this.randomNum(100, 1000)
- // : val.windSpeed.toFixed(1)
- // }m/s`,
- // },
- // {
- // label: "转速",
- // value: `${
- // this.isFakeData
- // ? this.randomNum(100, 1000)
- // : val.rotateSpeed.toFixed(1)
- // }p`,
- // },
- // // { label: "其他参数A", value: "...." },
- // // { label: "其他参数B", value: "...." },
- // // { label: "其他参数C", value: "...." },
- // // { label: "其他参数D", value: "...." },
- // // { label: "其他参数E", value: "...." },
- // // { label: "其他参数F", value: "...." },
- // ];
- // const billboardImage = advancedGenerator.generateAdvancedBillboard({
- // title: val.fjbh,
- // statusItems,
- // // borderGradient: ["#00e5ff", "#2979ff"],
- // borderGradient: ["#ccc", "#ccc"],
- // backgroundColor: "transparent",
- // padding: 6,
- // titleHeight: 22,
- // itemHeight: 17,
- // titleColor: "#1890ff",
- // titleStrokeStyle: "#000",
- // titleStrokeWidth: 1,
- // labelStrokeStyle: "#000",
- // labelStrokeWidth: 1,
- // valueStrokeStyle: "#000",
- // valueStrokeWidth: 1,
- // });
- // const entityxy = viewer.entities.add({
- // name: val.name,
- // position,
- // billboard: {
- // image: billboardImage,
- // scale: 1,
- // verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // 原来已经是CENTER,现在改为BOTTOM
- // pixelOffset: new Cesium.Cartesian2(80, -50), // 原来是-20,现在改为30,向上移动
- // eyeOffset: new Cesium.Cartesian3(0, 0, 0), // 保持固定大小
- // // heightReference: Cesium.HeightReference.NONE,
- // // 近大远小
- // scaleByDistance: new Cesium.NearFarScalar(
- // 6000, // 5010米内
- // 1.2, // 1倍大小
- // 9000, // 10000米外
- // 1 // 0.1倍大小
- // ),
- // // 透明度渐变
- // // translucencyByDistance: new Cesium.NearFarScalar(
- // // 6000, // 500米内
- // // 1.0, // 完全不透明
- // // 9000, // 3000米外
- // // 0.5 // 完全透明
- // // ),
- // },
- // });
- const btn = document.getElementById("windBtn");
- btn.addEventListener("click", function (event) {
- entityxy.show = !entityxy.show;
- });
- if (val.bgFj === "1") {
- const benchmark = viewer.entities.add({
- position,
- billboard: {
- image: that.benchmark,
- scale: 0.8,
- pixelOffset: new Cesium.Cartesian2(50, -25),
- }, // 偏移避免重叠
- });
- }
- const entity = viewer.entities.add({
- id: ids,
- position, // 模型位置
- billboard: {
- image: uri, // 也可以是 SVG 路径,如 'icon.svg'
- scale: 0.5,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- // 模型贴地
- // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
- },
- label: {
- // text: val.name ? val.name : val.plantname,
- text: val.fjbh,
- font: "14px sans-serif",
- fillColor: Cesium.Color.fromBytes(255, 255, 255),
- },
- });
- // 创建事件处理器
- const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
- handler.setInputAction(function (movement) {
- var position = movement.position;
- var pickedObject = viewer.scene.pick(position);
- if (pickedObject && pickedObject.id.id === ids) {
- console.log("你点击了标签或模型!", entity);
- console.log("标签或模型数据!", val);
- that.modelVal = val;
- // 找到实体,显示包含实体信息的弹框
- that.showRightClickPopup(position, val);
- return;
- }
- }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
- this.allWindEntitys.push({ entity, handler });
- }
- },
- changeZb(model) {
- const glText = this.isFakeData
- ? this.randomNum(100, 1000)
- : model.actualPower.toFixed(2);
- const fsText = this.isFakeData
- ? this.randomNum(100, 1000)
- : model.rotateSpeed.toFixed(2);
- const zsText = this.isFakeData
- ? this.randomNum(100, 1000)
- : model.windSpeed.toFixed(2);
- const zbMap = {
- glText: `${glText} MW`,
- fsText: `${fsText} m/s`,
- zsText: `${zsText} p`,
- };
- const position = Cesium.Cartesian3.fromDegrees(
- model.longitude,
- model.latitude,
- 0
- );
- const zbhj =
- this.zbLabelList.find((ele) => {
- return ele.fjbh === model.fjbh;
- }) || null;
- if (zbhj?.fjbh) {
- zbhj.zb.forEach((ele) => {
- if (ele.zb) {
- const spText = ele.label.text._value.split(": ");
- ele.label.text._value = `${spText[0]}: ${zbMap[ele.zb]}`;
- }
- });
- } else {
- const wtName = this.viewer.entities.add({
- position,
- label: {
- text: model.fjbh,
- font: "14pt sans-serif",
- fillColor: new Cesium.Color.fromCssColorString("#4fc3f7"), // 填充颜色
- outlineColor: Cesium.Color.BLACK, // 轮廓颜色
- style: Cesium.LabelStyle.FILL_AND_OUTLINE,
- outlineWidth: 2,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- showBackground: false, // 显示背景
- backgroundColor: new Cesium.Color.fromCssColorString(
- "rgba(13, 38, 77, 0.5)"
- ), // 背景颜色
- backgroundPadding: new Cesium.Cartesian2(10, 10), // 背景内边距
- verticalOrigin: Cesium.VerticalOrigin.CENTER, // 垂直对齐方式
- horizontalOrigin: Cesium.HorizontalOrigin.LEFT, // 水平对齐方式
- pixelOffset: new Cesium.Cartesian2(80, -60), // 原来是-20,现在改为30,向上移动
- eyeOffset: new Cesium.Cartesian3(0, 0, 0), // 保持固定大小
- heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
- scaleByDistance: new Cesium.NearFarScalar(
- 6000, // 6000米内
- 1,
- 9000, // 9000米外
- 0.8
- ),
- },
- });
- const glZb = this.viewer.entities.add({
- position,
- label: {
- text: `功率: ${glText} MW`,
- font: "14pt sans-serif",
- style: Cesium.LabelStyle.FILL_AND_OUTLINE,
- outlineWidth: 2,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- showBackground: false, // 显示背景
- backgroundColor: new Cesium.Color.fromCssColorString(
- "rgba(13, 38, 77, 0.5)"
- ), // 背景颜色
- backgroundPadding: new Cesium.Cartesian2(10, 10), // 背景内边距
- verticalOrigin: Cesium.VerticalOrigin.CENTER, // 垂直对齐方式
- horizontalOrigin: Cesium.HorizontalOrigin.LEFT, // 水平对齐方式
- pixelOffset: new Cesium.Cartesian2(80, -40), // 原来是-20,现在改为30,向上移动
- eyeOffset: new Cesium.Cartesian3(0, 0, 0), // 保持固定大小
- heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
- scaleByDistance: new Cesium.NearFarScalar(
- 6000, // 6000米内
- 1,
- 9000, // 9000米外
- 0.8
- ),
- },
- });
- glZb.zb = "glText";
- const fsZb = this.viewer.entities.add({
- position,
- label: {
- text: `风速: ${fsText}`,
- font: "14pt sans-serif",
- style: Cesium.LabelStyle.FILL_AND_OUTLINE,
- outlineWidth: 2,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- showBackground: false, // 显示背景
- backgroundColor: new Cesium.Color.fromCssColorString(
- "rgba(13, 38, 77, 0.5)"
- ), // 背景颜色
- backgroundPadding: new Cesium.Cartesian2(10, 10), // 背景内边距
- verticalOrigin: Cesium.VerticalOrigin.CENTER, // 垂直对齐方式
- horizontalOrigin: Cesium.HorizontalOrigin.LEFT, // 水平对齐方式
- pixelOffset: new Cesium.Cartesian2(80, -20), // 原来是-20,现在改为30,向上移动
- eyeOffset: new Cesium.Cartesian3(0, 0, 0), // 保持固定大小
- heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
- scaleByDistance: new Cesium.NearFarScalar(
- 6000, // 6000米内
- 1,
- 9000, // 9000米外
- 0.8
- ),
- },
- });
- fsZb.zb = "fsText";
- const zsZb = this.viewer.entities.add({
- position,
- label: {
- text: `转速: ${zsText}`,
- font: "14pt sans-serif",
- style: Cesium.LabelStyle.FILL_AND_OUTLINE,
- outlineWidth: 2,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- showBackground: false, // 显示背景
- backgroundColor: new Cesium.Color.fromCssColorString(
- "rgba(13, 38, 77, 0.5)"
- ), // 背景颜色
- backgroundPadding: new Cesium.Cartesian2(10, 10), // 背景内边距
- verticalOrigin: Cesium.VerticalOrigin.CENTER, // 垂直对齐方式
- horizontalOrigin: Cesium.HorizontalOrigin.LEFT, // 水平对齐方式
- pixelOffset: new Cesium.Cartesian2(80, 0), // 原来是-20,现在改为30,向上移动
- eyeOffset: new Cesium.Cartesian3(0, 0, 0), // 保持固定大小
- heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
- scaleByDistance: new Cesium.NearFarScalar(
- 6000, // 6000米内
- 1,
- 9000, // 9000米外
- 0.8
- ),
- },
- });
- zsZb.zb = "zsText";
- this.zbLabelList.push({
- fjbh: model.fjbh,
- zb: [wtName, glZb, fsZb, zsZb],
- });
- }
- },
- randomNum(minNum, maxNum) {
- switch (arguments.length) {
- case 1:
- return parseInt(Math.random() * minNum + 1, 10);
- case 2:
- return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
- default:
- return 0;
- }
- },
- //添加svg或png贴图
- addSvgs(viewer, uri, lon, lat, val, index) {
- let that = this;
- let ids = that.generateUniqueId(val.id);
- const position = Cesium.Cartesian3.fromDegrees(lon, lat);
- const entity = viewer.entities.add({
- id: ids,
- position, // 模型位置
- billboard: {
- image: uri, // 也可以是 SVG 路径,如 'icon.svg'
- scale: 0.5,
- pixelOffset: new Cesium.Cartesian2(0, -15),
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- // 模型贴地
- // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
- // 核心:使用 CallbackProperty 实现旋转动画
- rotation: new Cesium.CallbackProperty(function (time) {
- // 每 3 秒转一圈(可调速度)
- const seconds = time.secondsOfDay;
- const angle = Cesium.Math.toRadians(((seconds % 3) * -360) / 3); // 每3秒一圈
- return angle;
- }, false),
- // 确保绕中心旋转
- rotationAlignment: Cesium.HeightReference.CENTER,
- alignedAxis: Cesium.Cartesian3.UNIT_Z,
- },
- });
- // 创建事件处理器
- const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
- handler.setInputAction(function (movement) {
- var position = movement.position;
- var pickedObject = viewer.scene.pick(position);
- if (pickedObject && pickedObject.id.id === ids) {
- console.log("你点击了标签或模型!", entity);
- console.log("标签或模型数据!", val);
- that.modelVal = val;
- // 找到实体,显示包含实体信息的弹框
- that.showRightClickPopup(position, val);
- return;
- }
- }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
- this.allWindEntitys.push({ entity, handler });
- },
- // 右键展示元素
- showRightClickPopup(screenPosition, val) {
- // 创建或获取弹框元素
- var popup = document.getElementById("rightClickPopup");
- if (!popup) {
- popup = document.createElement("div");
- popup.id = "rightClickPopup";
- popup.style.position = "absolute";
- // popup.style.backgroundColor = 'white';
- popup.style.border = "1px solid rgba(255, 255, 255, 0.2)";
- popup.style.borderRadius = "4px";
- popup.style.padding = "10px";
- popup.style.boxShadow = "0 2px 10px rgba(0,0,0,0.2)";
- popup.style.backdropFilter = `blur(10px)`;
- popup.style.zIndex = "1000";
- popup.style.pointerEvents = "auto"; // 确保弹框可交互
- // 添加一个最小宽度,避免内容过短
- popup.style.minWidth = "100px";
- // 可选:添加箭头指向点击点
- // 这需要更复杂的 CSS 或额外的 DOM 元素
- document.body.appendChild(popup);
- }
- // <span class="popup-menu-item" data-message-type="model" style="cursor:pointer">模型解构</span>
- let content = `
- <div style="display: flex;gap: 10px;flex-direction: column;text-align: center;color: #fff">
- <span class="popup-menu-item" data-message-type="basic" style="cursor:pointer">基本信息</span>
- <span class="popup-menu-item" data-message-type="video" style="cursor:pointer">视频监控</span>
- <span class="popup-menu-item" data-message-type="problem" style="cursor:pointer">故障详情</span>
- </div>
- `;
- // 设置弹框内容
- popup.innerHTML = content;
- // --- 关键修正:准确计算弹框位置 ---
- // 1. 获取 Cesium 画布 (Canvas) 相对于视口 (viewport) 的位置
- var canvas = this.viewer.scene.canvas;
- var canvasRect = canvas.getBoundingClientRect();
- // console.log('Canvas Rect:', canvasRect); // 调试用
- // 2. 计算弹框左上角在页面中的绝对 X 坐标
- // screenPosition.x 是相对于画布左上角的 X 偏移
- // canvasRect.left 是画布左上角相对于浏览器视口左上角的 X 偏移
- // window.pageXOffset 是页面水平滚动的距离
- var popupLeft = canvasRect.left + screenPosition.x + window.pageXOffset;
- // 3. 计算弹框左上角在页面中的绝对 Y 坐标
- var popupTop = canvasRect.top + screenPosition.y + window.pageYOffset;
- // --- 可选:添加偏移量,避免完全覆盖鼠标指针 ---
- // 例如,向下和向右偏移 10px
- var offsetX = 10;
- var offsetY = 10;
- popupLeft += offsetX;
- popupTop += offsetY;
- // --- 可选:边界检查,防止弹框超出屏幕 ---
- var popupWidth = popup.offsetWidth || 150; // 确保有宽度
- var popupHeight = popup.offsetHeight || 50; // 确保有高度
- var windowWidth = window.innerWidth;
- var windowHeight = window.innerHeight;
- // 如果弹框右边会超出窗口,则左移
- if (popupLeft + popupWidth > windowWidth) {
- popupLeft = windowWidth - popupWidth - 10; // 靠右留 10px 边距
- }
- // 如果弹框底边会超出窗口,则上移
- if (popupTop + popupHeight > windowHeight) {
- popupTop = windowHeight - popupHeight - 10; // 靠下留 10px 边距
- }
- // 如果左边超出 (不太可能,但安全起见)
- if (popupLeft < 0) popupLeft = 10;
- // 如果顶边超出
- if (popupTop < 0) popupTop = 10;
- // --- 设置最终位置 ---
- popup.style.left = popupLeft + "px";
- popup.style.top = popupTop + "px";
- // console.log('Popup Position:', { left: popupLeft, top: popupTop }); // 调试用
- // 显示弹框
- popup.style.display = "block";
- // --- 隐藏弹框的逻辑 (保持不变) ---
- function hidePopup(event) {
- // 检查点击是否发生在弹框内部,如果是,则不隐藏
- if (event && popup.contains(event.target)) {
- return;
- }
- popup.style.display = "none";
- document.removeEventListener("click", hidePopup);
- document.removeEventListener("keydown", keyDownHandler);
- }
- function keyDownHandler(event) {
- if (event.key === "Escape") {
- hidePopup();
- }
- }
- let that = this;
- that.showBasicMsg = false;
- that.showVideoMsg = false;
- that.showProblemMsg = false;
- that.showModelMsg = false;
- function popupMenuItemClick(event) {
- // 检查点击的是否是菜单项
- if (event.target.classList.contains("popup-menu-item")) {
- event.stopPropagation(); // 阻止冒泡,防止弹框立即关闭
- var messageType = event.target.dataset.messageType; // 获取 data-message-type
- console.log("点击了菜单项:", messageType);
- // 调用您的 showMessage 函数
- that.showMessage(messageType, val);
- hidePopup();
- // 可选:执行后关闭弹框
- // hideRightClickPopup();
- }
- }
- // 移除旧的监听器(避免重复绑定)
- document.removeEventListener("click", hidePopup);
- document.removeEventListener("click", popupMenuItemClick);
- document.removeEventListener("keydown", keyDownHandler);
- // 添加新的监听器
- document.addEventListener("click", hidePopup);
- document.addEventListener("click", popupMenuItemClick);
- document.addEventListener("keydown", keyDownHandler);
- },
- showMessage(type, val) {
- console.log("type===>>>", type);
- this.windDrawer = true;
- this.windDrawerHeader = val.fjbh + "数据详情";
- if (type === "basic") {
- this.windDrawerTitle = "基础信息";
- this.showBasicMsg = true;
- } else if (type === "video") {
- this.windDrawerTitle = "视频监控";
- this.showVideoMsg = true;
- } else if (type === "problem") {
- this.windDrawerTitle = "故障查看";
- this.showProblemMsg = true;
- }
- // else {
- // this.windDrawerTitle = '模型解构'
- // this.showModelMsg = true
- // }
- },
- showwindmodel() {
- this.windDrawer = true;
- this.showBasicMsg = false;
- this.showVideoMsg = false;
- this.showProblemMsg = false;
- this.windDrawerHeader = "风机模型可视化解构说明";
- this.showModelMsg = true;
- },
- handleClose() {
- this.windDrawer = false;
- this.showBasicMsg = false;
- this.showVideoMsg = false;
- this.showProblemMsg = false;
- this.showModelMsg = false;
- },
- showComDia(val) {
- this.showcomModelDia = val;
- this.modelVal = null;
- },
- csceneElliposid(viewer) {
- let that = this;
- // 获取 scene 和 ellipsoid
- var scene = viewer.scene;
- var labels = viewer.scene.primitives.add(new Cesium.LabelCollection());
- // 创建 ScreenSpaceEventHandler
- var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
- // 监听左键点击事件
- handler.setInputAction(async (click) => {
- // 获取点击位置的笛卡尔坐标
- var position = click.position;
- if (!position) return;
- // 使用 globe.pick 获取包含地形高度的坐标
- var ray = viewer.camera.getPickRay(position);
- var cartesian = viewer.scene.globe.pick(ray, viewer.scene);
- if (cartesian) {
- // 转换为地理坐标
- var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
- var longitude = Cesium.Math.toDegrees(cartographic.longitude);
- var latitude = Cesium.Math.toDegrees(cartographic.latitude);
- var height = cartographic.height;
- // 格式化坐标
- var text = `经度: ${longitude.toFixed(6)}°\n纬度: ${latitude.toFixed(
- 6
- )}°`;
- // 创建一个标签
- var label = labels.add({
- position: cartesian,
- text: text,
- font: "14px monospace",
- fillColor: Cesium.Color.fromCssColorString("#1d70df"),
- // style: Cesium.LabelStyle.FILL_AND_OUTLINE,
- // outlineColor: Cesium.Color.BLACK,
- outlineWidth: 2,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // 标签在点的上方
- pixelOffset: new Cesium.Cartesian2(0, -20), // 向上偏移一点
- disableDepthTest: true, // 让标签始终可见(即使在地球背面)
- scale: 0.8,
- });
- // 5秒后移除标签
- setTimeout(function () {
- labels.remove(label);
- }, 5000);
- console.log(
- `点击坐标: ${longitude.toFixed(6)}, ${latitude.toFixed(
- 6
- )}, ${height.toFixed(2)}m`
- );
- }
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
- },
- generateUniqueId(prefix = "id") {
- let idCounter = 0;
- return `${prefix}-${Date.now()}-${Math.random()
- .toString(36)
- .substr(2, 9)}-${idCounter++}`;
- },
- handleInitView() {
- if (this.showWindDetail) {
- this.resetWindViewport();
- } else {
- this.resetAllStationViewport();
- }
- },
- // 重置所有风场视角
- resetAllStationViewport() {
- this.viewer.camera.flyTo({
- destination: Cesium.Cartesian3.fromDegrees(
- 114.502778,
- 35.326667,
- 3000000
- ),
- orientation: {
- heading: Cesium.Math.toRadians(0),
- pitch: Cesium.Math.toRadians(-90),
- roll: 0.0,
- },
- duration: 3.0,
- });
- },
- // 重置风场中所有风机视角
- resetWindViewport() {
- let fromLon = this.$route.query.longitude * 1;
- let fromLat = this.$route.query.latitude * 1;
- let fromheight = this.$route.query.height * 1;
- let fromname = this.$route.query.nameEn;
- let targetLon = null;
- let targetLat = null;
- this.restLatLon.forEach((it) => {
- if (it.name === fromname) {
- targetLon = it.longitude;
- targetLat = it.latitude;
- }
- });
- // 设置镜头到指定的经纬度(度)、高度(米)
- this.viewer.camera.setView({
- destination: Cesium.Cartesian3.fromDegrees(
- fromLon, // 经度 (degrees)
- fromLat, // 纬度 (degrees)
- fromheight // 高度 (meters)
- ),
- orientation: {
- heading: Cesium.Math.toRadians(0.0), // 偏航角 (方向,0 指向北方)
- pitch: Cesium.Math.toRadians(-90.0), // 俯仰角 (-90 是垂直向下)
- roll: 0.0, // 翻滚角
- },
- });
- // 目标位置:经度、纬度、高度
- // const targetLon = 114.48789;
- // const targetLat = 35.32916;
- const targetHeight = 5000;
- const draggableHeightTolerance = 5000; // 允许拖拽的高度范围:20,000 ~ 30,000
- const minHeight = 5000; // 最低高度
- const maxHeight = 10000; // 最高高度
- const allowedOffsetDegrees = 0.2; // 允许拖拽的最大偏移(经纬度)
- const minLon = targetLon - allowedOffsetDegrees;
- const maxLon = targetLon + allowedOffsetDegrees;
- const minLat = targetLat - allowedOffsetDegrees;
- const maxLat = targetLat + allowedOffsetDegrees;
- let that = this;
- that.viewer.camera.flyTo({
- destination: Cesium.Cartesian3.fromDegrees(
- targetLon,
- targetLat,
- targetHeight
- ),
- orientation: {
- heading: Cesium.Math.toRadians(0),
- pitch: Cesium.Math.toRadians(-90),
- roll: 0.0,
- },
- duration: 3.0,
- complete: function () {
- console.log("飞入完成,启用拖拽限制逻辑");
- enableHeightBasedDragControl();
- },
- });
- // ===== 控制逻辑:根据高度决定是否允许拖拽 =====
- function enableHeightBasedDragControl() {
- that.viewer.scene.preUpdate.addEventListener(function (scene, time) {
- const camera = that.viewer.camera;
- const posCartographic = camera.positionCartographic;
- if (!posCartographic) return;
- const currentHeight = posCartographic.height;
- that.currentHeight = currentHeight;
- const currentLon = Cesium.Math.toDegrees(posCartographic.longitude);
- const currentLat = Cesium.Math.toDegrees(posCartographic.latitude);
- // === 第一步:限制相机高度不能超出 [10000, 100000] ===
- if (currentHeight < minHeight) {
- // 强制拉高到 minHeight,但保持当前水平视角
- const newPos = Cesium.Cartesian3.fromDegrees(
- currentLon,
- currentLat,
- minHeight
- );
- camera.setView({
- destination: newPos,
- orientation: {
- heading: camera.heading,
- pitch: camera.pitch,
- roll: camera.roll,
- },
- });
- return; // 避免后续逻辑冲突
- }
- if (currentHeight > maxHeight) {
- const newPos = Cesium.Cartesian3.fromDegrees(
- currentLon,
- currentLat,
- maxHeight
- );
- camera.setView({
- destination: newPos,
- orientation: {
- heading: camera.heading,
- pitch: camera.pitch,
- roll: camera.roll,
- },
- });
- return;
- }
- // if (currentHeight < (maxHeight-700000)) {
- // that.cancleAllLayer();
- // }
- // === 第二步:判断是否在“可拖拽高度区间” ===
- const isInDraggableRange =
- currentHeight >= targetHeight - draggableHeightTolerance &&
- currentHeight <= targetHeight + draggableHeightTolerance;
- if (isInDraggableRange) {
- // ✅ 允许拖拽,但限制在指定范围内
- const correctedLon = Cesium.Math.clamp(currentLon, minLon, maxLon);
- const correctedLat = Cesium.Math.clamp(currentLat, minLat, maxLat);
- if (
- Math.abs(correctedLon - currentLon) > 1e-8 ||
- Math.abs(correctedLat - currentLat) > 1e-8
- ) {
- // 越界了,纠正位置,保留当前高度和视角
- camera.setView({
- destination: Cesium.Cartesian3.fromDegrees(
- correctedLon,
- correctedLat,
- currentHeight
- ),
- orientation: {
- heading: camera.heading,
- pitch: camera.pitch,
- roll: camera.roll,
- },
- });
- }
- } else {
- // ❌ 不在可拖拽高度:禁止平移,强制回正到目标点
- const correctedPosition = Cesium.Cartesian3.fromDegrees(
- targetLon,
- targetLat,
- currentHeight // 保留当前缩放高度
- );
- camera.setView({
- destination: correctedPosition,
- orientation: {
- heading: camera.heading,
- pitch: camera.pitch,
- roll: camera.roll,
- },
- });
- }
- });
- }
- },
- coverOnChange(val) {
- if (val.value === "风场") {
- this.switchWindLayer(val.check);
- } else if (val.value === "云层") {
- this.switchCloudLayer(val.check);
- } else if (val.value === "降雨") {
- this.switchRainLayer(val.check);
- } else if (val.value === "温度") {
- this.switchTemperatureLayerr(val.check);
- }
- },
- // 提供控制函数以便在需要时停止循环
- stopCycling(intervalId) {
- if (intervalId) {
- clearInterval(intervalId);
- intervalId = null;
- console.log("循环已停止");
- }
- },
- // 切换风场图显隐
- switchWindLayer() {
- this.viewer.scene.screenSpaceCameraController.enableZoom = true;
- if (this.rainLayer || this.rainImagesLayer.length > 0) {
- this.removeRainLayer();
- this.stopCycling(this.rainintervalId);
- }
- if (this.cloudLayer || this.cloudImagesLayer.length > 0) {
- this.removeCloudLayer();
- this.stopCycling(this.cloudintervalId);
- }
- if (this.temperatureLayer || this.tempImagesLayer.length > 0) {
- this.removeTemperatureLayer();
- this.stopCycling(this.tempintervalId);
- }
- if (this.windLayer) {
- this.removeWindLayer();
- } else {
- this.showWindLayer();
- }
- },
- // 添加风场图
- async showWindLayer() {
- if (!this.windLayer) {
- this.windLayer = new WindLayer(windGridData, {
- particleSize: 2.0,
- particleOpacity: 0.6,
- particleSpeed: 0.01,
- maxVelocity: 25, // 风速最大值(用于颜色映射和速度缩放)
- minVelocity: 0, // 风速最小值阈值(低于此值不显示粒子)
- colorScale: [
- "rgb(36,104, 180)",
- "rgb(60,157, 194)",
- "rgb(128,205,193)",
- "rgb(151,218,168)",
- "rgb(198,231,181)",
- "rgb(238,247,217)",
- "rgb(255,238,159)",
- "rgb(252,217,125)",
- "rgb(255,182,100)",
- "rgb(252,150,75)",
- "rgb(250,112,52)",
- "rgb(245,64,32)",
- "rgb(237,45,28)",
- "rgb(220,24,32)",
- "rgb(180,0,35)",
- ], // 颜色强度缩放
- frameRate: 15,
- fadeOpacity: 0.995,
- particleAge: 150,
- maxAge: 60,
- globalAlpha: 0.8,
- velocityScale: 1 / 30, // 粒子移动速度缩放因子(控制动画快慢)
- paths: 500,
- lineWidth: 2,
- });
- this.windLayer.addTo(this.viewer);
- }
- },
- // 切换卫星云图显隐
- switchCloudLayer(val) {
- if (this.windLayer) {
- this.removeWindLayer();
- }
- if (this.rainLayer || this.rainImagesLayer.length > 0) {
- this.removeRainLayer();
- this.stopCycling(this.rainintervalId);
- }
- if (this.temperatureLayer || this.tempImagesLayer.length > 0) {
- this.removeTemperatureLayer();
- this.stopCycling(this.tempintervalId);
- }
- if (!val || this.cloudLayer || this.cloudImagesLayer.length > 0) {
- this.removeCloudLayer();
- this.stopCycling(this.cloudintervalId);
- } else {
- this.showCloudLayer();
- }
- },
- // 切换降雨图显隐
- switchRainLayer() {
- this.viewer.scene.screenSpaceCameraController.enableZoom = true;
- if (this.windLayer) {
- this.removeWindLayer();
- }
- if (this.cloudLayer || this.cloudImagesLayer.length > 0) {
- this.removeCloudLayer();
- this.stopCycling(this.cloudintervalId);
- }
- if (this.temperatureLayer || this.tempImagesLayer.length > 0) {
- this.removeTemperatureLayer();
- this.stopCycling(this.tempintervalId);
- }
- if (this.rainLayer || this.rainImagesLayer.length > 0) {
- this.removeRainLayer();
- this.stopCycling(this.rainintervalId);
- } else {
- this.showRainLayer();
- }
- },
- // 切换温度图显隐
- switchTemperatureLayerr() {
- this.viewer.scene.screenSpaceCameraController.enableZoom = true;
- if (this.windLayer) {
- this.removeWindLayer();
- }
- if (this.cloudLayer || this.cloudImagesLayer.length > 0) {
- this.removeCloudLayer();
- this.stopCycling(this.cloudintervalId);
- }
- if (this.rainLayer || this.rainImagesLayer.length > 0) {
- this.removeRainLayer();
- this.stopCycling(this.rainintervalId);
- }
- if (this.temperatureLayer || this.tempImagesLayer.length > 0) {
- this.removeTemperatureLayer();
- this.stopCycling(this.tempintervalId);
- } else {
- this.showTemperatureLayer();
- }
- },
- // 显示云图
- showCloudLayer() {
- const imageUrls = [];
- cloudJson.forEach((it) => {
- imageUrls.push("/public/static" + it.path);
- });
- this.showeveryTypeImagesLayer(
- imageUrls,
- this.cloudintervalId,
- this.cloudImagesLayer
- );
- },
- //显示降雨图
- showRainLayer() {
- const imageUrls = [];
- rainJson.forEach((it) => {
- imageUrls.push("/public/static" + it.path);
- });
- this.showeveryTypeImagesLayer(
- imageUrls,
- this.rainintervalId,
- this.rainImagesLayer
- );
- this.csceneElliposid(this.viewer, "rain");
- },
- //显示温度图
- showTemperatureLayer() {
- const imageUrls = [];
- tempJson.forEach((it) => {
- imageUrls.push("/public/static" + it.path);
- });
- this.showeveryTypeImagesLayer(
- imageUrls,
- this.tempintervalId,
- this.tempImagesLayer
- );
- this.csceneElliposid(this.viewer, "temp");
- },
- async showeveryTypeImagesLayer(imageUrls, intervalId, ImagesLayers) {
- // 存储所有图片图层的数组
- let imageLayers = [];
- // 当前显示的图片索引
- let currentImageIndex = -1; // 初始为-1,表示没有图片显示
- // 创建所有图片图层并添加到Viewer,初始时全部隐藏
- await imageUrls.forEach((url) => {
- const provider = new Cesium.SingleTileImageryProvider({
- url: url,
- // url: URL.createObjectURL(url),
- rectangle: Cesium.Rectangle.fromDegrees(-180.0, -90.0, 180.0, 90.0), // 全球覆盖
- tileWidth: 1440, // 根据你的图片实际宽度修改
- tileHeight: 721,
- // 如果你的图片只覆盖特定区域,请修改rectangle参数
- });
- const Layer = this.viewer.imageryLayers.addImageryProvider(provider);
- Layer.alpha = 0.8; // 透明度
- Layer.brightness = 1; // 亮度
- Layer.contrast = 1; // 对比度
- Layer.show = false; // 初始隐藏
- imageLayers.push(Layer);
- ImagesLayers.push(Layer);
- });
- function showNextImage() {
- // 隐藏当前图片
- if (currentImageIndex >= 0 && currentImageIndex < imageLayers.length) {
- imageLayers[currentImageIndex].show = false;
- }
- // 计算下一张图片的索引
- currentImageIndex = (currentImageIndex + 1) % imageLayers.length;
- // 显示下一张图片
- imageLayers[currentImageIndex].show = true;
- // imageLayers[currentImageIndex + 1].show = true;
- console.log("当前显示图片: " + imageUrls[currentImageIndex]);
- }
- // 设置切换间隔(毫秒),例如每5秒切换一次
- const intervalMs = 5000;
- intervalId = setInterval(showNextImage, intervalMs);
- // 初始显示第一张图片
- showNextImage();
- },
- // 移除风场图
- removeWindLayer() {
- if (this.windLayer) {
- // this.windLayer.destroy();
- this.windLayer.remove();
- this.windLayer = null;
- }
- },
- // 移除卫星云图
- removeCloudLayer() {
- if (this.cloudLayer) {
- this.tagMsg = null;
- this.viewer.imageryLayers.remove(this.cloudLayer);
- this.cloudLayer = null;
- }
- if (this.cloudImagesLayer.length > 0) {
- this.cloudImagesLayer.forEach((it) => {
- this.viewer.imageryLayers.remove(it);
- });
- this.cloudImagesLayer = [];
- }
- if (this.imageryProviderV) {
- this.viewer.imageryLayers.remove(this.imageryProviderV);
- this.imageryProviderV = null;
- }
- },
- // 移除降雨图
- removeRainLayer() {
- if (this.rainLayer) {
- this.tagMsg = null;
- this.viewer.imageryLayers.remove(this.rainLayer);
- this.rainLayer = null;
- this.setMapImageryProvider();
- this.handlerAction.removeInputAction(
- Cesium.ScreenSpaceEventType.LEFT_CLICK
- );
- }
- if (this.rainImagesLayer.length > 0) {
- this.rainImagesLayer.forEach((it) => {
- this.viewer.imageryLayers.remove(it);
- });
- this.rainImagesLayer = [];
- }
- if (this.imageryProviderV) {
- this.viewer.imageryLayers.remove(this.imageryProviderV);
- this.imageryProviderV = null;
- }
- },
- // 移除温度图
- removeTemperatureLayer() {
- if (this.temperatureLayer) {
- this.tagMsg = null;
- this.viewer.imageryLayers.remove(this.temperatureLayer);
- this.temperatureLayer = null;
- this.setMapImageryProvider();
- this.handlerAction.removeInputAction(
- Cesium.ScreenSpaceEventType.LEFT_CLICK
- );
- }
- if (this.tempImagesLayer.length > 0) {
- this.tempImagesLayer.forEach((it) => {
- this.viewer.imageryLayers.remove(it);
- });
- this.tempImagesLayer = [];
- }
- if (this.imageryProviderV) {
- this.viewer.imageryLayers.remove(this.imageryProviderV);
- this.imageryProviderV = null;
- }
- },
- //取消所有图层加载
- cancleAllLayer() {
- if (this.windLayer) {
- this.removeWindLayer();
- }
- if (this.rainLayer || this.rainImagesLayer.length > 0) {
- this.removeRainLayer();
- this.stopCycling(this.rainintervalId);
- }
- if (this.cloudLayer || this.cloudImagesLayer.length > 0) {
- this.removeCloudLayer();
- this.stopCycling(this.cloudintervalId);
- }
- if (this.temperatureLayer || this.tempImagesLayer.length > 0) {
- this.removeTemperatureLayer();
- this.stopCycling(this.tempintervalId);
- }
- },
- switchLayer() {
- this.$router.push({
- path: "/",
- });
- },
- menuComTSty(val) {
- this.menuComTStyB = val;
- },
- },
- };
- </script>
- <style lang="less" scoped>
- .dataLoading {
- width: 100vw;
- height: 100vh;
- background: rgba(0, 0, 0, 0.5);
- z-index: 999;
- position: fixed;
- .loadText {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- background: rgba(255, 255, 255, 0.7);
- padding: 15px 20px;
- border-radius: 6px;
- color: black;
- font-size: 14px;
- font-weight: bold;
- }
- }
- .mapBox {
- width: 100%;
- height: 100%;
- position: relative;
- box-sizing: content-box;
- overflow: hidden;
- .menuComT {
- position: fixed;
- bottom: 400px;
- left: 20px;
- }
- .menuComTSty {
- position: fixed;
- bottom: 20px;
- left: 20px;
- }
- }
- </style>
- <style lang="less">
- .el-overlay {
- background-color: transparent !important;
- .windModelDrawer {
- width: 80% !important;
- backdrop-filter: blur(15px) !important;
- background: rgba(255, 255, 255, 0.8) !important;
- border-radius: 10px 0 0 10px !important;
- .el-drawer__body {
- overflow: hidden;
- padding-top: 0;
- }
- }
- }
- .windDrawerCla {
- .line {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- width: 100%;
- margin-bottom: 10px;
- .leftContent {
- width: 242px;
- height: 41px;
- display: flex;
- align-items: center;
- background: url("@/assets/cesiumImg/title_left_bg.png") no-repeat;
- span {
- font-size: 16px;
- font-family: Microsoft YaHei;
- font-weight: 400;
- color: #ffffff;
- margin-left: 25px;
- }
- }
- }
- .jcxx,
- .gzck {
- height: 100%;
- }
- .spjk,
- .third {
- height: 80vh;
- }
- }
- </style>
|