map3Data.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <template>
  2. <div>
  3. <div style="width:800px;height:600px" ref="chartsDOM"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import * as echarts from "echarts";
  8. import shandong from "@views/tj/areaJson/shandong.json"
  9. import {getAction} from "@api/manage";
  10. export default {
  11. name: "mapData",
  12. data() {
  13. return {
  14. resdata: [],
  15. yData: [],
  16. barData: [],
  17. tem_title: "",
  18. centerData: {},
  19. myChart: null,
  20. tem_resultMapData: {},
  21. tem_data: {},
  22. visible: false,
  23. max1: 100,
  24. areaData: "", //地区数据,
  25. tem_areaData: "",//临时数据
  26. areaUrl: "",
  27. options: {},
  28. myTool1_show: false,
  29. rangeMax: 200,
  30. rangeMin: 0,
  31. }
  32. },
  33. mounted() {
  34. },
  35. watch: {
  36. resultMapData: {
  37. deep: true,
  38. handler(newVal, oldVal) {
  39. this.tem_data = newVal
  40. this.$nextTick(function () {
  41. for (var i = 0; i < newVal.length; i++) {
  42. this.barData.push(newVal[i]);
  43. this.yData.push(i + newVal[i].name);
  44. }
  45. this.getPie()
  46. })
  47. // 获取组件允许最大值
  48. // this.rangeMax = Math.max.apply(Math, newVal.map(item => item.value));
  49. // 获取组件允许最小值
  50. // this.rangeMin = Math.min.apply(Math, newVal.map(item => item.value));
  51. }
  52. },
  53. tem_data: {
  54. deep: true,
  55. handler(newVal, oldVal) {
  56. if (oldVal != "") {
  57. this.tem_resultMapData = oldVal
  58. this.getPie()
  59. }
  60. }
  61. }
  62. },
  63. created() {
  64. this.initMap()
  65. },
  66. props: {
  67. resultMapData: {
  68. type: Array,
  69. default: [{name: '济南市', value: 496, ssqy: 200, szdw: 296},
  70. {name: '青岛市', value: 66, ssqy: 200, szdw: 296},
  71. {name: '烟台市', value: 222, ssqy: 200, szdw: 296},
  72. {name: '潍坊市', value: 688, ssqy: 200, szdw: 296},
  73. {name: '菏泽市', value: 75, ssqy: 200, szdw: 296},
  74. {name: '日照市', value: 121, ssqy: 200, szdw: 296},
  75. {name: '威海市', value: 91, ssqy: 200, szdw: 296},
  76. {name: '枣庄市', value: 479, ssqy: 200, szdw: 296},
  77. {name: '临沂市', value: 34, ssqy: 200, szdw: 296},
  78. {name: '滨州市', value: 631, ssqy: 200, szdw: 296},
  79. {name: '东营市', value: 400, ssqy: 200, szdw: 296},
  80. {name: '淄博市', value: 988, ssqy: 200, szdw: 296},
  81. {name: '泰安市', value: 693, ssqy: 200, szdw: 296},
  82. {name: '聊城市', value: 934, ssqy: 200, szdw: 296},
  83. {name: '济宁市', value: 748, ssqy: 200, szdw: 296},
  84. {name: '德州市', value: 900, ssqy: 200, szdw: 296},]
  85. },
  86. titles: {
  87. type: Object,
  88. }
  89. },
  90. methods: {
  91. initMap() {
  92. this.areaData = require("@views/tj/areaJson/shandong.json")
  93. this.setCenter(shandong)
  94. this.tem_title = ""
  95. },
  96. setCenter(data) {
  97. var arr = data.features
  98. arr.length > 0 && arr.forEach((item, index) => {
  99. var obj = {}
  100. this.centerData[item.properties.name] = item.properties.center
  101. })
  102. },
  103. getPie() {
  104. var _this = this
  105. var myChart = echarts.init(this.$refs["chartsDOM"]);
  106. document.oncontextmenu = function () {
  107. return false;
  108. };
  109. // 获取组件允许最大值
  110. this.rangeMax = Math.max.apply(Math, this.tem_data.map(item => item.value));
  111. // 获取组件允许最小值
  112. this.rangeMin = Math.min.apply(Math, this.tem_data.map(item => item.value));
  113. // 显示 loading 动画
  114. myChart.showLoading();
  115. myChart.on("contextmenu", (params) => {
  116. if (_this.areaData.features[0].properties.level == 'district') {
  117. this.areaData = require("@views/tj/areaJson/shandong.json")
  118. this.setCenter(_this.areaData)
  119. this.tem_data = this.tem_resultMapData
  120. this.tem_title = ""
  121. this.$emit('visible', {xzqh: ""});
  122. this.myTool1_show = false
  123. }
  124. })
  125. _this.tem_areaData = _this.areaData
  126. myChart.on("click", (params) => {
  127. _this.tem_title = params.data.name
  128. _this.myTool1_show = true
  129. if (_this.areaData.features[0].properties.level == 'city') {
  130. _this.$emit('visible', {xzqh: params.data.xzqhdm, xzqhmc: params.data.name});
  131. _this.areaData = require("@views/tj/GeographicDataJson/" + params.data.name + ".json")
  132. _this.setCenter(_this.areaData)
  133. if (this.titles.orgCode == "A04") {
  134. getAction("/qcsb.qyxx/qcQyxx/dtdktjSQByxq", {orgCode: "A04", xzqh: params.data.xzqhdm}).then(res => {
  135. if (res.code == 200) {
  136. _this.tem_data = res.result
  137. }
  138. })
  139. } else if (this.titles.orgCode == "A03") {
  140. getAction("/qcsb.qyxx/qcQyxx/dtdktjSQByxq", {orgCode: "A03", xzqh: params.data.xzqhdm}).then(res => {
  141. if (res.code == 200) {
  142. _this.tem_data = res.result
  143. }
  144. })
  145. }
  146. } else if (_this.tem_areaData.features[0].properties.level == 'district') {
  147. _this.$emit('visible', {xzqh: params.data.xzqhdm, sfsb: "3"});
  148. // var areaDataItem = _this.areaData.features.filter(item => item.properties.name == params.data.name)
  149. // console.log(areaDataItem);
  150. // _this.areaData = {
  151. // "type": "FeatureCollection",
  152. // "features": areaDataItem
  153. // }
  154. // console.log(_this.areaData);
  155. // _this.setCenter(_this.areaData)
  156. // _this.resultMapData = [{
  157. // "xzqhdm": "3717",
  158. // "value2": 38456.0543,
  159. // "name": "潍城区",
  160. // "value": 220
  161. // }]
  162. }
  163. })
  164. // 再得到数据的基础上,进行地图绘制
  165. // 得到结果后,关闭动画
  166. myChart.hideLoading();
  167. // 注册地图(数据放在axios返回对象的data中哦)
  168. echarts.registerMap('SD', this.areaData);
  169. this.options = {
  170. title: [{
  171. show: true,
  172. text: this.tem_title ? this.tem_title + this.titles.title : '山东省' + this.titles.title,
  173. }],
  174. toolbox: {
  175. orient: 'vertical',
  176. right: '5%',
  177. top: '3%',
  178. itemSize: 15,
  179. itemGap: 25,
  180. feature: {
  181. myTool1: {
  182. show: this.myTool1_show,
  183. title: '返回上级',
  184. icon: 'path://M250.283494 0.000618a45.730811 45.730811 0 0 0-32.753149 13.595647L21.011454 210.115156a45.730811 45.730811 0 0 0 0 65.506297L53.764602 308.992586l164.383727 163.147759a43.876859 43.876859 0 0 0 32.753149 13.595647 45.730811 45.730811 0 0 0 32.753149-13.595647 46.348795 46.348795 0 0 0 0-65.506297l-123.596788-123.596787h460.398033a332.475358 332.475358 0 0 1 330.621406 257.081317 323.823582 323.823582 0 0 1-316.407776 389.947864H48.202747a48.202747 48.202747 0 0 0-48.202747 48.202747 44.494843 44.494843 0 0 0 44.494843 44.494843h591.410627A415.903189 415.903189 0 0 0 1050.572691 596.9731a432.588755 432.588755 0 0 0-432.588755-405.397462H170.563566l112.473077-112.473076a46.348795 46.348795 0 0 0 0-65.506297 45.730811 45.730811 0 0 0-32.753149-13.595647z',
  185. onclick: function () {
  186. if (_this.areaData.features[0].properties.level == 'district') {
  187. _this.areaData = require("@views/tj/areaJson/shandong.json")
  188. _this.setCenter(_this.areaData)
  189. _this.tem_data = _this.tem_resultMapData
  190. _this.tem_title = ""
  191. _this.$emit('visible', {xzqh: ""});
  192. _this.myTool1_show = false
  193. }
  194. }
  195. },
  196. }
  197. },
  198. tooltip: {
  199. triggerOn: "mousemove", //mousemove、click
  200. padding: 8,
  201. borderWidth: 1,
  202. borderColor: '#409eff',
  203. backgroundColor: 'rgba(255,255,255,0.9)',
  204. formatter: function (params) {
  205. return params.name + ':' + '</br>' + "地块数量:" + params.value + '块' + '</br>' + "实际占用总面积:" + parseFloat(params.data.value2).toFixed(2) + "亩"
  206. },
  207. },
  208. visualMap: {
  209. type: 'continuous',
  210. orient: 'horizontal',
  211. itemWidth: 10,
  212. itemHeight: 80,
  213. text: ['高', '低'],
  214. showLabel: false,
  215. seriesIndex: [0],
  216. // min: 0,
  217. min: this.rangeMin,
  218. max: this.rangeMax,
  219. inRange: {
  220. color: ['#ADD6F1', '#26AEFB', '#0290EB'] // 渐变颜色
  221. },
  222. textStyle: {
  223. color: '#7B93A7'
  224. },
  225. bottom: 30,
  226. left: 'left',
  227. },
  228. geo: {
  229. roam: false,
  230. map: 'SD',
  231. select: { //选中显示设置
  232. label: {
  233. show: false,
  234. },
  235. },
  236. // layoutSize: '80%',
  237. label: {
  238. normal: {
  239. show: false, //显示省份标签
  240. },
  241. emphasis: { //对应的鼠标悬浮效果
  242. show: false,
  243. textStyle: {
  244. color: "#000"
  245. }
  246. }
  247. },
  248. itemStyle: {
  249. emphasis: {
  250. areaColor: '#fff464'
  251. }
  252. }
  253. },
  254. series: [{
  255. name: 'mapSer',
  256. type: 'map',
  257. roam: false,
  258. geoIndex: 0,
  259. label: {
  260. show: false,
  261. fontSize: 0,
  262. },
  263. data: this.tem_data
  264. }]
  265. };
  266. myChart.clear();
  267. console.log("tem_data", this.tem_data);
  268. myChart.setOption(this.options, true);
  269. myChart.resize();
  270. //地图的点击事件
  271. var option = {
  272. xAxis: [],
  273. yAxis: [],
  274. grid: [],
  275. series: [],
  276. };
  277. echarts.util.each(_this.tem_data, function (dataItem, idx) {
  278. var geoCoord = _this.centerData[dataItem.name];
  279. var coord = myChart.convertToPixel('geo', geoCoord);
  280. idx += '';
  281. var inflationData = [dataItem.value];
  282. option.xAxis.push({
  283. id: idx,
  284. gridId: idx,
  285. type: 'category',
  286. nameLocation: 'middle',
  287. name: dataItem.name,
  288. nameGap: 3,
  289. nameTextStyle: {
  290. color: "#000000",
  291. },
  292. splitLine: {
  293. show: false
  294. },
  295. axisTick: {
  296. show: false
  297. },
  298. axisLabel: {
  299. color: "#fff",
  300. show: false
  301. },
  302. axisLine: {
  303. onZero: false,
  304. lineStyle: {
  305. color: '#555'
  306. }
  307. },
  308. data: ["地块数量"],
  309. z: 100
  310. });
  311. option.yAxis.push({
  312. id: idx,
  313. gridId: idx,
  314. splitLine: {
  315. show: false
  316. },
  317. axisTick: {
  318. show: false
  319. },
  320. axisLabel: {
  321. show: false
  322. },
  323. axisLine: {
  324. show: false,
  325. lineStyle: {
  326. color: '#fff'
  327. }
  328. },
  329. min: 0,
  330. max: 1000,
  331. z: 100
  332. });
  333. option.grid.push({
  334. id: idx,
  335. width: 15,
  336. height: 35,
  337. left: coord[0] - 15,
  338. top: coord[1] - 30,
  339. z: 100
  340. });
  341. option.series.push({
  342. id: idx,
  343. type: 'bar',
  344. xAxisId: idx,
  345. yAxisId: idx,
  346. barGap: 0,
  347. barCategoryGap: 0,
  348. data: inflationData,
  349. label: {
  350. normal: {
  351. show: true,//开启显示
  352. position: 'top',//柱形上方
  353. textStyle: { //数值样式
  354. color: '#000000'
  355. }
  356. }
  357. },
  358. z: 100,
  359. itemStyle: {
  360. normal: {
  361. barBorderRadius: [5, 5, 0, 0],
  362. color: new echarts.graphic.LinearGradient(
  363. 0, 0, 0, 1, [{
  364. offset: 0,
  365. color: '#FE735A'
  366. },
  367. {
  368. offset: 1,
  369. color: '#f1cb07'
  370. }
  371. ]
  372. )
  373. }
  374. }
  375. });
  376. })
  377. myChart.setOption(option);
  378. },
  379. }
  380. }
  381. </script>
  382. <style scoped>
  383. </style>