map3Data.vue 12 KB

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