widgetLineMap.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <template>
  2. <div :style="styleObj">
  3. <v-chart :options="options" autoresize/>
  4. </div>
  5. </template>
  6. <script>
  7. import "echarts/map/js/china.js";
  8. import echarts from "echarts";
  9. import {conversionCity} from '@/utils/china';
  10. /*let geoCoordMap = {
  11. 上海市: [121.4648, 31.2891],
  12. 东莞市: [113.8953, 22.901],
  13. 东营市: [118.7073, 37.5513],
  14. 中山市: [113.4229, 22.478],
  15. 临汾市: [111.4783, 36.1615],
  16. 临沂市: [118.3118, 35.2936],
  17. 丹东市: [124.541, 40.4242],
  18. 丽水市: [119.5642, 28.1854],
  19. 乌鲁木齐市: [87.9236, 43.5883],
  20. 佛山市: [112.8955, 23.1097],
  21. 保定市: [115.0488, 39.0948],
  22. 兰州市: [103.5901, 36.3043],
  23. 包头市: [110.3467, 41.4899],
  24. 北京市: [116.4551, 40.2539],
  25. 北海市: [109.314, 21.6211],
  26. 南京市: [118.8062, 31.9208],
  27. 南宁市: [108.479, 23.1152],
  28. 南昌市: [116.0046, 28.6633],
  29. 南通市: [121.1023, 32.1625],
  30. 厦门市: [118.1689, 24.6478],
  31. 台州市: [121.1353, 28.6688],
  32. 合肥市: [117.29, 32.0581],
  33. 呼和浩特市: [111.4124, 40.4901],
  34. 咸阳市: [108.4131, 34.8706],
  35. 哈尔滨市: [127.9688, 45.368],
  36. 唐山市: [118.4766, 39.6826],
  37. 嘉兴市: [120.9155, 30.6354],
  38. 大同市: [113.7854, 39.8035],
  39. 大连市: [122.2229, 39.4409],
  40. 天津市: [117.4219, 39.4189],
  41. 太原市: [112.3352, 37.9413],
  42. 威海市: [121.9482, 37.1393],
  43. 宁波市: [121.5967, 29.6466],
  44. 宝鸡市: [107.1826, 34.3433],
  45. 宿迁市: [118.5535, 33.7775],
  46. 常州市: [119.4543, 31.5582],
  47. 广州市: [113.5107, 23.2196],
  48. 廊坊市: [116.521, 39.0509],
  49. 延安市: [109.1052, 36.4252],
  50. 张家口市: [115.1477, 40.8527],
  51. 徐州市: [117.5208, 34.3268],
  52. 德州市: [116.6858, 37.2107],
  53. 惠州市: [114.6204, 23.1647],
  54. 成都市: [103.9526, 30.7617],
  55. 扬州市: [119.4653, 32.8162],
  56. 承德市: [117.5757, 41.4075],
  57. 拉萨市: [91.1865, 30.1465],
  58. 无锡市: [120.3442, 31.5527],
  59. 日照市: [119.2786, 35.5023],
  60. 昆明市: [102.9199, 25.4663],
  61. 杭州市: [119.5313, 29.8773],
  62. 枣庄市: [117.323, 34.8926],
  63. 柳州市: [109.3799, 24.9774],
  64. 株洲市: [113.5327, 27.0319],
  65. 武汉市: [114.3896, 30.6628],
  66. 汕头市: [117.1692, 23.3405],
  67. 江门市: [112.6318, 22.1484],
  68. 沈阳市: [123.1238, 42.1216],
  69. 沧州市: [116.8286, 38.2104],
  70. 河源市: [114.917, 23.9722],
  71. 泉州市: [118.3228, 25.1147],
  72. 泰安市: [117.0264, 36.0516],
  73. 泰州市: [120.0586, 32.5525],
  74. 济南市: [117.1582, 36.8701],
  75. 济宁市: [116.8286, 35.3375],
  76. 海口市: [110.3893, 19.8516],
  77. 淄博市: [118.0371, 36.6064],
  78. 淮安市: [118.927, 33.4039],
  79. 深圳市: [114.5435, 22.5439],
  80. 清远市: [112.9175, 24.3292],
  81. 温州市: [120.498, 27.8119],
  82. 渭南市: [109.7864, 35.0299],
  83. 湖州市: [119.8608, 30.7782],
  84. 湘潭市: [112.5439, 27.7075],
  85. 滨州市: [117.8174, 37.4963],
  86. 潍坊市: [119.0918, 36.524],
  87. 烟台市: [120.7397, 37.5128],
  88. 玉溪市: [101.9312, 23.8898],
  89. 珠海市: [113.7305, 22.1155],
  90. 盐城市: [120.2234, 33.5577],
  91. 盘锦市: [121.9482, 41.0449],
  92. 石家庄市: [114.4995, 38.1006],
  93. 福州市: [119.4543, 25.9222],
  94. 秦皇岛市: [119.2126, 40.0232],
  95. 绍兴市: [120.564, 29.7565],
  96. 聊城市: [115.9167, 36.4032],
  97. 肇庆市: [112.1265, 23.5822],
  98. 舟山市: [122.2559, 30.2234],
  99. 苏州市: [120.6519, 31.3989],
  100. 莱芜市: [117.6526, 36.2714],
  101. 菏泽市: [115.6201, 35.2057],
  102. 营口市: [122.4316, 40.4297],
  103. 葫芦岛市: [120.1575, 40.578],
  104. 衡水市: [115.8838, 37.7161],
  105. 衢州市: [118.6853, 28.8666],
  106. 西宁市: [101.4038, 36.8207],
  107. 西安市: [109.1162, 34.2004],
  108. 贵阳市: [106.6992, 26.7682],
  109. 连云港市: [119.1248, 34.552],
  110. 邢台市: [114.8071, 37.2821],
  111. 邯郸市: [114.4775, 36.535],
  112. 郑州市: [113.4668, 34.6234],
  113. 鄂尔多斯市: [108.9734, 39.2487],
  114. 重庆市: [107.7539, 30.1904],
  115. 金华市: [120.0037, 29.1028],
  116. 铜川市: [109.0393, 35.1947],
  117. 银川市: [106.3586, 38.1775],
  118. 镇江市: [119.4763, 31.9702],
  119. 长春市: [125.8154, 44.2584],
  120. 长沙市: [113.0823, 28.2568],
  121. 长治市: [112.8625, 36.4746],
  122. 阳泉市: [113.4778, 38.0951],
  123. 青岛市: [120.4651, 36.3373],
  124. 韶关市: [113.7964, 24.7028]
  125. };*/
  126. let geoCoordMap = conversionCity;
  127. let pointSize = 3;
  128. let planePath =
  129. "path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z";
  130. export default {
  131. name: "widgetMap",
  132. props: {
  133. value: Object,
  134. ispreview: Boolean
  135. },
  136. data() {
  137. return {
  138. options: {
  139. title: {
  140. left: "center",
  141. textStyle: {
  142. color: "#fff"
  143. }
  144. },
  145. tooltip: {
  146. trigger: 'item',
  147. formatter: function (params, ticket, callback) {
  148. if (params.seriesType == "effectScatter") {
  149. return "线路:" + params.data.name + "" + params.data.value[2];
  150. } else if (params.seriesType == "lines") {
  151. return params.data.fromName + ">" + params.data.toName + "<br />" + params.data.value;
  152. } else {
  153. return params.name;
  154. }
  155. }
  156. },
  157. legend: {
  158. show: true,
  159. orient: 'vertical',
  160. top: 'bottom',
  161. left: 'right',
  162. textStyle: {
  163. color: '#fff'
  164. },
  165. selectedMode: 'multiple',
  166. },
  167. geo: {
  168. map: "china",
  169. label: {
  170. emphasis: {
  171. show: true,
  172. color: "white"
  173. }
  174. },
  175. roam: true,
  176. itemStyle: {
  177. normal: {
  178. areaColor: "#323c48",
  179. borderColor: "#404a59",
  180. borderWidth: 1,
  181. },
  182. emphasis: {
  183. areaColor: "#2a333d"
  184. }
  185. },
  186. },
  187. series: [
  188. {
  189. //name: tempData[0],
  190. type: "lines",
  191. zlevel: 1,
  192. effect: {
  193. show: false,
  194. period: 6,
  195. trailLength: 0.7,
  196. color: "#fff",
  197. symbolSize: 3
  198. },
  199. lineStyle: {
  200. normal: {
  201. color: '#a6c84c',
  202. width: 0,
  203. curveness: 0.2
  204. }
  205. },
  206. data: [],
  207. },
  208. {
  209. type: "lines",
  210. zlevel: 2,
  211. symbol: ['none', 'arrow'],
  212. symbolSize: 10,
  213. effect: {
  214. show: true,
  215. period: 4,
  216. trailLength: 0,
  217. symbol: 'arrow',
  218. symbolSize: 5
  219. },
  220. lineStyle: {
  221. normal: {
  222. // 颜色+ 线条
  223. color: '#ffa022',
  224. width: 1,
  225. opacity: 0.4,
  226. curveness: 0.2
  227. }
  228. },
  229. data: [],
  230. },
  231. {
  232. // 起点
  233. //name: tempData[0],
  234. type: 'effectScatter',
  235. coordinateSystem: 'geo',
  236. zlevel: 2,
  237. rippleEffect: {
  238. brushType: 'stroke'
  239. },
  240. label: {
  241. normal: {
  242. show: true,
  243. position: 'right',
  244. formatter: '{b}',
  245. fontSize: 22,
  246. }
  247. },
  248. // 点的大小
  249. symbolSize: function (val) {
  250. return val[2] / pointSize;
  251. },
  252. itemStyle: {
  253. normal: {
  254. // 地图点颜色
  255. color: '#46bee9'
  256. }
  257. },
  258. data: [],
  259. },
  260. {
  261. // 终点
  262. //name: tempData[0],
  263. type: 'effectScatter',
  264. coordinateSystem: 'geo',
  265. zlevel: 2,
  266. rippleEffect: {
  267. brushType: 'stroke'
  268. },
  269. label: {
  270. normal: {
  271. show: true,
  272. position: 'right',
  273. formatter: '{b}',
  274. fontSize: 22,
  275. }
  276. },
  277. // 点的大小
  278. symbolSize: function (val) {
  279. return val[2] / pointSize;
  280. },
  281. itemStyle: {
  282. normal: {
  283. // 地图点颜色
  284. color: '#46bee9'
  285. }
  286. },
  287. data: [],
  288. },
  289. ]
  290. },
  291. optionsSetup: {}
  292. };
  293. },
  294. computed: {
  295. styleObj() {
  296. return {
  297. position: this.ispreview ? "absolute" : "static",
  298. width: this.optionsStyle.width + "px",
  299. height: this.optionsStyle.height + "px",
  300. left: this.optionsStyle.left + "px",
  301. top: this.optionsStyle.top + "px",
  302. background: this.optionsSetup.background
  303. };
  304. }
  305. },
  306. watch: {
  307. value: {
  308. handler(val) {
  309. this.optionsStyle = val.position;
  310. this.optionsData = val.data;
  311. this.optionsSetup = val.setup;
  312. this.editorOptions();
  313. },
  314. deep: true
  315. }
  316. },
  317. created() {
  318. this.optionsStyle = this.value.position;
  319. this.optionsData = this.value.data;
  320. this.optionsSetup = this.value.setup;
  321. },
  322. mounted() {
  323. this.editorOptions();
  324. },
  325. methods: {
  326. convertData(data) {
  327. let res = [];
  328. for (let i = 0; i < data.length; i++) {
  329. let dataItem = data[i];
  330. let sourceCoord = geoCoordMap[dataItem.source];
  331. let targetCoord = geoCoordMap[dataItem.target];
  332. if (sourceCoord && targetCoord) {
  333. res.push({
  334. fromName: dataItem.source,
  335. toName: dataItem.target,
  336. coords: [sourceCoord, targetCoord],
  337. value: dataItem.value,
  338. }
  339. )
  340. }
  341. ;
  342. }
  343. return res;
  344. },
  345. editorOptions() {
  346. this.setOptionsTitle();
  347. //this.setOptionsText();
  348. this.setOptionsSymbol();
  349. //this.setOptionsPoint();
  350. this.setOptionsLine();
  351. this.setOptionsSource();
  352. this.setOptionsTarget();
  353. this.setOptionsColor();
  354. this.setOptionsData();
  355. },
  356. // 标题设置
  357. setOptionsTitle() {
  358. const optionsSetup = this.optionsSetup;
  359. const title = {};
  360. title.show = optionsSetup.isNoTitle;
  361. title.text = optionsSetup.titleText;
  362. title.left = optionsSetup.textAlign;
  363. title.textStyle = {
  364. color: optionsSetup.textColor,
  365. fontSize: optionsSetup.textFontSize,
  366. fontWeight: optionsSetup.textFontWeight
  367. };
  368. title.subtext = optionsSetup.subText;
  369. title.subtextStyle = {
  370. color: optionsSetup.subTextColor,
  371. fontWeight: optionsSetup.subTextFontWeight,
  372. fontSize: optionsSetup.subTextFontSize
  373. };
  374. this.options.title = title;
  375. },
  376. // 起点设置
  377. setOptionsSource(){
  378. const optionsSetup = this.optionsSetup;
  379. const series = this.options.series[2];
  380. const normal = {
  381. show: optionsSetup.isShowSource,
  382. position: 'right',
  383. color: optionsSetup.sourceFontTextColor,
  384. fontSize: optionsSetup.sourceFontTextSize,
  385. fontWeight: optionsSetup.sourceFontTextWeight,
  386. };
  387. const itemStyle = {
  388. normal: {
  389. color: optionsSetup.sourcePointColor,
  390. }
  391. };
  392. pointSize = optionsSetup.sourcePointSize;
  393. series.label.normal = normal;
  394. series.itemStyle = itemStyle;
  395. },
  396. // 终点设置
  397. setOptionsTarget(){
  398. const optionsSetup = this.optionsSetup;
  399. const series = this.options.series[3];
  400. const normal = {
  401. show: optionsSetup.isShowTarget,
  402. position: 'right',
  403. color: optionsSetup.targetFontTextColor,
  404. fontSize: optionsSetup.targetFontTextSize,
  405. fontWeight: optionsSetup.targetFontTextWeight,
  406. };
  407. const itemStyle = {
  408. normal: {
  409. color: optionsSetup.targetPointColor,
  410. }
  411. };
  412. pointSize = optionsSetup.targetPointSize;
  413. series.label.normal = normal;
  414. series.itemStyle = itemStyle;
  415. },
  416. // 地图字体设置
  417. setOptionsText() {
  418. const optionsSetup = this.optionsSetup;
  419. const series = this.options.series;
  420. const normal = {
  421. show: true,
  422. position: 'right',
  423. color: optionsSetup.fontTextColor,
  424. fontSize: optionsSetup.fontTextSize,
  425. fontWeight: optionsSetup.fontTextWeight,
  426. }
  427. series[2].label["normal"] = normal;
  428. series[3].label["normal"] = normal;
  429. },
  430. // 图标设置
  431. setOptionsSymbol(){
  432. const optionsSetup = this.optionsSetup;
  433. const series = this.options.series[1];
  434. const effect = {
  435. show: true,
  436. period: this.setPeriod(optionsSetup),
  437. trailLength: 0,
  438. symbol: this.setSymbol(optionsSetup),
  439. symbolSize: optionsSetup.symbolSize,
  440. color: optionsSetup.symbolColor,
  441. };
  442. series['effect'] = effect;
  443. },
  444. setSymbol(optionsSetup) {
  445. let symbol;
  446. if (optionsSetup.symbol == 'plane') {
  447. symbol = planePath;
  448. } else {
  449. symbol = "arrow";
  450. }
  451. return symbol;
  452. },
  453. setPeriod(optionsSetup){
  454. let period;
  455. if (optionsSetup.symbol == 'plane') {
  456. period = optionsSetup.symbolPeriod - 1;
  457. }else {
  458. period = optionsSetup.symbolPeriod;
  459. }
  460. return period;
  461. },
  462. // 点设置
  463. setOptionsPoint() {
  464. const optionsSetup = this.optionsSetup;
  465. const series = this.options.series;
  466. pointSize = optionsSetup.pointSize
  467. const itemStyle = {
  468. normal: {
  469. color: optionsSetup.pointColor,
  470. }
  471. };
  472. series[2]["itemStyle"] = itemStyle;
  473. series[3]["itemStyle"] = itemStyle;
  474. },
  475. // 线设置
  476. setOptionsLine() {
  477. const optionsSetup = this.optionsSetup;
  478. const series = this.options.series[1];
  479. const lineStyle = {
  480. normal: {
  481. // 线条颜色
  482. color: optionsSetup.lineColor,
  483. width: optionsSetup.lineWidth,
  484. opacity: 0.4,
  485. curveness: 0.2
  486. }
  487. };
  488. series['lineStyle'] = lineStyle;
  489. },
  490. // 地图颜色设置
  491. setOptionsColor() {
  492. const optionsSetup = this.optionsSetup;
  493. const itemStyle = {
  494. normal: {
  495. // 地图的颜色
  496. areaColor: optionsSetup.blockColor,
  497. borderColor: optionsSetup.borderColor,
  498. },
  499. emphasis: {
  500. // 地图块颜色
  501. areaColor: optionsSetup.highlightColor,
  502. }
  503. };
  504. this.options.geo["itemStyle"] = itemStyle;
  505. },
  506. //数据解析
  507. setOptionsData() {
  508. const optionsData = this.optionsData; // 数据类型 静态 or 动态
  509. optionsData.dataType == "staticData"
  510. ? this.staticDataFn(optionsData.staticData)
  511. : this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
  512. },
  513. staticDataFn(val) {
  514. const series = this.options.series;
  515. series[0]["data"] = this.convertData(val);
  516. series[1]["data"] = this.convertData(val);
  517. series[2]["data"] = val.map(function (dataItem) {
  518. return {
  519. name: dataItem.source,
  520. value: geoCoordMap[dataItem.source].concat([dataItem.value])
  521. }
  522. });
  523. series[3]["data"] = val.map(function (dataItem) {
  524. return {
  525. name: dataItem.target,
  526. value: geoCoordMap[dataItem.target].concat([dataItem.value])
  527. }
  528. });
  529. },
  530. dynamicDataFn(val, refreshTime) {
  531. if (!val) return;
  532. if (this.ispreview) {
  533. this.getEchartData(val);
  534. this.flagInter = setInterval(() => {
  535. this.getEchartData(val);
  536. }, refreshTime);
  537. } else {
  538. this.getEchartData(val);
  539. }
  540. },
  541. getEchartData(val) {
  542. const data = this.queryEchartsData(val);
  543. data.then(res => {
  544. this.renderingFn(res);
  545. });
  546. },
  547. renderingFn(val) {
  548. const series = this.options.series;
  549. series[0]["data"] = this.convertData(val);
  550. series[1]["data"] = this.convertData(val);
  551. series[2]["data"] = val.map(function (dataItem) {
  552. return {
  553. name: dataItem.source,
  554. value: geoCoordMap[dataItem.source].concat([dataItem.value])
  555. }
  556. });
  557. series[3]["data"] = val.map(function (dataItem) {
  558. return {
  559. name: dataItem.target,
  560. value: geoCoordMap[dataItem.target].concat([dataItem.value])
  561. }
  562. });
  563. }
  564. }
  565. };
  566. </script>
  567. <style lang="scss" scoped>
  568. .echartMap {
  569. width: 100%;
  570. height: 100%;
  571. }
  572. .echarts {
  573. width: 100%;
  574. height: 100%;
  575. overflow: hidden;
  576. }
  577. </style>