jlMap.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <!-- <div style="height:100%"> -->
  3. <div id="map1" style="width: 100%;height:100%"></div>
  4. <!-- </div> -->
  5. </template>
  6. <script>
  7. import echarts from "echarts";
  8. import map from "../../util/jilin";
  9. export default {
  10. name: "jlMapChart",
  11. props: {
  12. data: {
  13. type: Array,
  14. default: () => {
  15. return [];
  16. }
  17. }
  18. // data1: {
  19. // type: Array,
  20. // default: () => {
  21. // return [];
  22. // }
  23. // }
  24. },
  25. data() {
  26. return {
  27. myChart: null
  28. };
  29. },
  30. watch: {
  31. data() {
  32. this.myChart.clear();
  33. this.registerMap1();
  34. }
  35. },
  36. methods: {
  37. registerMap1() {
  38. console.log(this.data)
  39. let myChart = this.$echarts.init(document.getElementById("map1"));
  40. this.myChart = myChart;
  41. // console.log(this.data,"sdsadsadsadsadsadasdsad");
  42. // let data1 = this.data;
  43. echarts.registerMap("吉林", map);
  44. // 每个地区的坐标
  45. var geoCoordMap = {
  46. 长春市: [125.55, 44.18],
  47. // 九台市: [124.35, 43.88],
  48. // 德惠市: [123.35, 43.88],
  49. 四平市: [124.600785, 43.470344],
  50. 辽源市: [125.13, 42.88],
  51. 吉林市: [126.75, 43.33],
  52. 松原市: [124.12, 44.81],
  53. 白城市: [123.14, 45.21],
  54. 白山市: [126.997839, 41.992505],
  55. 通化市: [125.93, 41.73],
  56. 延边朝鲜族自治州: [128.9, 43.12]
  57. };
  58. // 每个地区的设备数量值
  59. var data = this.data;
  60. // 每个地区的设备告警数量
  61. var data2 = [];
  62. var convertData = function(data) {
  63. var res = [];
  64. for (var i = 0; i < data.length; i++) {
  65. var geoCoord = geoCoordMap[data[i].name];
  66. if (geoCoord) {
  67. res.push({
  68. name: data[i].name,
  69. value: geoCoord.concat(data[i].value)
  70. });
  71. }
  72. }
  73. // 有数据的地区的名称和value值
  74. return res;
  75. };
  76. // 设定series是一个空的数组
  77. var series = [];
  78. [["吉林", data]].forEach(function(item) {
  79. series.push(
  80. {
  81. name: "定位点",
  82. type: "effectScatter", // 散点图
  83. coordinateSystem: "geo", // 使用地理坐标系
  84. // hoverAnimation: "true",
  85. // legendHoverLink: "false",
  86. rippleEffect: {
  87. period: 4,
  88. brushType: "stroke",
  89. scale: 3
  90. },
  91. data: convertData(item[1]),
  92. symbolSize: 0.1,
  93. label: {
  94. normal: {
  95. show: true,
  96. formatter: function(params) {
  97. // console.log(params);
  98. return (
  99. "{fline|" +
  100. " " +
  101. data[params.dataIndex].value +
  102. " " +
  103. "户" +
  104. "}"
  105. );
  106. },
  107. position: "bottom",
  108. distance: 20,
  109. // background:require(..),
  110. // backgroundColor: "rgba(255,200,9,.7)",
  111. padding: [0, 0],
  112. borderRadius: 3,
  113. lineHeight: 30,
  114. verticalAlign: "middle",
  115. color: "#ffc809",
  116. rich: {
  117. fline: {
  118. fontSize: 18,
  119. padding: [0, 10],
  120. color: "#ffc809",
  121. fontWeight:900
  122. }
  123. }
  124. }
  125. },
  126. itemStyle: {
  127. normal: {
  128. color: "#ffc809"
  129. }
  130. },
  131. zlevel: 10
  132. },
  133. {
  134. type: "map",
  135. map: "吉林",
  136. zlevel: 10,
  137. // itemStyle: {
  138. // normal: {
  139. // areaColor: "rgba(41,103,160,0.5)",
  140. // borderColor: "#24bae7"
  141. // },
  142. // emphasis: {
  143. // areaColor: "#24bae7"
  144. // }
  145. // },
  146. itemStyle: {
  147. normal: {
  148. areaColor: "#2071b4",
  149. borderColor: "#23b9e8",
  150. borderWidth:2
  151. },
  152. emphasis: {
  153. areaColor: "#23b9e8"
  154. }
  155. },
  156. label: {
  157. normal: {
  158. show: true,
  159. textStyle: {
  160. color: "#fff",
  161. fontSize: 18
  162. }
  163. },
  164. emphasis: {
  165. textStyle: {
  166. color: "#fff",
  167. fontSize: 18
  168. }
  169. }
  170. },
  171. data: data
  172. },
  173. {
  174. name: "点",
  175. type: "scatter",
  176. coordinateSystem: "geo",
  177. symbol: "pin",
  178. symbolSize: 25,
  179. label: {
  180. normal: {
  181. show: true,
  182. textStyle: {
  183. color: "#fff",
  184. fontSize: 14
  185. }
  186. }
  187. },
  188. itemStyle: {
  189. normal: {
  190. color: "#F62157" //标志颜色
  191. }
  192. },
  193. zlevel: 2,
  194. data: convertData(data2)
  195. }
  196. );
  197. });
  198. let option = {
  199. // tooltip: {
  200. // padding: 0,
  201. // enterable: true,
  202. // transitionDuration: 1,
  203. // textStyle: {
  204. // color: "#000",
  205. // decoration: "none"
  206. // },
  207. // formatter: function(params) {
  208. // let tipHtml = "";
  209. // tipHtml =
  210. // '<div style="width:200px;height:150px;background:rgba(20,47,88,0.8);border:1px solid rgba(7,166,255,0.7)">' +
  211. // // '<div style="width:85%;height:40px;line-height:40px;border-bottom:2px solid rgba(7,166,255,0.7);padding:0 20px">' +
  212. // // '<span style="margin-left:10px;color:#fff;font-size:16px;">' +
  213. // // params.name +
  214. // // "</span>" +
  215. // // "</div>" +
  216. // '<div style="padding:20px">' +
  217. // '<p style="color:#fff;font-size:12px;">' +
  218. // "企业名称:" +
  219. // '<span style="color:#ffc809;font-size:1em;margin:0 6px;">' +
  220. // data1[params.dataIndex].qymc +
  221. // "</span>" +
  222. // // "家" +
  223. // "</p>" +
  224. // '<p style="color:#fff;font-size:12px;">' +
  225. // "申请金额:" +
  226. // '<span style="color:#00d8ff;font-size:2em;margin:0 6px;font-family:LCD">' +
  227. // data1[params.dataIndex].sqje +
  228. // "</span>" +
  229. // "万" +
  230. // "</p>" +
  231. // "</p>" +
  232. // '<p style="color:#fff;font-size:12px;">' +
  233. // "推送银行:" +
  234. // '<span style="color:#00d8ff;font-size:1em;margin:0 6px;">' +
  235. // data1[params.dataIndex].tsyh +
  236. // "</span>" +
  237. // // "个" +
  238. // "</p>" +
  239. // "</div>" +
  240. // "</div>";
  241. // // setTimeout(function() {
  242. // // tooltipCharts(params.name);
  243. // // }, 10);
  244. // return tipHtml;
  245. // }
  246. // },
  247. geo: {
  248. map: "吉林",
  249. label: {
  250. textStyle: {
  251. fontSize: ".1rem"
  252. }
  253. },
  254. itemStyle: {
  255. normal: {
  256. areaColor: "#2071b4",
  257. borderColor: "#23b9e8"
  258. },
  259. emphasis: {
  260. areaColor: "#23b9e8"
  261. }
  262. }
  263. },
  264. series: series
  265. };
  266. myChart.setOption(option);
  267. window.addEventListener("resize", function() {
  268. myChart.resize();
  269. });
  270. }
  271. },
  272. mounted() {
  273. this.registerMap1();
  274. }
  275. // watch: {
  276. // data() {
  277. // if (this.myChart != null) {
  278. // this.myChart.clear();
  279. // }
  280. // this.gatherers();
  281. // }
  282. // }
  283. };
  284. </script>
  285. <style scoped>
  286. </style>