TongzhouTrafficMap.vue 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  1. <template>
  2. <div class="map-wrapper">
  3. <div ref="mapContainer" class="map-container"></div>
  4. <div class="map-legend" :style="privateStyle.legend" v-if="(!mode || mode === '路口')"
  5. :class="{ 'legend-hidden': !legendVisible }">
  6. <div class="legend-header">
  7. <div class="legend-title">图例</div>
  8. <div class="legend-close-btn" @click="toggleLegend">✕</div>
  9. </div>
  10. <div class="legend-list">
  11. <div class="legend-item all-select" @click="toggleAll">
  12. <div class="legend-dot"
  13. :style="{ backgroundColor: isAllSelected ? '#fff' : 'transparent', border: '1px solid #fff' }"></div>
  14. <div class="legend-label" style="font-weight: bold;">全选</div>
  15. </div>
  16. <div v-for="item in legendStatusConfig" class="legend-item" @click="toggleRouteVisible(item.name)" :key="item.name"
  17. :class="{ 'is-inactive': !activeLegends.includes(item.name) }">
  18. <div class="legend-dot"
  19. :style="{ backgroundColor: ['离线', '降级', '故障'].includes(item.name) ? 'transparent' : item.color }"
  20. :class="{ 'special-route': ['干线协调', '勤务路线'].includes(item.name), 'is-status-wrapper': ['离线', '降级', '故障'].includes(item.name) }">
  21. <span v-if="!['离线', '降级', '故障'].includes(item.name)">
  22. {{ item.name.charAt(0) }}
  23. </span>
  24. <img v-else
  25. :src="require(`@/assets/images/icon_${item.name === '离线' ? 'lixian' : item.name === '降级' ? 'jiangji' : 'guzhang'}.png`)"
  26. class="status-icon" />
  27. </div>
  28. <div class="legend-label">{{ item.name }}</div>
  29. </div>
  30. </div>
  31. </div>
  32. <div class="legend-show-btn" v-if="(!mode || mode === '路口') && !legendVisible" @click="toggleLegend" :style="legendShowBtnStyle">
  33. <div class="legend-show-icon">☰</div>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. import AMapLoader from '@amap/amap-jsapi-loader';
  39. export default {
  40. name: "TrafficMap",
  41. props: {
  42. amapKey: { type: String, default: '您的Key' },
  43. securityJsCode: { type: String, default: '您的安全密钥' },
  44. mode: { type: String, default: '', validator: (value) => ['', '路口', '干线', '特勤'].includes(value) }
  45. },
  46. data() {
  47. return {
  48. AMap: null,
  49. map: null,
  50. infoWindow: null,
  51. routeGroups: {},
  52. polylines: [],
  53. privateStyle: {
  54. legend: {}
  55. },
  56. legendVisible: true,
  57. activeLegends: ["中心计划", "干线协调", "勤务路线", "定周期控制", "感应控制", "自适应控制", "手动控制", "特殊控制", "离线", "降级", "故障"],
  58. // 核心修正:增加生命周期标识,防止组件销毁后异步回调继续执行
  59. isComponentDestroyed: false,
  60. drawSeq: 0,
  61. driving: null,
  62. infoCloseTimer: null,
  63. activeInfoWindowId: null,
  64. isInfoWindowHovered: false,
  65. // 状态类型配置
  66. statusConfig: [
  67. { name: "中心计划", color: "#004CDE", type: "normal" },
  68. { name: "干线协调", color: "#13C373", type: "route" },
  69. { name: "勤务路线", color: "#BC301D", type: "route" },
  70. { name: "定周期控制", color: "#3296FA", type: "normal" },
  71. { name: "感应控制", color: "#FF864C", type: "normal" },
  72. { name: "自适应控制", color: "#9F6EFE", type: "normal" },
  73. { name: "手动控制", color: "#EB9F36", type: "normal" },
  74. { name: "特殊控制", color: "#A26218", type: "normal" },
  75. { name: "离线", color: "#7A7A7A", type: "abnormal" },
  76. { name: "降级", color: "#D9C13B", type: "abnormal" },
  77. { name: "故障", color: "#FF3938", type: "abnormal" }
  78. ],
  79. // 真实路口数据
  80. intersectionData: [],
  81. // 按状态分类的路口数据
  82. statusIntersections: {},
  83. };
  84. },
  85. mounted() {
  86. this.isComponentDestroyed = false; // 重置标识
  87. this.loadMapData().then(() => {
  88. this.classifyIntersectionsByStatus();
  89. this.updateMapByMode();
  90. this.initAMap();
  91. // 在数据加载完成后存储坐标
  92. this.storeStatusCoordsToLocalStorage();
  93. });
  94. if (this.$route.path === '/home' || this.$route.path === '/watch') {
  95. this.privateStyle.legend = { right: "25%" };
  96. }
  97. },
  98. watch: {
  99. mode: {
  100. handler() {
  101. this.updateMapByMode();
  102. this.updateMapDisplay();
  103. },
  104. immediate: false
  105. }
  106. },
  107. beforeDestroy() {
  108. // 1. 立即设置销毁状态
  109. this.isComponentDestroyed = true;
  110. this.drawSeq += 1;
  111. // 2. 关闭弹窗
  112. if (this.infoWindow) {
  113. try {
  114. this.infoWindow.close();
  115. } catch (e) {
  116. console.warn('关闭信息窗口时出错:', e);
  117. }
  118. this.infoWindow = null;
  119. }
  120. // 3. 清理覆盖物引用
  121. if (this.routeGroups) {
  122. Object.values(this.routeGroups).forEach(overlays => {
  123. if (Array.isArray(overlays)) {
  124. overlays.forEach(o => {
  125. try {
  126. if (o.setMap) o.setMap(null);
  127. } catch (e) {
  128. console.warn('清理覆盖物时出错:', e);
  129. }
  130. });
  131. }
  132. });
  133. this.routeGroups = {};
  134. }
  135. // 4. 销毁地图实例并清空引用
  136. if (this.map) {
  137. try {
  138. this.map.destroy();
  139. } catch (e) {
  140. console.warn('销毁地图实例时出错:', e);
  141. }
  142. this.map = null;
  143. }
  144. // 5. 清理其他引用
  145. this.AMap = null;
  146. this.driving = null;
  147. if (this.infoCloseTimer) {
  148. clearTimeout(this.infoCloseTimer);
  149. this.infoCloseTimer = null;
  150. }
  151. this.activeInfoWindowId = null;
  152. this.isInfoWindowHovered = false;
  153. },
  154. computed: {
  155. isAllSelected() {
  156. return this.activeLegends.length === this.statusConfig.length;
  157. },
  158. isHomePage() {
  159. return this.$route && (this.$route.path === '/home' || this.$route.path === '/surve');
  160. },
  161. legendShowBtnStyle() {
  162. if (!this.isHomePage) return {};
  163. const right = (this.privateStyle.legend && this.privateStyle.legend.right) ? this.privateStyle.legend.right : '25%';
  164. return { right, borderRadius: '6px' };
  165. },
  166. legendStatusConfig() {
  167. if (!this.mode) return this.statusConfig;
  168. if (this.mode === '路口') {
  169. return this.statusConfig.filter(item => !['干线协调', '勤务路线'].includes(item.name));
  170. }
  171. return [];
  172. }
  173. },
  174. methods: {
  175. // 动态加载地图数据
  176. async loadMapData() {
  177. try {
  178. const mapDataModule = await import('@/mock/map_data_gaode.json');
  179. this.intersectionData = mapDataModule.default || [];
  180. console.log('地图数据加载成功,共', this.intersectionData.length, '个路口');
  181. } catch (error) {
  182. console.error('地图数据加载失败:', error);
  183. this.intersectionData = [];
  184. }
  185. },
  186. // 检查地图环境是否安全可用
  187. isMapReady() {
  188. return !this.isComponentDestroyed && this.map && typeof this.map.add === 'function';
  189. },
  190. // 将真实路口数据按状态类型分类
  191. classifyIntersectionsByStatus() {
  192. const remainingData = this.intersectionData;
  193. const normalStatusCount = 6;
  194. const abnormalStatusCount = 3;
  195. const chunkSize = Math.floor(remainingData.length / (normalStatusCount + abnormalStatusCount));
  196. const maxAbnormalCount = 4;
  197. this.statusIntersections = {
  198. "中心计划": remainingData.slice(0, 20),
  199. "干线协调": [], // 清空,改为动态生成
  200. "勤务路线": [], // 清空,改为动态生成
  201. "定周期控制": remainingData.slice(chunkSize, chunkSize * 2),
  202. "感应控制": remainingData.slice(chunkSize * 2, chunkSize * 3),
  203. "自适应控制": remainingData.slice(chunkSize * 3, chunkSize * 4),
  204. "手动控制": remainingData.slice(chunkSize * 4, chunkSize * 5),
  205. "特殊控制": remainingData.slice(chunkSize * 5, chunkSize * 6),
  206. "离线": remainingData.slice(chunkSize * 6, Math.min(chunkSize * 7, chunkSize * 6 + maxAbnormalCount)),
  207. "降级": remainingData.slice(chunkSize * 7, Math.min(chunkSize * 8, chunkSize * 7 + maxAbnormalCount)),
  208. "故障": remainingData.slice(chunkSize * 8, Math.min(chunkSize * 9, chunkSize * 8 + maxAbnormalCount))
  209. };
  210. },
  211. updateMapByMode() {
  212. switch (this.mode) {
  213. case '路口':
  214. this.activeLegends = ["中心计划", "定周期控制", "感应控制", "自适应控制", "手动控制", "特殊控制", "离线", "降级", "故障"];
  215. break;
  216. case '干线':
  217. this.activeLegends = ["干线协调"];
  218. break;
  219. case '特勤':
  220. this.activeLegends = ["勤务路线"];
  221. break;
  222. default:
  223. this.activeLegends = this.statusConfig.map(item => item.name);
  224. }
  225. },
  226. updateMapDisplay() {
  227. if (this.infoWindow) this.infoWindow.close();
  228. if (!this.isMapReady()) return;
  229. Object.keys(this.routeGroups).forEach(name => {
  230. const overlays = this.routeGroups[name];
  231. if (overlays && overlays.length > 0) {
  232. if (this.activeLegends.includes(name)) {
  233. this.map.add(overlays);
  234. } else {
  235. this.map.remove(overlays);
  236. }
  237. }
  238. });
  239. },
  240. async initAMap() {
  241. if (this.isComponentDestroyed) return;
  242. // 确保在加载前注入
  243. window._AMapSecurityConfig = { securityJsCode: this.securityJsCode };
  244. try {
  245. const AMap = await AMapLoader.load({
  246. key: this.amapKey,
  247. version: "2.0",
  248. // 核心:确保 Driving 插件在此加载
  249. plugins: ['AMap.Driving']
  250. });
  251. if (this.isComponentDestroyed) return;
  252. this.AMap = AMap;
  253. this.map = new AMap.Map(this.$refs.mapContainer, {
  254. zoom: 15,
  255. mapStyle: "amap://styles/darkblue",
  256. center: [116.663, 39.905], // 通州区中心
  257. });
  258. this.driving = new AMap.Driving({ map: null, hideMarkers: true });
  259. // 建议在地图加载完成后再画线
  260. this.map.on('complete', () => {
  261. if (!this.isComponentDestroyed) {
  262. this.drawStaticRoutes();
  263. }
  264. });
  265. } catch (err) {
  266. console.error('地图加载失败:', err);
  267. }
  268. },
  269. // 绘制静态路线和标记
  270. // 对于普通状态,从 mock 数据加载路口标记
  271. // 对于路线类(干线协调和勤务路线),使用高德地图路线规划绘制路线和密集点位
  272. async drawStaticRoutes() {
  273. if (!this.isMapReady()) return;
  274. this.drawSeq += 1;
  275. const drawSeq = this.drawSeq;
  276. this.clearAllRouteOverlays();
  277. const realRouteConfigs = {
  278. "干线协调": [
  279. { start: [116.6421, 39.9272], end: [116.6825, 39.9272], color: "#13C373" },
  280. { start: [116.6426, 39.9221], end: [116.6830, 39.9221], color: "#13C373" },
  281. { start: [116.6432, 39.9171], end: [116.6833, 39.9171], color: "#13C373" },
  282. { start: [116.6438, 39.9123], end: [116.6841, 39.9123], color: "#13C373" },
  283. { start: [116.6445, 39.9075], end: [116.6846, 39.9075], color: "#13C373" }
  284. ],
  285. "勤务路线": [
  286. { start: [116.6900, 39.9225], end: [116.6900, 39.8971], color: "#BC301D" },
  287. { start: [116.6965, 39.9225], end: [116.6965, 39.8971], color: "#BC301D" },
  288. { start: [116.7021, 39.9225], end: [116.7021, 39.8971], color: "#BC301D" },
  289. { start: [116.7120, 39.9225], end: [116.7120, 39.8971], color: "#BC301D" },
  290. { start: [116.7234, 39.9225], end: [116.7234, 39.8971], color: "#BC301D" },
  291. { start: [116.7290, 39.9225], end: [116.7290, 39.8971], color: "#BC301D" },
  292. { start: [116.7350, 39.9170], end: [116.7350, 39.9000], color: "#BC301D" }
  293. ]
  294. };
  295. for (const config of this.statusConfig) {
  296. if (this.isComponentDestroyed || drawSeq !== this.drawSeq) return;
  297. // 1. 处理普通非路线状态(从 mock 数据加载)
  298. if (!realRouteConfigs[config.name]) {
  299. const intersections = this.statusIntersections[config.name] || [];
  300. const markers = intersections.map(item =>
  301. this.createTrafficLightMarker([item["位置-经度"], item["位置-纬度"]], {
  302. ...config,
  303. road: item["路口名称"] || '规划路口'
  304. })
  305. ).filter(Boolean);
  306. this.routeGroups[config.name] = markers;
  307. if (this.activeLegends.includes(config.name)) this.map.add(markers);
  308. continue;
  309. }
  310. // 2. 处理路线类(干线/特勤)
  311. this.routeGroups[config.name] = [];
  312. const lines = realRouteConfigs[config.name] || [];
  313. for (let lineIdx = 0; lineIdx < lines.length; lineIdx += 1) {
  314. if (this.isComponentDestroyed || drawSeq !== this.drawSeq) return;
  315. const line = lines[lineIdx];
  316. let path = null;
  317. try {
  318. path = await this.searchDrivingPathWithRetry(line.start, line.end);
  319. } catch (e) {
  320. path = null;
  321. }
  322. const overlays = this.buildRouteOverlaysFromPath({
  323. config,
  324. configName: config.name,
  325. line,
  326. lineIdx,
  327. path
  328. });
  329. if (this.isComponentDestroyed || drawSeq !== this.drawSeq) return;
  330. if (overlays.length > 0) {
  331. this.routeGroups[config.name].push(...overlays);
  332. if (this.activeLegends.includes(config.name)) this.map.add(overlays);
  333. }
  334. await this.sleep(80);
  335. }
  336. }
  337. },
  338. clearAllRouteOverlays() {
  339. if (!this.isMapReady()) return;
  340. try {
  341. if (this.infoWindow) this.infoWindow.close();
  342. } catch (e) {
  343. void e;
  344. }
  345. Object.values(this.routeGroups || {}).forEach(overlays => {
  346. if (!Array.isArray(overlays) || overlays.length === 0) return;
  347. try {
  348. this.map.remove(overlays);
  349. } catch (e) {
  350. void e;
  351. }
  352. overlays.forEach(o => {
  353. try {
  354. if (o && typeof o.setMap === 'function') o.setMap(null);
  355. } catch (e) {
  356. void e;
  357. }
  358. });
  359. });
  360. this.routeGroups = {};
  361. },
  362. sleep(ms) {
  363. return new Promise(resolve => setTimeout(resolve, ms));
  364. },
  365. async searchDrivingPathWithRetry(start, end) {
  366. if (!this.AMap || !this.driving || typeof this.driving.search !== 'function') {
  367. throw new Error('Driving not ready');
  368. }
  369. const maxAttempts = 3;
  370. let lastErr = null;
  371. for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
  372. try {
  373. return await this.withTimeout(this.searchDrivingPathOnce(start, end), 8000);
  374. } catch (e) {
  375. lastErr = e;
  376. await this.sleep(250 * attempt);
  377. }
  378. }
  379. throw lastErr || new Error('Driving search failed');
  380. },
  381. searchDrivingPathOnce(start, end) {
  382. return new Promise((resolve, reject) => {
  383. this.driving.search(start, end, (status, result) => {
  384. const route = result && result.routes && result.routes[0];
  385. if (status === 'complete' && route && Array.isArray(route.steps)) {
  386. const fullPath = [];
  387. route.steps.forEach(step => {
  388. if (step && Array.isArray(step.path)) fullPath.push(...step.path);
  389. });
  390. if (fullPath.length >= 2) resolve(fullPath);
  391. else reject(new Error('empty_path'));
  392. return;
  393. }
  394. reject(new Error(typeof status === 'string' ? status : 'driving_error'));
  395. });
  396. });
  397. },
  398. withTimeout(promise, timeoutMs) {
  399. return Promise.race([
  400. promise,
  401. new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeoutMs))
  402. ]);
  403. },
  404. buildRouteOverlaysFromPath({ config, configName, line, lineIdx, path }) {
  405. if (!this.AMap || !this.map) return [];
  406. let basePath = path;
  407. if (!Array.isArray(basePath) || basePath.length < 2) {
  408. basePath = this.buildFallbackLinePath(line.start, line.end, 30);
  409. }
  410. const segments = this.extractMainStraightSegments(basePath);
  411. const overlays = [];
  412. segments.forEach((segmentPath, segmentIdx) => {
  413. if (!Array.isArray(segmentPath) || segmentPath.length < 2) return;
  414. const polyline = new this.AMap.Polyline({
  415. path: segmentPath,
  416. strokeColor: line.color,
  417. strokeWeight: 6,
  418. strokeOpacity: 0.8,
  419. zIndex: 15
  420. });
  421. overlays.push(polyline);
  422. const totalPoints = segmentPath.length;
  423. // --- 核心优化:全路段物理距离均匀放置方向箭头 ---
  424. // 1. 计算整条 segmentPath 的总物理距离及每个点的累计距离
  425. const pathDistances = [0];
  426. let totalPathDist = 0;
  427. for (let j = 0; j < totalPoints - 1; j++) {
  428. const d = this.calcApproxDistance(segmentPath[j], segmentPath[j+1]);
  429. totalPathDist += d;
  430. pathDistances.push(totalPathDist);
  431. }
  432. // 2. 设定标准间距:约每 0.0018 度 (约 200 米) 放置一个箭头
  433. const targetSpacing = 0.0018;
  434. let currentTargetDist = targetSpacing / 2; // 第一个箭头放在 1/2 间距处,让分布更美观
  435. while (currentTargetDist < totalPathDist) {
  436. // 3. 寻找对应 targetDist 的路径位置 (线性插值)
  437. let foundIdx = 0;
  438. for (let j = 0; j < pathDistances.length - 1; j++) {
  439. if (currentTargetDist >= pathDistances[j] && currentTargetDist <= pathDistances[j + 1]) {
  440. foundIdx = j;
  441. break;
  442. }
  443. }
  444. const p1 = segmentPath[foundIdx];
  445. const p2 = segmentPath[foundIdx + 1];
  446. if (p1 && p2) {
  447. // 在 p1 和 p2 之间线性插值
  448. const ratio = (currentTargetDist - pathDistances[foundIdx]) / (pathDistances[foundIdx + 1] - pathDistances[foundIdx]);
  449. const lng1 = p1.lng || (Array.isArray(p1) ? Number(p1[0]) : 0);
  450. const lat1 = p1.lat || (Array.isArray(p1) ? Number(p1[1]) : 0);
  451. const lng2 = p2.lng || (Array.isArray(p2) ? Number(p2[0]) : 0);
  452. const lat2 = p2.lat || (Array.isArray(p2) ? Number(p2[1]) : 0);
  453. const midLng = lng1 + (lng2 - lng1) * ratio;
  454. const midLat = lat1 + (lat2 - lat1) * ratio;
  455. const bearing = this.calcBearingDeg({ lng: lng1, lat: lat1 }, { lng: lng2, lat: lat2 });
  456. const rotation = bearing - 90;
  457. const directionMarker = new this.AMap.Marker({
  458. position: [midLng, midLat],
  459. content: `
  460. <div style="transform: rotate(${rotation}deg); width: 20px; height: 10px; display: flex; align-items: center; pointer-events: none; opacity: 0.85;">
  461. <img src="${require('@/assets/map/direction.png')}" style="width: 100%; height: auto;" />
  462. </div>
  463. `,
  464. offset: new this.AMap.Pixel(-10, -5),
  465. zIndex: 20,
  466. bubble: true
  467. });
  468. overlays.push(directionMarker);
  469. }
  470. currentTargetDist += targetSpacing;
  471. }
  472. // 为圆点保留原来的分布 logic (不受箭头影响)
  473. const indices = this.pickEvenlySpacedIndices(totalPoints, 6);
  474. // 为第一个和最后一个圆点设置特殊类型
  475. for (let i = 0; i < indices.length; i++) {
  476. const idx = indices[i];
  477. const p = segmentPath[idx];
  478. const lng = p && typeof p.lng === 'number' ? p.lng : (Array.isArray(p) ? Number(p[0]) : NaN);
  479. const lat = p && typeof p.lat === 'number' ? p.lat : (Array.isArray(p) ? Number(p[1]) : NaN);
  480. if (Number.isNaN(lng) || Number.isNaN(lat)) continue;
  481. // 确定圆点类型:第一个为start,最后一个为end,其余为normal
  482. let markerType = 'normal';
  483. if (i === 0) {
  484. markerType = 'start';
  485. } else if (i === indices.length - 1) {
  486. markerType = 'end';
  487. }
  488. const marker = this.createTrafficLightMarker([lng, lat], {
  489. ...config,
  490. id: `MOCK-${configName.charAt(0)}-${lineIdx}-${segmentIdx}-${idx}`,
  491. road: `${configName}路口-${lineIdx}-${segmentIdx}-${idx}`
  492. }, markerType);
  493. if (marker) overlays.push(marker);
  494. }
  495. });
  496. return overlays;
  497. },
  498. pickEvenlySpacedIndices(totalPoints, count) {
  499. const total = Math.max(Number(totalPoints) || 0, 0);
  500. const target = Math.max(Number(count) || 0, 0);
  501. if (total <= 0) return [];
  502. if (target <= 0) return [];
  503. if (target >= total) return Array.from({ length: total }, (_, i) => i);
  504. if (target === 1) return [0];
  505. const set = new Set();
  506. const last = total - 1;
  507. for (let k = 0; k < target; k += 1) {
  508. const idx = Math.round((k * last) / (target - 1));
  509. set.add(idx);
  510. }
  511. return Array.from(set).sort((a, b) => a - b);
  512. },
  513. buildFallbackLinePath(start, end, pointCount) {
  514. const sLng = Number(start && start[0]);
  515. const sLat = Number(start && start[1]);
  516. const eLng = Number(end && end[0]);
  517. const eLat = Number(end && end[1]);
  518. const n = Math.max(Number(pointCount) || 2, 2);
  519. const path = [];
  520. if ([sLng, sLat, eLng, eLat].some(v => Number.isNaN(v))) return path;
  521. for (let i = 0; i < n; i += 1) {
  522. const t = n === 1 ? 0 : i / (n - 1);
  523. const lng = sLng + (eLng - sLng) * t;
  524. const lat = sLat + (eLat - sLat) * t;
  525. path.push({ lng, lat });
  526. }
  527. return path;
  528. },
  529. extractMainStraightSegments(path) {
  530. const points = (path || []).filter(p => p && typeof p.lng === 'number' && typeof p.lat === 'number');
  531. if (points.length < 2) return [];
  532. const thresholdDeg = 18;
  533. const segments = [];
  534. let curStart = 0;
  535. let curAngle = null;
  536. let curLen = 0;
  537. const pushSegment = (endIdx) => {
  538. if (endIdx <= curStart) return;
  539. segments.push({
  540. start: curStart,
  541. end: endIdx,
  542. len: curLen
  543. });
  544. };
  545. for (let i = 0; i < points.length - 1; i += 1) {
  546. const a = points[i];
  547. const b = points[i + 1];
  548. const len = this.calcApproxDistance(a, b);
  549. if (len <= 0) continue;
  550. const angle = this.calcBearingDeg(a, b);
  551. if (curAngle === null) {
  552. curStart = i;
  553. curAngle = angle;
  554. curLen = len;
  555. continue;
  556. }
  557. const diff = this.calcAngleDiffDeg(curAngle, angle);
  558. if (diff <= thresholdDeg) {
  559. curLen += len;
  560. } else {
  561. pushSegment(i);
  562. curStart = i;
  563. curAngle = angle;
  564. curLen = len;
  565. }
  566. }
  567. pushSegment(points.length - 2);
  568. if (segments.length === 0) return [points];
  569. segments.sort((s1, s2) => s2.len - s1.len);
  570. const maxLen = segments[0].len || 0;
  571. const filtered = segments.filter(s => s.len >= maxLen * 0.55).slice(0, 3);
  572. const finalSegments = filtered.map(s => points.slice(s.start, s.end + 2));
  573. return finalSegments.length > 0 ? finalSegments : [points];
  574. },
  575. calcBearingDeg(a, b) {
  576. const latRad = ((a.lat + b.lat) / 2) * Math.PI / 180;
  577. const dx = (b.lng - a.lng) * Math.cos(latRad);
  578. const dy = (b.lat - a.lat);
  579. // 使用地理方位角公式:0度为北,顺时针增加
  580. // atan2(dy, dx) 返回数学角度(0为东,逆时针)
  581. // geographic_bearing = (90 - math_angle + 360) % 360
  582. const mathAngle = Math.atan2(dy, dx) * 180 / Math.PI;
  583. let bearing = (90 - mathAngle + 360) % 360;
  584. return bearing;
  585. },
  586. calcAngleDiffDeg(a, b) {
  587. let diff = Math.abs(a - b);
  588. if (diff > 180) diff = 360 - diff;
  589. return diff;
  590. },
  591. calcApproxDistance(a, b) {
  592. const latRad = ((a.lat + b.lat) / 2) * Math.PI / 180;
  593. const dx = (b.lng - a.lng) * Math.cos(latRad);
  594. const dy = (b.lat - a.lat);
  595. return Math.sqrt(dx * dx + dy * dy);
  596. },
  597. createTrafficLightMarker(position, config, type = 'normal') {
  598. if (!position || !config) return null;
  599. try {
  600. const lng = Number(position[0] || position.lng);
  601. const lat = Number(position[1] || position.lat);
  602. if (isNaN(lng) || isNaN(lat)) return null;
  603. // 状态文字:起、终、或者状态配置的首字母
  604. let displayText = config.name ? config.name.charAt(0) : '';
  605. if (type === 'start') displayText = '起';
  606. if (type === 'end') displayText = '终';
  607. const isAbnormal = ["离线", "降级", "故障"].includes(config.name);
  608. const isRoute = ["干线协调", "勤务路线"].includes(config.name);
  609. // 动态计算尺寸:起终点最大,异常点次之,普通点最小
  610. const isStartEnd = type === 'start' || type === 'end';
  611. const size = isStartEnd ? '24px' : (isAbnormal ? '30px' : '14px');
  612. const sizeNumber = parseInt(size, 10);
  613. const paddingNumber = (isAbnormal || isStartEnd) ? 0 : 2;
  614. const outerSizeNumber = sizeNumber + paddingNumber * 2;
  615. // 边框样式:起终点用实白边框
  616. const borderStyle = isStartEnd
  617. ? '2px solid #fff'
  618. : '1.5px solid rgba(255,255,255,0.7)';
  619. // 生成标记内容
  620. let markerContent = '';
  621. if (isStartEnd) {
  622. const iconPath = type === 'start'
  623. ? require('@/assets/map/start.png')
  624. : require('@/assets/map/end.png');
  625. markerContent = `
  626. <div class="pure-light-node start-end-node"
  627. style="
  628. width: ${size};
  629. height: 30px;
  630. background: transparent;
  631. border: none;
  632. display: flex;
  633. justify-content: center;
  634. align-items: flex-end;
  635. cursor: pointer;
  636. transform-origin: bottom center;
  637. ">
  638. <img src="${iconPath}" style="width: 100%; height: auto; object-fit: contain; pointer-events: none;" />
  639. </div>
  640. `;
  641. } else if (isAbnormal) {
  642. const iconName = config.name === '离线' ? 'lixian' : config.name === '降级' ? 'jiangji' : 'guzhang';
  643. markerContent = `
  644. <div class="pure-light-node ${isAbnormal ? 'breathe' : ''}"
  645. style="
  646. width: ${size};
  647. height: ${size};
  648. background: transparent;
  649. box-shadow: none;
  650. border: none;
  651. box-sizing: content-box;
  652. display: flex;
  653. justify-content: center;
  654. align-items: center;
  655. cursor: pointer;
  656. padding: ${paddingNumber}px;
  657. ">
  658. <img src="${require(`@/assets/images/icon_${iconName}.png`)}" style="width: 100%; height: 100%; object-fit: contain;" />
  659. </div>
  660. `;
  661. } else {
  662. markerContent = `
  663. <div class="pure-light-node ${isAbnormal ? 'breathe' : ''} ${isRoute ? 'route-node' : ''}"
  664. style="
  665. width: ${size};
  666. height: ${size};
  667. background: ${config.color || '#999'};
  668. box-shadow: ${isRoute ? 'none' : `0 0 8px ${config.color}`};
  669. border: ${isRoute ? 'none' : borderStyle};
  670. box-sizing: content-box;
  671. display: flex;
  672. justify-content: center;
  673. align-items: center;
  674. color: #fff;
  675. border-radius: 50%;
  676. cursor: pointer;
  677. padding: ${paddingNumber}px;
  678. ">
  679. <span style="transform: scale(0.8); font-weight: bold; font-size: 12px;">${displayText}</span>
  680. </div>
  681. `;
  682. }
  683. // 计算偏移量:起点终点底部对齐,其他中心对齐
  684. let markerOffset;
  685. if (isStartEnd) {
  686. // 设置 24px 宽 30px 高,偏移量设置为底部中心对齐
  687. markerOffset = new this.AMap.Pixel(-12, -30);
  688. } else {
  689. markerOffset = new this.AMap.Pixel(-Math.round(outerSizeNumber / 2), -Math.round(outerSizeNumber / 2));
  690. }
  691. const marker = new this.AMap.Marker({
  692. position: [lng, lat],
  693. zIndex: isStartEnd ? 120 : (isAbnormal ? 110 : 100),
  694. content: markerContent,
  695. offset: markerOffset,
  696. extData: {
  697. ...config,
  698. position: [lng, lat],
  699. statusColor: config.color || '#999',
  700. statusLabel: config.name,
  701. road: config.road || '规划路口',
  702. timestamp: Date.now(),
  703. time: this.formatEventTime(Date.now())
  704. }
  705. });
  706. marker.on('click', (e) => {
  707. if (this.isComponentDestroyed) return;
  708. const extData = e.target.getExtData();
  709. if (this.$route && this.$route.path === '/home') {
  710. this.cancelCloseInfoWindow();
  711. this.openLightInfo(extData, e.lnglat);
  712. }
  713. // 获取像素坐标
  714. const pixel = this.map.lngLatToContainer(e.lnglat);
  715. this.$emit('map-crossing-click', extData, e.lnglat, pixel);
  716. });
  717. marker.on('mouseover', (e) => {
  718. if (this.isComponentDestroyed) return;
  719. if (this.$route && this.$route.path === '/home') {
  720. this.cancelCloseInfoWindow();
  721. this.openLightInfo(e.target.getExtData(), e.lnglat);
  722. }
  723. // 获取像素坐标
  724. const pixel = this.map.lngLatToContainer(e.lnglat);
  725. // 传递路口鼠标滑入事件
  726. this.$emit('map-crossing-mouseover', e.target.getExtData(), e.lnglat, pixel);
  727. });
  728. marker.on('mouseout', (e) => {
  729. if (this.isComponentDestroyed) return;
  730. if (this.$route && this.$route.path === '/home') {
  731. this.scheduleCloseInfoWindow();
  732. }
  733. // 传递路口鼠标滑出事件
  734. this.$emit('map-crossing-mouseout', e.target.getExtData());
  735. });
  736. return marker;
  737. } catch (e) {
  738. console.warn('创建标记时出错:', e);
  739. return null;
  740. }
  741. },
  742. openLightInfo(data, position) {
  743. if (!this.isMapReady()) return;
  744. const infoWindowId = `info-window-${Date.now()}`;
  745. this.activeInfoWindowId = infoWindowId;
  746. const isAbnormal = ["离线", "降级", "故障"].includes(data.name);
  747. const deviceStatusText = isAbnormal ? data.name : '正常';
  748. const alarmInfoText = isAbnormal ? this.getAlarmInfoText(data.name) : '';
  749. const eventTimeText = this.formatEventTime(data.timestamp || data.time);
  750. let statusDotContent = '';
  751. if (isAbnormal) {
  752. const iconName = data.name === '离线' ? 'lixian' : data.name === '降级' ? 'jiangji' : 'guzhang';
  753. statusDotContent = `<img src="${require(`@/assets/images/icon_${iconName}.png`)}" style="width: 100%; height: 100%; object-fit: contain;" />`;
  754. } else {
  755. statusDotContent = `<span>${data.name.charAt(0)}</span>`;
  756. }
  757. const content = `
  758. <div class="custom-info-card" id="${infoWindowId}">
  759. <div class="close-btn" data-id="${infoWindowId}">✕</div>
  760. <div class="card-header">
  761. <div class="status-dot ${isAbnormal ? 'breathe' : ''}" style="background: ${isAbnormal ? 'transparent' : data.statusColor}; border: ${isAbnormal ? 'none' : ''}">
  762. ${statusDotContent}
  763. </div>
  764. <span class="status-text">${data.statusLabel}</span>
  765. </div>
  766. <div class="card-body">
  767. ${isAbnormal
  768. ? `
  769. <div class="info-line"><span class="label">路口名称:</span><span class="value">${data.road}</span></div>
  770. <div class="info-line"><span class="label">设备状态:</span><span class="value digital">${deviceStatusText}</span></div>
  771. <div class="info-line"><span class="label">报警信息:</span><span class="value">${alarmInfoText}</span></div>
  772. <div class="info-line"><span class="label">发生时间:</span><span class="value digital">${eventTimeText}</span></div>
  773. `
  774. : `
  775. <div class="info-line"><span class="label">路口名称:</span><span class="value">${data.road}</span></div>
  776. <div class="info-line"><span class="label">设备状态:</span><span class="value digital">${deviceStatusText}</span></div>
  777. `
  778. }
  779. </div>
  780. </div>
  781. `;
  782. if (!this.infoWindow) {
  783. this.infoWindow = new this.AMap.InfoWindow({
  784. isCustom: true,
  785. offset: new this.AMap.Pixel(0, -20),
  786. autoMove: false // 防止弹窗自动平移导致的中心点偏移
  787. });
  788. }
  789. this.infoWindow.setContent(content);
  790. this.infoWindow.open(this.map, position);
  791. setTimeout(() => {
  792. if (this.activeInfoWindowId !== infoWindowId) return;
  793. const closeBtn = document.querySelector(`#${infoWindowId} .close-btn`);
  794. if (closeBtn) {
  795. closeBtn.addEventListener('click', () => {
  796. if (this.infoWindow) this.infoWindow.close();
  797. });
  798. }
  799. const root = document.querySelector(`#${infoWindowId}`);
  800. if (root) {
  801. root.addEventListener('mouseenter', () => {
  802. if (this.activeInfoWindowId !== infoWindowId) return;
  803. this.isInfoWindowHovered = true;
  804. this.cancelCloseInfoWindow();
  805. });
  806. root.addEventListener('mouseleave', () => {
  807. if (this.activeInfoWindowId !== infoWindowId) return;
  808. this.isInfoWindowHovered = false;
  809. this.scheduleCloseInfoWindow();
  810. });
  811. }
  812. }, 100);
  813. },
  814. cancelCloseInfoWindow() {
  815. if (this.infoCloseTimer) {
  816. clearTimeout(this.infoCloseTimer);
  817. this.infoCloseTimer = null;
  818. }
  819. },
  820. scheduleCloseInfoWindow() {
  821. this.cancelCloseInfoWindow();
  822. this.infoCloseTimer = setTimeout(() => {
  823. if (this.isComponentDestroyed) return;
  824. if (this.isInfoWindowHovered) return;
  825. if (this.infoWindow) this.infoWindow.close();
  826. this.activeInfoWindowId = null;
  827. }, 160);
  828. },
  829. getAlarmInfoText(statusName) {
  830. if (statusName === '离线') return '通讯中断设备离线';
  831. if (statusName === '降级') return '降级定周期控制';
  832. if (statusName === '故障') return '东向左转信号灯红绿同亮';
  833. return '设备异常';
  834. },
  835. formatEventTime(input) {
  836. let d = null;
  837. if (input instanceof Date) d = input;
  838. else if (typeof input === 'number') d = new Date(input);
  839. else if (typeof input === 'string') {
  840. const t = Date.parse(input);
  841. if (!Number.isNaN(t)) d = new Date(t);
  842. }
  843. if (!d || Number.isNaN(d.getTime())) d = new Date();
  844. const y = d.getFullYear();
  845. const m = d.getMonth() + 1;
  846. const day = d.getDate();
  847. const hh = String(d.getHours()).padStart(2, '0');
  848. const mm = String(d.getMinutes()).padStart(2, '0');
  849. return `${y}.${m}.${day} ${hh}:${mm}`;
  850. },
  851. toggleAll() {
  852. const targetState = !this.isAllSelected;
  853. if (!this.isMapReady()) return;
  854. if (targetState) {
  855. this.activeLegends = this.statusConfig.map(item => item.name);
  856. Object.values(this.routeGroups).forEach(overlays => {
  857. if (overlays && overlays.length > 0) this.map.add(overlays);
  858. });
  859. } else {
  860. this.activeLegends = [];
  861. Object.values(this.routeGroups).forEach(overlays => {
  862. if (overlays && overlays.length > 0) this.map.remove(overlays);
  863. });
  864. if (this.infoWindow) this.infoWindow.close();
  865. }
  866. },
  867. toggleRouteVisible(name) {
  868. if (!this.isMapReady()) return;
  869. const overlays = this.routeGroups[name] || [];
  870. const index = this.activeLegends.indexOf(name);
  871. if (index > -1) {
  872. this.activeLegends.splice(index, 1);
  873. this.map.remove(overlays);
  874. if (this.infoWindow) this.infoWindow.close();
  875. } else {
  876. this.activeLegends.push(name);
  877. this.map.add(overlays);
  878. }
  879. },
  880. focusByLocation(targetPos) {
  881. if (!this.isMapReady() || !targetPos) return;
  882. // 如果是字符串坐标 "lng,lat",则解析
  883. let pos = targetPos;
  884. if (typeof targetPos === 'string') {
  885. pos = targetPos.split(',').map(Number);
  886. }
  887. if (!Array.isArray(pos) || pos.length < 2) return;
  888. const [targetLng, targetLat] = pos;
  889. let bestMarker = null;
  890. let minDistanceSq = Infinity;
  891. // 遍历所有路由组,寻找离坐标点最近的标记
  892. Object.values(this.routeGroups).forEach(group => {
  893. if (!Array.isArray(group)) return;
  894. group.forEach(item => {
  895. if (!(item instanceof this.AMap.Marker)) return;
  896. const markerExt = item.getExtData();
  897. const markerPos = markerExt.position;
  898. if (!markerPos) return;
  899. const dx = markerPos[0] - targetLng;
  900. const dy = markerPos[1] - targetLat;
  901. const distSq = dx * dx + dy * dy;
  902. // 容差范围内(约 20 米),寻找最接近的点
  903. if (distSq < 0.000001) {
  904. // 优先规则:如果距离相同或非常接近,优先选择异常状态点(离线/降级/故障)
  905. const isAbnormal = ["离线", "降级", "故障"].includes(markerExt.name);
  906. const currentIsAbnormal = bestMarker ? ["离线", "降级", "故障"].includes(bestMarker.getExtData().name) : false;
  907. if (distSq < minDistanceSq || (isAbnormal && !currentIsAbnormal)) {
  908. minDistanceSq = distSq;
  909. bestMarker = item;
  910. }
  911. }
  912. });
  913. });
  914. if (bestMarker) {
  915. const finalPos = bestMarker.getPosition();
  916. this.map.setZoomAndCenter(17, finalPos, false, 500);
  917. setTimeout(() => {
  918. if (!this.isComponentDestroyed) this.openLightInfo(bestMarker.getExtData(), finalPos);
  919. }, 600);
  920. } else {
  921. // 如果找不到对应的标记,直接使用传入的坐标设置地图中心
  922. this.map.setZoomAndCenter(17, [targetLng, targetLat], false, 500);
  923. }
  924. },
  925. toggleLegend() {
  926. this.legendVisible = !this.legendVisible;
  927. },
  928. // 按4:4:4比例提取故障、离线、降级路口信息并存储到localStorage
  929. storeStatusCoordsToLocalStorage() {
  930. const alarmTypes = [
  931. { status: "故障", titles: ["通讯中断", "灯组故障", "相位冲突", "绿冲突"], level: "high", type: "error" },
  932. { status: "离线", titles: ["信号机离线", "信号机离线", "通讯中断", "检测器异常"], level: "mid", type: "warning" },
  933. { status: "降级", titles: ["降级黄闪", "降级黄闪", "方案切换异常", "检测器异常"], level: "mid", type: "warning" },
  934. ];
  935. const alarmList = [];
  936. let id = 1;
  937. alarmTypes.forEach(({ status, titles, level, type }) => {
  938. (this.statusIntersections[status] || []).slice(0, 4).forEach((item, i) => {
  939. const lng = item["位置-经度"];
  940. const lat = item["位置-纬度"];
  941. const name = item["路口名称"] || "";
  942. if (!lng || !lat) return;
  943. alarmList.push({
  944. id: `A${String(id).padStart(3, "0")}`,
  945. title: titles[i] || titles[0],
  946. loc: name,
  947. level,
  948. type,
  949. description: `${name}-${titles[i] || titles[0]}`,
  950. position: [lng, lat],
  951. });
  952. // 保持原有的 pos1-pos12 存储,兼容其他可能的引用
  953. localStorage.setItem(`pos${id}`, `${lng},${lat}`);
  954. id++;
  955. });
  956. });
  957. localStorage.setItem("alarmListFromMap", JSON.stringify(alarmList));
  958. console.log('状态坐标及告警数据已存储到localStorage');
  959. },
  960. // 公开方法:将经纬度转换为像素坐标
  961. lngLatToPixel(lng, lat) {
  962. if (!this.map) return null;
  963. return this.map.lngLatToContainer([lng, lat]);
  964. }
  965. }
  966. };
  967. </script>
  968. <style scoped>
  969. .map-wrapper {
  970. width: 100%;
  971. height: 100vh;
  972. position: relative;
  973. background: #010813;
  974. }
  975. .map-container {
  976. width: 100%;
  977. height: 100%;
  978. }
  979. ::v-deep .amap-logo,
  980. ::v-deep .amap-copyright,
  981. ::v-deep .amap-copyright-logo {
  982. display: none !important;
  983. }
  984. ::v-deep .pure-light-node.breathe {
  985. animation: light-breathe 2s infinite ease-in-out;
  986. }
  987. ::v-deep .pure-light-node span {
  988. display: flex;
  989. transform: scale(0.75);
  990. align-items: center;
  991. }
  992. ::v-deep .pure-light-node:hover {
  993. transform: scale(1.4);
  994. filter: brightness(1.2);
  995. }
  996. @keyframes light-breathe {
  997. 0% {
  998. transform: scale(0.9);
  999. opacity: 0.8;
  1000. }
  1001. 50% {
  1002. transform: scale(1.1);
  1003. opacity: 1;
  1004. }
  1005. 100% {
  1006. transform: scale(0.9);
  1007. opacity: 0.8;
  1008. }
  1009. }
  1010. ::v-deep .close-btn {
  1011. position: absolute;
  1012. top: 10px;
  1013. right: 12px;
  1014. color: #8da6c7;
  1015. cursor: pointer;
  1016. font-size: 16px;
  1017. transition: color 0.3s;
  1018. line-height: 1;
  1019. z-index: 10;
  1020. }
  1021. ::v-deep .close-btn:hover {
  1022. color: #ffffff;
  1023. }
  1024. ::v-deep .custom-info-card {
  1025. position: relative;
  1026. background: rgba(10, 15, 24, 0.95);
  1027. border-radius: 10px;
  1028. padding: 12px 16px;
  1029. min-width: 200px;
  1030. border: 1px solid rgba(255, 255, 255, 0.1);
  1031. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  1032. color: #fff;
  1033. }
  1034. ::v-deep .card-header {
  1035. display: flex;
  1036. align-items: center;
  1037. margin-bottom: 10px;
  1038. }
  1039. ::v-deep .status-dot {
  1040. width: 30px;
  1041. height: 30px;
  1042. border-radius: 50%;
  1043. display: flex;
  1044. justify-content: center;
  1045. align-items: center;
  1046. margin-right: 8px;
  1047. font-size: 14px;
  1048. padding: 0;
  1049. box-sizing: border-box;
  1050. }
  1051. ::v-deep .status-dot.breathe {
  1052. animation: light-breathe 2s infinite ease-in-out;
  1053. }
  1054. ::v-deep .status-dot span {
  1055. transform: scale(0.75);
  1056. }
  1057. ::v-deep .status-dot img {
  1058. width: 100%;
  1059. height: 100%;
  1060. object-fit: contain;
  1061. display: block;
  1062. }
  1063. ::v-deep .status-text {
  1064. font-size: 15px;
  1065. font-weight: bold;
  1066. }
  1067. ::v-deep .info-line {
  1068. display: flex;
  1069. margin-bottom: 6px;
  1070. font-size: 13px;
  1071. align-items: center;
  1072. }
  1073. ::v-deep .label {
  1074. color: #8da6c7;
  1075. white-space: nowrap;
  1076. }
  1077. ::v-deep .value {
  1078. color: #ffffff;
  1079. }
  1080. ::v-deep .digital {
  1081. font-family: 'Consolas', monospace;
  1082. }
  1083. .map-legend {
  1084. position: absolute;
  1085. bottom: 30px;
  1086. right: 40px;
  1087. background: rgba(5, 22, 45, 0.9);
  1088. border: 1px solid #1e4d8e;
  1089. padding: 15px;
  1090. border-radius: 6px;
  1091. z-index: 100;
  1092. transition: all 0.3s ease-in-out;
  1093. opacity: 1;
  1094. max-width: 200px;
  1095. overflow: hidden;
  1096. }
  1097. .map-legend.legend-hidden {
  1098. opacity: 0;
  1099. transform: translateX(calc(100% + 20px));
  1100. pointer-events: none;
  1101. }
  1102. .legend-header {
  1103. display: flex;
  1104. justify-content: space-between;
  1105. align-items: center;
  1106. margin-bottom: 12px;
  1107. border-bottom: 1px solid #1e4d8e;
  1108. padding-bottom: 8px;
  1109. }
  1110. .legend-close-btn {
  1111. color: #8da6c7;
  1112. cursor: pointer;
  1113. font-size: 16px;
  1114. transition: color 0.3s;
  1115. line-height: 1;
  1116. }
  1117. .legend-close-btn:hover {
  1118. color: #ffffff;
  1119. }
  1120. .legend-show-btn {
  1121. position: absolute;
  1122. bottom: 30px;
  1123. right: 20px;
  1124. background: rgba(5, 22, 45, 0.9);
  1125. border: 1px solid #1e4d8e;
  1126. width: 40px;
  1127. height: 40px;
  1128. border-radius: 6px 0 0 6px;
  1129. display: flex;
  1130. justify-content: center;
  1131. align-items: center;
  1132. cursor: pointer;
  1133. z-index: 99;
  1134. transition: all 0.3s ease-in-out;
  1135. }
  1136. .legend-show-btn:hover {
  1137. background: rgba(10, 30, 60, 0.9);
  1138. border-color: #3a75c4;
  1139. }
  1140. .legend-show-icon {
  1141. color: #8da6c7;
  1142. font-size: 18px;
  1143. transition: color 0.3s;
  1144. }
  1145. .legend-show-btn:hover .legend-show-icon {
  1146. color: #ffffff;
  1147. }
  1148. .legend-title {
  1149. color: #fff;
  1150. font-size: 14px;
  1151. }
  1152. .legend-item {
  1153. display: flex;
  1154. align-items: center;
  1155. margin-bottom: 10px;
  1156. cursor: pointer;
  1157. transition: 0.3s;
  1158. }
  1159. .legend-item.is-inactive {
  1160. opacity: 0.2;
  1161. filter: grayscale(1);
  1162. }
  1163. .legend-dot {
  1164. margin-right: 10px;
  1165. display: flex;
  1166. justify-content: center;
  1167. align-items: center;
  1168. }
  1169. .legend-dot:not(.is-status-wrapper) {
  1170. width: 20px;
  1171. height: 20px;
  1172. border-radius: 50%;
  1173. }
  1174. .legend-dot span {
  1175. display: inline-block;
  1176. width: 20px;
  1177. height: 20px;
  1178. font-size: 12px;
  1179. color: #FFF;
  1180. text-align: center;
  1181. transform: scale(0.75);
  1182. line-height: 20px;
  1183. }
  1184. .legend-dot.special-route {
  1185. position: relative;
  1186. overflow: visible !important;
  1187. z-index: 1;
  1188. border: none !important;
  1189. border-radius: 50%;
  1190. }
  1191. .legend-dot.special-route span {
  1192. position: relative;
  1193. z-index: 3;
  1194. font-weight: bold;
  1195. }
  1196. .legend-dot.special-route::after {
  1197. content: "";
  1198. position: absolute;
  1199. top: 50%;
  1200. left: 50%;
  1201. width: 150%;
  1202. height: 3px;
  1203. background-color: inherit;
  1204. opacity: 0.8;
  1205. transform: translate(-50%, -50%) rotate(-45deg);
  1206. pointer-events: none;
  1207. z-index: 0;
  1208. }
  1209. .legend-dot.special-route::before {
  1210. content: "";
  1211. position: absolute;
  1212. top: 0;
  1213. left: 0;
  1214. width: 100%;
  1215. height: 100%;
  1216. border-radius: 50%;
  1217. z-index: 2;
  1218. background-color: inherit;
  1219. opacity: 1;
  1220. }
  1221. .legend-label {
  1222. flex: 1;
  1223. color: #d0d9e2;
  1224. font-size: 13px;
  1225. }
  1226. .legend-status {
  1227. font-size: 11px;
  1228. color: #5b7da8;
  1229. }
  1230. .all-select {
  1231. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  1232. padding-bottom: 12px;
  1233. margin-bottom: 12px !important;
  1234. }
  1235. .all-select .legend-dot {
  1236. border-radius: 2px;
  1237. transition: all 0.3s;
  1238. width: 10px;
  1239. height: 10px;
  1240. }
  1241. .legend-dot.is-status-wrapper {
  1242. width: 28px;
  1243. height: 28px;
  1244. background-color: transparent !important;
  1245. box-shadow: none !important;
  1246. border: none !important;
  1247. margin-right: 0;
  1248. transform: translateX(-15%);
  1249. }
  1250. .status-icon {
  1251. width: 100%;
  1252. height: 100%;
  1253. object-fit: contain;
  1254. display: block;
  1255. }
  1256. ::v-deep .pure-light-node {
  1257. width: 16px;
  1258. height: 16px;
  1259. border-radius: 50%;
  1260. border: 2px solid rgba(255, 255, 255, 0.8);
  1261. cursor: pointer;
  1262. transition: all 0.3s;
  1263. display: flex;
  1264. justify-content: center;
  1265. align-items: center;
  1266. color: #fff;
  1267. pointer-events: auto;
  1268. }
  1269. ::v-deep .pure-light-node.route-node {
  1270. position: relative;
  1271. overflow: visible;
  1272. }
  1273. ::v-deep .pure-light-node.route-node::after {
  1274. content: "";
  1275. position: absolute;
  1276. top: 50%;
  1277. left: 50%;
  1278. width: 150%;
  1279. height: 3px;
  1280. background-color: inherit;
  1281. opacity: 0.8;
  1282. transform: translate(-50%, -50%) rotate(-45deg);
  1283. pointer-events: none;
  1284. }
  1285. ::v-deep .pure-light-node.route-node span {
  1286. position: relative;
  1287. z-index: 1;
  1288. }
  1289. /* 异常状态增加稍微剧烈一点的呼吸感,但缩小范围 */
  1290. @keyframes light-breathe {
  1291. 0% {
  1292. transform: scale(0.9);
  1293. opacity: 0.8;
  1294. }
  1295. 50% {
  1296. transform: scale(1.1);
  1297. opacity: 1;
  1298. }
  1299. 100% {
  1300. transform: scale(0.9);
  1301. opacity: 0.8;
  1302. }
  1303. }
  1304. /* 首页展示时,如果觉得还是太密,可以给非异常节点降权 */
  1305. ::v-deep .pure-light-node:not(.abnormal-node) {
  1306. border: 1px solid rgba(255, 255, 255, 0.4);
  1307. }
  1308. </style>