chartsJs.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. import jnpf from '@/utils/jnpf'
  2. import {
  3. geojson,
  4. getAtlas
  5. } from '@/api/portal/portal.js'
  6. import {
  7. getDataInterfaceRes
  8. } from '@/api/common'
  9. let timer;
  10. export default {
  11. data() {
  12. return {
  13. show: false,
  14. mapData: [],
  15. mapList: [],
  16. mapType: '',
  17. markPoints: [],
  18. pointLoading: false,
  19. opts: {
  20. update: true,
  21. fontSize: 10,
  22. padding: [40, 15, 30, 15],
  23. extra: {
  24. map: {
  25. mercator: true,
  26. },
  27. },
  28. },
  29. regionStep: [],
  30. stepMapList: [],
  31. option: {}
  32. }
  33. },
  34. created() {
  35. this.init()
  36. if (this.config.dataType === 'dynamic') {
  37. uni.$off('proRefresh')
  38. uni.$on('proRefresh', () => {
  39. this.handelChart()
  40. })
  41. }
  42. },
  43. methods: {
  44. init() {
  45. if (timer) clearInterval(timer)
  46. this.handelChart()
  47. if (!this.config.allRefresh.autoRefresh && this.config?.refresh?.autoRefresh) {
  48. timer = setInterval(this.handelChart, this.config.refresh.autoRefreshTime * 60000)
  49. }
  50. },
  51. async handelChart() {
  52. this.customEchartsKey()
  53. if (this.config.dataType === 'dynamic') {
  54. if (!this.config.propsApi) return
  55. const query = {
  56. paramList: this.config.templateJson
  57. };
  58. getDataInterfaceRes(this.config.propsApi, query).then(res => {
  59. this.config.option.defaultValue = this.handleMappingConfig(res.data, this.config)
  60. this.handleAttrs()
  61. })
  62. } else {
  63. this.handleAttrs()
  64. }
  65. },
  66. // 自定义echarts属性取app的
  67. customEchartsKey() {
  68. this.config.option = {
  69. ...this.config.option,
  70. ...this.config.appOption
  71. }
  72. if (['customEcharts'].includes(this.config.jnpfKey)) {
  73. this.config.dataType = this.config.appDataType
  74. this.config.propsApi = this.config.appPropsApi
  75. this.config.propsName = this.config.appPropsName
  76. this.config.templateJson = this.config.appTemplateJson
  77. this.config.refresh = this.config.appRefresh ? this.config.appRefresh : {}
  78. }
  79. this.config.option.urlAddress = this.config.option.appUrlAddress
  80. },
  81. // 处理字段映射
  82. handleMappingConfig(resultData, config) {
  83. let defaultValue = undefined
  84. if (['rankList', 'barChart', 'pieChart', 'tableList'].includes(this.config.jnpfKey)) {
  85. defaultValue = this.config.option.defaultValue || []
  86. }
  87. let mappingConfig = config.mappingConfig
  88. let result = []
  89. resultData.forEach(data => {
  90. let temp = {}
  91. for (let item of mappingConfig) {
  92. if (item.field === '系列') {
  93. temp['type'] = item.value ? data[item.value] : data['type']
  94. }
  95. if (item.field === '维度') {
  96. temp['name'] = item.value ? data[item.value] : data['name']
  97. }
  98. if (item.field === '数值') {
  99. temp['value'] = item.value ? data[item.value] : data['value']
  100. }
  101. if (item.field === '最大值') {
  102. temp['max'] = item.value ? data[item.value] : data['max']
  103. }
  104. if (item.field === '时间戳') {
  105. temp['timestamp'] = item.value ? data[item.value] : data['timestamp']
  106. }
  107. if (item.field === '经度') {
  108. temp['long'] = item.value ? data[item.value] : data['long']
  109. }
  110. if (item.field === '纬度') {
  111. temp['lat'] = item.value ? data[item.value] : data['lat']
  112. }
  113. }
  114. result.push(temp)
  115. })
  116. return result
  117. },
  118. handleParam(e) {
  119. let jnpfKey = this.config.jnpfKey
  120. if (jnpfKey == 'customEcharts') return
  121. let item = {}
  122. let choose = e.opts.series && e.opts.series[0]
  123. let chooseIndex = e.currentIndex['index']
  124. let name = ''
  125. let type = ''
  126. let value = ''
  127. if (jnpfKey === "barChart") {
  128. name = e.opts.categories[chooseIndex]
  129. value = choose.data[chooseIndex]
  130. type = choose.name
  131. }
  132. if (jnpfKey === "pieChart") {
  133. name = choose.name
  134. value = choose.data
  135. let series = this.option.chartData.series && this.option.chartData.series[0]
  136. type = series.name
  137. }
  138. if (jnpfKey === "lineChart") {
  139. name = e.opts.categories[chooseIndex]
  140. value = choose.data[chooseIndex]
  141. type = choose.name
  142. }
  143. if (jnpfKey === "radarChart") {
  144. chooseIndex = e.currentIndex
  145. name = e.opts.categories[chooseIndex]
  146. value = choose.data[chooseIndex]
  147. type = choose.name
  148. }
  149. if (jnpfKey === "mapChart" && choose.properties.childrenNum == 0) {
  150. name = choose.properties.name
  151. item.long = choose.properties.center[0]
  152. item.lat = choose.properties.center[1]
  153. }
  154. if (chooseIndex < 0 && jnpfKey !== "mapChart") return
  155. if (jnpfKey === "mapChart" && choose.properties.childrenNum != 0) return
  156. item.name = name
  157. item.value = value
  158. item.type = type
  159. item.urlAddress = this.config.option.urlAddress
  160. this.jnpf.solveAddressParam(item, this.config)
  161. this.jnpf.jumpLink(item.urlAddress)
  162. },
  163. handleAttrs() {
  164. let chartTitle = {
  165. titleText: this.config.option.titleText, //主标题
  166. titleTextStyleColor: this.config.option.titleTextStyleColor, //主标题字体颜色
  167. titleTextStyleFontSize: this.config.option.titleTextStyleFontSize * 2 + 'rpx', //主标题字体大小[12-25px]
  168. titleTextStyleFontWeight: this.config.option.titleTextStyleFontWeight ? 700 : 0, //主标题是否加粗
  169. titleLeft: this.config.option.titleLeft === 'left' ? 'flex-start' : this.config.option
  170. .titleLeft === 'right' ? 'flex-end' : 'center', //主子标题位置[left,center,right]
  171. titleBgColor: this.config.option.titleBgColor, //主子标题背景色[rgba(),#303133]
  172. // 图表副标题设置
  173. titleSubtext: this.config.option.titleSubtext, //子标题
  174. titleSubtextStyleColor: this.config.option.titleSubtextStyleColor, //子标题字体颜色
  175. titleSubtextStyleFontSize: this.config.option.titleSubtextStyleFontSize * 2 +
  176. 'rpx', //子标题字体大小[12-25px]
  177. titleSubtextStyleFontWeight: this.config.option.titleSubtextStyleFontWeight ? 700 : 0, //子标题是否加粗
  178. }
  179. if (['customEcharts'].includes(this.config.jnpfKey)) {
  180. this.$nextTick(() => {
  181. this.show = true
  182. this.key = +new Date()
  183. })
  184. return
  185. }
  186. let defVal = this.config.option.defaultValue
  187. let chartVal = JSON.parse(JSON.stringify(defVal)) || []
  188. let typeArr = Array.from(new Set(chartVal.map((item) => item.type)))
  189. let axisData = Array.from(new Set(chartVal.map((item) => item.name)))
  190. let seriesData = []
  191. let colorList = [];
  192. let chartsType = "";
  193. let Ymin = []; //y轴最小
  194. let Ymax = []; //y轴最大
  195. let type = "";
  196. let yAxis = {};
  197. let xAxis = {};
  198. if (!['mapChart', 'customEcharts'].includes(this.config.jnpfKey)) {
  199. typeArr.forEach((title, index) => {
  200. const type = this.getType(title, this.config)
  201. let obj = {
  202. name: title,
  203. type: type
  204. }
  205. if (this.config.option.seriesLabelShow) {
  206. obj.textSize = (this.config.option.seriesLabelFontSize / 2) < 12 ? 12 : this.config
  207. .option
  208. .seriesLabelFontSize / 2
  209. obj.textColor = this.config.option.seriesLabelColor
  210. }
  211. let chartArr = chartVal.filter((item) => title === item.type)
  212. if (this.config.jnpfKey === 'barChart' || this.config.jnpfKey === 'lineChart' || this
  213. .config
  214. .jnpfKey ==
  215. 'radarChart') {
  216. obj['data'] = chartArr.map((item) => item.value)
  217. } else {
  218. obj['data'] = chartArr.map((item) => {
  219. return {
  220. value: item.value,
  221. name: item.name,
  222. }
  223. })
  224. if (this.config.option.showZero) obj['data'] = obj['data'].filter((item) => item
  225. .value != 0)
  226. this.key = +new Date
  227. }
  228. Ymin.push(Math.min(...obj['data']))
  229. Ymax.push(Math.max(...obj['data']))
  230. seriesData.push(obj);
  231. })
  232. xAxis = {
  233. disabled: !this.config.option.xAxisShow, //不绘制X轴
  234. axisLine: this.config.option.xAxisShow, //绘制坐标轴轴线
  235. axisLineColor: !this.config.option.xAxisShow ? '#fff' : this.config.option
  236. .xAxisAxisLineLineStyleColor, //坐标轴轴线颜色,默认#CCCCCC
  237. title: "", //X轴标题
  238. titleFontSize: this.config.option.xAxisNameTextStyleFontSize, //标题字体大小
  239. titleFontColor: this.config.option.xAxisNameTextStyleColor, //X轴名称字体颜色
  240. titleOffsetY: -20, //标题纵向偏移距离,负数为向上偏移,正数向下偏移
  241. titleOffsetX: -300, //标题横向偏移距离,负数为向左偏移,正数向右偏移
  242. fontSize: (this.config.option.xAxisAxisLabelTextStyleFontSize / 2) < 14 ? 14 : this.config
  243. .option
  244. .xAxisAxisLabelTextStyleFontSize / 2, //X轴标签字体大小
  245. fontColor: this.config.option.xAxisAxisLabelTextStyleColor, //X轴标签字体颜色
  246. rotateAngle: this.config.option.xAxisAxisLabelRotate, ////X轴标签角度
  247. rotateLabel: this.config.option.xAxisAxisLabelRotate > 0 ? true : false, //【旋转】数据点(刻度点)文字
  248. gridColor: this.config.option.xAxisSplitLineLineStyleColor, //纵向网格颜色,默认#CCCCCC
  249. splitNumber: 4, //X轴网格数量,纵向网格数量(竖着的)
  250. disableGrid: !this.config.option.xAxisShow ? !this.config.option.xAxisShow : !this.config
  251. .option.xAxisSplitLineShow, //不绘制纵向网格(即默认绘制网格)
  252. scrollShow: axisData.length > 5 ? true : false, //是否显示滚动条,配合拖拽滚动使用(即仅在启用 enableScroll 时有效
  253. scrollAlign: "left", //滚动条初始位置
  254. scrollColor: "#A6A6A6", //滚动条颜色,默认#A6A6A6
  255. scrollBackgroundColor: "#EFEBEF", //滚动条底部背景颜色,默认#EFEBEF
  256. itemCount: axisData.length > 5 ? 6 : 5, //单屏数据密度即图表可视区域内显示的X轴数据点数量,仅在启用enableScroll时有效
  257. };
  258. yAxis = {
  259. data: [{
  260. position: "left",
  261. title: "",
  262. min: this.config.option.styleType == 6 ? -jnpf.toRound(Math.abs(Math.min(...
  263. Ymin)
  264. .toString().length > 2 ? Math.min(...Ymin) - 200 : Math
  265. .min(
  266. ...Ymin) - 50)) : 0,
  267. max: jnpf.toRound(Math.max(...Ymax)),
  268. axisLine: true, //坐标轴轴线是否显示(数据还能显示)
  269. axisLineColor: this.config.option
  270. .yAxisAxisLineLineStyleColor, //坐标轴轴线颜色,默认#CCCCCC
  271. disabled: !this.config.option.yAxisShow, //不绘制Y轴(刻度和轴线都不绘制)
  272. fontColor: this.config.option
  273. .yAxisAxisLabelTextStyleColor, //数据点(刻度点)字体颜色,默认#666666
  274. fontSize: (this.config.option.yAxisAxisLabelTextStyleFontSize / 2) < 12 ? 12 : this
  275. .config
  276. .option.yAxisAxisLabelTextStyleFontSize / 2, //数据点(刻度点)字体颜色,默认#666666
  277. }],
  278. padding: 10, //多个Y轴间的间距
  279. gridSet: "number", //横向向网格数量类型设置,可选值,'auto','array'
  280. disableGrid: !this.config.option.yAxisSplitLineShow, //不绘制横向向网格(即默认绘制网格)
  281. splitNumber: 4, //【指定数量】的横向向网格数量,此数量与Y轴数据点是否为小数有关,如果指定了max,请指定为能被max-min整除的数值
  282. gridType: "solid", //横向向网格线型
  283. gridColor: this.config.option.yAxisSplitLineLineStyleColor, //横向网格颜色,默认#CCCCCC
  284. };
  285. this.config.option.colorList.forEach((o, i) => {
  286. if (o.color1) colorList.push(o.color1)
  287. })
  288. }
  289. let opts = {
  290. color: colorList, //主题颜色,16进制颜色格式,Array格式
  291. padding: [15, 15, 0, 15], //画布填充边距[上,右,下,左],Array格式
  292. enableScroll: axisData.length > 5 ? true :
  293. false, //开启图表可拖拽滚动,开启后ontouch需要赋值为true,X轴配置里需要配置itemCount单屏幕数据点数量
  294. dataLabel: this.config.option.seriesLabelShow, //是否显示图表区域内数据点上方的数据文案
  295. legend: {
  296. fontColor: this.config.jnpfKey === 'pieChart' ? "#666666" : "",
  297. show: this.config.option.legendShow, //是否显示图例标识
  298. position: 'top',
  299. float: 'right',
  300. fontSize: (this.config.option.legendTextStyleFontSize / 2) < 14 ? 14 : this.config.option
  301. .legendTextStyleFontSize / 2
  302. },
  303. extra: {
  304. tooltip: {
  305. showBox: this.config.option.tooltipShow, //提示语显示
  306. fontSize: (this.config.option.tooltipTextStyleFontSize / 2) < 14 ? 14 : this.config
  307. .option
  308. .tooltipTextStyleFontSize / 2, //提示语字体大小
  309. fontColor: this.config.option.tooltipTextStyleColor, //提示语字体颜色
  310. bgColor: this.config.option.tooltipBgColor || '#000000' //提示窗口的背景颜色
  311. },
  312. mix: {
  313. column: {}
  314. },
  315. column: {
  316. type: 'group',
  317. width: this.config.option.seriesBarWidth, //柱体宽度
  318. activeBgColor: "#000000",
  319. activeBgOpacity: 0.08,
  320. linearType: "none",
  321. barBorderRadius: [this.config.option.seriesItemStyleBarBorderRadius, this.config.option
  322. .seriesItemStyleBarBorderRadius, this.config.option
  323. .seriesItemStyleBarBorderRadius,
  324. this.config.option.seriesItemStyleBarBorderRadius
  325. ], //自定义4个圆角半径[左上,右上,右下,左下]
  326. seriesGap: 5, //多series每个柱子之间的间距
  327. customColor: colorList, //扩展渐变色
  328. barBorderCircle: false
  329. }
  330. }
  331. }
  332. if (this.config.jnpfKey === 'barChart') {
  333. if (this.config.option.styleType == 5 || this.config.option.styleType == 1 ||
  334. this.config.option.styleType == 4 || this.config.option.styleType == 6) {
  335. type = 'group'
  336. if (this.config.option.styleType == 6) {
  337. opts.extra.column.barBorderRadius = []
  338. // opts.extra.column.width = 50
  339. // yAxis.splitNumber = (yAxis.data[0].max / 500) + (Math.abs(yAxis.data[0].min) / 500)
  340. }
  341. } else {
  342. type = 'stack'
  343. opts.extra.mix.column = {
  344. width: this.config.option.seriesBarWidth, //柱体宽度
  345. barBorderCircle: false, //启用分组柱状图半圆边框
  346. barBorderRadius: [this.config.option.seriesItemStyleBarBorderRadius, this.config.option
  347. .seriesItemStyleBarBorderRadius, this.config.option
  348. .seriesItemStyleBarBorderRadius,
  349. this.config.option.seriesItemStyleBarBorderRadius
  350. ], //自定义4个圆角半径[左上,右上,右下,左下]
  351. }
  352. }
  353. chartsType = this.config.option.styleType == 7 ? 'mix' : 'column'
  354. opts.xAxis = {
  355. ...xAxis
  356. }
  357. opts.yAxis = {
  358. ...yAxis
  359. }
  360. opts.extra.column.type = type
  361. } else if (this.config.jnpfKey === "pieChart") {
  362. chartsType = 'pie'
  363. opts.fontColor = this.config.option.seriesLabelColor
  364. opts.fontSize = (this.config.option.seriesLabelFontSize / 2) < 14 ? 14 : this.config.option
  365. .seriesLabelFontSize / 2
  366. let pieChartObj = {
  367. borderColor: "#FFFFFF",
  368. borderWidth: 3,
  369. activeOpacity: 0.5,
  370. offsetAngle: -90,
  371. labelWidth: 15,
  372. border: false,
  373. }
  374. let pieChartObj2 = {
  375. offsetX: 0,
  376. offsetY: 0,
  377. name: "",
  378. }
  379. if (this.config.option.styleType == 1) {
  380. if (this.config.option.roseType) chartsType = 'rose'
  381. opts.extra[chartsType] = {
  382. ...pieChartObj
  383. }
  384. } else {
  385. chartsType = 'ring';
  386. opts.title = {
  387. fontSize: 15,
  388. color: "#666666",
  389. ...pieChartObj2
  390. };
  391. opts.subtitle = {
  392. fontSize: 25,
  393. color: "#7cb5ec",
  394. ...pieChartObj2
  395. }
  396. opts.extra[chartsType] = {
  397. ringWidth: 60,
  398. activeRadius: 10,
  399. ...pieChartObj
  400. }
  401. }
  402. } else if (this.config.jnpfKey === "lineChart") {
  403. chartsType = this.config.option.areaStyle ? 'area' : 'line'
  404. type = this.config.option.styleType == 2 ? 'curve' : this.config.option.styleType == 3 ? 'step' :
  405. 'straight'
  406. let lineChartObj = {
  407. type: type,
  408. width: this.config.option.seriesLineStyleWidth
  409. }
  410. opts.extra[chartsType] = {
  411. ...lineChartObj
  412. }
  413. opts.xAxis = {
  414. ...xAxis
  415. }
  416. opts.yAxis = {
  417. ...yAxis
  418. }
  419. } else if (this.config.jnpfKey === "radarChart") {
  420. chartsType = "radar";
  421. type = this.config.option.styleType == 1 ? chartsType : 'circle'
  422. opts.fontSize = (this.config.option.radarAxisNameFontSize / 2) < 14 ? 14 : this.config.option
  423. .radarAxisNameFontSize / 2
  424. opts.fontColor = this.config.option.seriesLabelColor
  425. opts.extra[chartsType] = {
  426. gridType: type,
  427. gridColor: "#CCCCCC",
  428. gridCount: 5,
  429. opacity: 0.2,
  430. max: 200,
  431. labelShow: true,
  432. border: true,
  433. max: 100,
  434. labelColor: this.config.option.radarAxisNameColor
  435. }
  436. } else {
  437. this.getAtlas()
  438. chartsType = "map";
  439. this.config.option.markPoints = []
  440. opts = {
  441. update: true,
  442. fontSize: this.config.option.geoLabelFontSize,
  443. padding: [15, 15, 30, 15],
  444. dataLabel: this.config.option.geoLabelShow,
  445. fontColor: this.config.option.geoLabelColor,
  446. extra: {
  447. tooltip: {
  448. showBox: this.config.option.tooltipShow,
  449. fontColor: this.config.option.tooltipTextStyleColor || '#000',
  450. //fontSize: this.config.option.tooltipTextStyleFontSize,
  451. bgColor: this.config.option.tooltipBgColor || '#fff',
  452. bgOpacity: 1
  453. },
  454. map: {
  455. mercator: false,
  456. border: true,
  457. borderWidth: this.config.option.geoBorderWidth / 2,
  458. borderColor: this.config.option.geoBorderColor,
  459. activeBorderColor: "#F04864",
  460. activeFillColor: "#FACC14",
  461. activeFillOpacity: 1,
  462. active: true,
  463. activeTextColor: "#FFFFFF",
  464. fillOpacity: 1
  465. },
  466. },
  467. }
  468. this.config.option.defaultValue.forEach(o => {
  469. this.config.option.markPoints.push({
  470. latitude: o.lat,
  471. longitude: o.long,
  472. name: o.name,
  473. value: o.value
  474. })
  475. })
  476. }
  477. let chartData = {
  478. categories: axisData,
  479. series: seriesData,
  480. opts,
  481. type: chartsType
  482. }
  483. if (chartsType != 'map') {
  484. if (chartTitle.titleText && chartTitle.titleSubtext) {
  485. chartData.opts.legend.padding = 50
  486. } else if (chartTitle.titleText && !chartTitle.titleSubtext) {
  487. chartData.opts.legend.padding = 30
  488. } else {
  489. chartData.opts.legend.padding = 5
  490. }
  491. }
  492. this.config.option.chartData = chartData
  493. this.config.option.chartTitle = chartTitle
  494. this.option = this.config.option
  495. this.$nextTick(() => {
  496. this.show = true
  497. this.key = +new Date()
  498. })
  499. },
  500. /* 获取地图树 */
  501. getAtlas() {
  502. getAtlas().then(res => {
  503. this.mapList = jnpf.treeToArray(res.data);
  504. this.regionStep = []
  505. this.drawChina()
  506. })
  507. },
  508. /* 获取地图数据 */
  509. drawChina(type) {
  510. if (Array.isArray(this.option.mapType) && !type) this.mapType = this.option.mapType[this.option.mapType
  511. .length - 1]
  512. geojson(this.mapType).then(res => {
  513. let series = JSON.parse(JSON.stringify(res.data.features)) || [];
  514. for (var i = 0; i < series.length; i++) {
  515. if (series[i].geometry.type === 'Polygon' && !type) {
  516. if (this.mapType == 150000) {
  517. series[i].geometry.coordinates = series[i].geometry.coordinates
  518. } else {
  519. series[i].geometry.coordinates = [series[i].geometry.coordinates]
  520. }
  521. }
  522. series[i].value = Math.floor(Math.random() * 1000)
  523. series[i].color = this.option.geoAreaColor
  524. }
  525. this.mapData = series
  526. this.stepMapList.push(this.mapData)
  527. this.option.chartData.series = series
  528. this.key = +new Date()
  529. })
  530. },
  531. /* 地图点击路径 */
  532. regionStepClick(e, index) {
  533. if (index == 0) {
  534. this.stepMapList = []
  535. this.regionStep = []
  536. for (let i = 0; i < this.mapList.length; i++) {
  537. if (this.mapList[i].enCode == this.option.mapType[this.option.mapType.length - 1]) {
  538. this.regionStep.push({
  539. name: this.mapList[i].fullName,
  540. adcode: this.mapList[i].enCode
  541. })
  542. }
  543. }
  544. this.drawChina()
  545. return
  546. }
  547. this.mapType = e.adcode
  548. this.stepMapList.splice(index + 1, this.regionStep.length - index - 1)
  549. this.regionStep.splice(index + 1, this.regionStep.length - index - 1)
  550. this.drawChina(1)
  551. },
  552. /* 地图点击 */
  553. getIndex(e) {
  554. // 处理跳转参数
  555. this.handleParam(e)
  556. let current = this.mapList.filter(o => o.enCode == this.option.mapType[this.option.mapType.length - 1])
  557. if (!this.config.option.drillDown) return
  558. let mapData = this.mapData[e.currentIndex] ? this.mapData[e.currentIndex] : []
  559. this.mapType = mapData.properties.adcode
  560. let acroutes = mapData.properties.acroutes
  561. let selectName = mapData.properties.name
  562. let adcode = mapData.properties.adcode
  563. this.regionStep.unshift({
  564. name: current[0].fullName,
  565. adcode: current[0].enCode
  566. })
  567. this.regionStep.push({
  568. name: selectName,
  569. adcode: adcode
  570. })
  571. //对象数组去重
  572. this.regionStep = this.regionStep.filter((a, b, c) => {
  573. return c.findIndex(x => x.name === a.name) === b
  574. })
  575. this.pointLoading = false
  576. this.drawChina(1)
  577. },
  578. getType(title) {
  579. if (this.config.jnpfKey == 'barChart') {
  580. if (this.config.option.styleType == 7) {
  581. const arr = this.config.option.barType.find(ele => title == ele.title)
  582. if (arr && arr.type) {
  583. if (arr.type == 'bar') return 'column'
  584. return arr.type
  585. }
  586. }
  587. return 'column'
  588. } else if (this.config.jnpfKey == 'lineChart') {
  589. return 'line'
  590. } else if (this.config.jnpfKey == 'pieChart') {
  591. return 'pie'
  592. } else {
  593. return 'radar'
  594. }
  595. },
  596. /* 设置地图点 */
  597. setPoints(e) {
  598. const mapData = e.opts.chartData.mapData;
  599. this.option.markPoints = this.option.markPoints.slice(0, this.option.appShowNumber)
  600. for (var i = 0; i < this.option.markPoints.length; i++) {
  601. const points = this.coordinateToPoint(this.option.markPoints[i].longitude, this.option.markPoints[i]
  602. .latitude, mapData
  603. .bounds,
  604. mapData.scale, mapData.xoffset, mapData.yoffset, mapData.mercator)
  605. this.option.markPoints[i].x = points.x;
  606. this.option.markPoints[i].y = points.y;
  607. }
  608. this.pointLoading = true
  609. this.$refs.charts.key = +new Date();
  610. },
  611. /* 经纬度转画布坐标 */
  612. coordinateToPoint(longitude, latitude, bounds, scale, xoffset, yoffset, mercator) {
  613. var x = longitude;
  614. var y = latitude;
  615. if (mercator == true) {
  616. x = longitude * 20037508.34 / 130;
  617. y = Math.log(Math.tan((90 + latitude) * Math.PI / 360)) / (Math.PI / 180);
  618. y = y * 20037508.34 / 180;
  619. }
  620. return {
  621. x: (x - bounds.xMin) * scale + xoffset,
  622. y: (bounds.yMax - y) * scale + yoffset
  623. };
  624. }
  625. }
  626. }