TongzhouTrafficMap.vue 47 KB

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