ea6b706fc88e01b3eab95b227aa1c6c58255b6ea.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <!-- -->
  2. <template>
  3. <div style="width:100%;height:100%;">
  4. <div style="width:100%;height:100%;">
  5. <div id="syMainMapContainer" style="width: 100%;height: calc(100% - 40px);">
  6. <div style="width:100%;height:100%;" id="mapChart"></div>
  7. </div>
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  13. //例如:import 《组件名称》 from '《组件路径》';
  14. import echarts from 'echarts'
  15. import axios from 'axios' //引入axios
  16. // import theme from '../../store/theme'
  17. export default {
  18. //import引入的组件需要注入到对象中才能使用
  19. props: ['useAddv', 'mapData', 'focusType', 'mapTitleFocusName', 'mapPointColor', 'barsChooseUnit'],
  20. components: {},
  21. data() {
  22. //这里存放数据
  23. return {
  24. addvCenters: {},
  25. mapName: 'china',
  26. firstToOn: true,
  27. themeColor: '#000',
  28. themeColorMap: 'rgb(195,240,255)',
  29. mapBorderColor: '#778387',
  30. customSettings: [],
  31. noDataArr:[]
  32. };
  33. },
  34. //监听属性 类似于data概念
  35. computed: {
  36. msg() {
  37. // return theme.state.testMsg;
  38. return this.$store.state.theme.testMsg;
  39. },
  40. symbolSize() {
  41. if (window.innerWidth <= 1366) {
  42. return 40;
  43. } else {
  44. return 50;
  45. }
  46. },
  47. organNm() {
  48. return localStorage.getItem('currentOrgNm') ? localStorage.getItem('currentOrgNm') : ''
  49. },
  50. organCode() {
  51. return localStorage.getItem('currentRlcode') ? localStorage.getItem('currentRlcode') : ''
  52. },
  53. isNational() {
  54. return this.organCode.indexOf('00') == 0 ? true : false
  55. },
  56. currentOrgId() {
  57. return localStorage.getItem('currentOrgId') ? localStorage.getItem('currentOrgId') : ''
  58. }
  59. },
  60. //监控data中的数据变化
  61. watch: {
  62. mapData: function () {
  63. this.mapName = this.organNm
  64. this.refreshTheChart();
  65. },
  66. msg(n, o) {
  67. if (n == 'dark') {
  68. this.themeColor = 'rgba(177, 210, 254, 1)';
  69. this.themeColorMap = 'rgb(32,66,160)';
  70. this.mapBorderColor = '#0380c3';
  71. this.refreshTheChart();
  72. } else {
  73. this.themeColor = '#000';
  74. this.themeColorMap = 'rgb(195,240,255)';
  75. this.mapBorderColor = '#778387';
  76. this.refreshTheChart();
  77. }
  78. }
  79. },
  80. //方法集合
  81. methods: {
  82. getTheCustomGeoDataByOrg(originalGeoJson, useAdName) {
  83. /*该方法接收原本的geoJson,从中挑选出所选机构涉及的行政区(其余的不要了) */
  84. let usedGeoJson = [];
  85. let originalGeoObject = {};
  86. originalGeoJson.features.forEach(item => {//将要处理的originalGeoJson的Features数组转化为以adCode做key的对象,方便后续根据业务数据进行查找,避免嵌套循环
  87. originalGeoObject[item.id] = item;
  88. });
  89. this.mapData.forEach((dataItem) => {//根据业务数据,将业务数据包含的行政区划代码对应的geo数据放到数组里以过滤不涉及的行政区划
  90. if (originalGeoObject[dataItem.adCode.substr(0, 6)]) {
  91. usedGeoJson.push(originalGeoObject[dataItem.adCode.substr(0, 6)]);
  92. }
  93. });
  94. if(usedGeoJson.length==0){
  95. originalGeoJson.features.forEach((dataItem) => {//根据业务数据,将业务数据包含的行政区划代码对应的geo数据放到数组里以过滤不涉及的行政区划
  96. usedGeoJson.push(dataItem);
  97. });
  98. this.noDataArr = originalGeoJson.features;
  99. }
  100. console.log(usedGeoJson)
  101. let _self = this;
  102. usedGeoJson.forEach(item => {//在挑选完需要保留的geo数据后,将中间点取出单独存储,供散点图使用。防止过度嵌套的for循环影像效率。
  103. _self.addvCenters[item.properties.name] = item.properties.cp;
  104. });
  105. // originalGeoJson.features = usedGeoJson;//将处理过后的features赋回原有对象,保持对象格式,便于echarts引用
  106. // 2019.06.19 因为政治问题保留全部数据
  107. return originalGeoJson;
  108. },
  109. convertData: function () {//制作散点数据。
  110. var res = [];
  111. let _self = this;
  112. let mapSeriesData = this.mapData;
  113. console.log(mapSeriesData);
  114. if(this.noDataArr.length==0){
  115. for (var i = 0; i < mapSeriesData.length; i++) {
  116. var geoCoord = _self.addvCenters[mapSeriesData[i].name];
  117. if (geoCoord) {
  118. res.push({
  119. name: mapSeriesData[i].name,
  120. value: geoCoord.concat(Number(mapSeriesData[i].total)),
  121. });
  122. }
  123. }
  124. }else{
  125. for(var i = 0;i<this.noDataArr.length;i++){
  126. res.push({
  127. name: this.noDataArr[i].properties.name,
  128. value: 0,
  129. });
  130. }
  131. }
  132. return res;
  133. },
  134. getChartSeriesData: function () {
  135. let seriesData = this.convertData();
  136. console.log(seriesData);
  137. let color = ['#b9dd7d', '#b9dc7e','#ee9e9f', '#fffb9a', '#fffb9a', '#ee9c9e',
  138. '#f6c992', '#b9dd7d', '#c6c', '#6363ff','#da70d6', '#32cd32',
  139. '#ff7f50', '#87cefa', '#da70d6', '#32cd32', '#6495ed',
  140. '#ff69b4', '#ba55d3', '#cd5c5c', '#ffa500', '#40e0d0',
  141. '#1e90ff', '#ff6347', '#7b68ee', '#d0648a', '#ffd700',
  142. '#6b8e23', '#4ea397', '#3cb371', '#b8860b', '#7bd9a5'];
  143. //福建需求单独新增市级颜色区分
  144. //this.currentOrgId == "034"
  145. // if(){
  146. this.customSettings = seriesData.map(function (item, index) {
  147. return {
  148. name: item.name,
  149. itemStyle: {
  150. areaColor: color[index]
  151. }
  152. }
  153. })
  154. // }else{
  155. // this.customSettings = [];
  156. // }
  157. return seriesData;
  158. },
  159. getChartOption: function () {
  160. console.log(this.mapData);
  161. let _this = this
  162. let seriesData = this.getChartSeriesData();
  163. let option = {
  164. title: {
  165. text: this.mapTitleFocusName + '数量分布情况',
  166. left: 'center',
  167. textStyle: {
  168. color: this.themeColor
  169. }
  170. },
  171. tooltip: {
  172. show: false,
  173. },
  174. geo: {
  175. itemStyle: {
  176. normal: {
  177. borderColor: this.mapBorderColor,
  178. borderWidth: 1,
  179. },
  180. },
  181. show: true,
  182. map: this.mapName,
  183. top: "80",
  184. bottom: "30",
  185. roam: true,
  186. zoom: .9,
  187. regions: this.customSettings,
  188. selectedMode: false, //选中模式:single | multiple
  189. left: 0,
  190. right: 0,
  191. layoutCenter: ["50%", "50%"], //设置后left/right/top/bottom等属性无效
  192. layoutSize: "100%",
  193. label: {
  194. normal: { //静态的时候展示样式
  195. show: true, //是否显示地图省份得名称
  196. textStyle: {
  197. color: "#000",
  198. fontSize: 12,
  199. fontFamily: "Arial"
  200. }
  201. },
  202. // emphasis: { //动态展示的样式
  203. // color: '#43d0d6',
  204. // }
  205. },
  206. },
  207. // visualMap: {
  208. // show: false,
  209. // min: 1,
  210. // max: 20,
  211. // left: 'left',
  212. // top: 'bottom',
  213. // text: ['高', '低'],
  214. // textStyle: {
  215. // color: '#ccc'
  216. // },
  217. // calculable: true,
  218. // seriesIndex: [1],
  219. // inRange: {
  220. // color: ['#7ab751', '#cc66cc', '#36c', '#f93', '#86c583', '#ff9999', '#cc9933', '#66a13e', '#ff9933', '#6363ff']
  221. // }
  222. // },
  223. series: [
  224. {
  225. left: '20%',
  226. tooltip: {
  227. show: true,
  228. formatter: function (params) {
  229. return params.name + ': ' + params.value[2] + ' ' + _this.barsChooseUnit
  230. },
  231. },
  232. type: 'scatter',
  233. coordinateSystem: 'geo',
  234. symbol: 'pin', //气泡
  235. symbolSize: this.symbolSize,
  236. // data: seriesData,
  237. label: {
  238. normal: {
  239. show: true,
  240. formatter: function (params) {
  241. return params.value[2]
  242. },
  243. textStyle: {
  244. fontSize: 12,
  245. color: "#ffffff"
  246. }
  247. }
  248. },
  249. itemStyle: {
  250. normal: {
  251. color: this.mapPointColor,
  252. borderColor: '#fff',
  253. borderWidth: 1,
  254. borderType: 'solid',
  255. }
  256. }
  257. },
  258. {
  259. type: 'map',
  260. map: this.mapName,
  261. geoIndex: 0,
  262. aspectScale: 0.75, //长宽比
  263. showLegendSymbol: false, // 存在legend时显示
  264. animation: false,
  265. roam: true,
  266. // data: seriesData
  267. },
  268. ]
  269. };
  270. return option;
  271. },
  272. refreshTheChart: async function () {
  273. // 准备工作
  274. let _self = this;
  275. let myChart = echarts.init(document.getElementById('mapChart'));
  276. // 处理地图数据
  277. let geoAdcode = this.organCode.substr(0, 6) //省级切换时获取不同的行政区代码
  278. let geoJsonResult = await this.getAddvGeoData(geoAdcode);// 根据行政区划代码请求地图geoJson
  279. let geoJson = _self.getTheCustomGeoDataByOrg(geoJsonResult.data, '');//根据可能的所选机构处理摘出需要的行政区数据
  280. echarts.registerMap(this.mapName, geoJson);//向echart注册地图
  281. // 获取option
  282. let option = _self.getChartOption();
  283. myChart.setOption(option, true);
  284. if (this.firstToOn) {
  285. myChart.on('click', function (params) {//注册地图点击事件,上冒
  286. if (params.componentSubType && params.componentSubType == 'scatter') {
  287. //点击的为标记 应当出弹框
  288. // let
  289. } else if (params.componentSubType && params.componentSubType == 'map') {
  290. //点击的为底图 应当下钻
  291. let adName = params.name;
  292. _self.mapData.forEach((dataItem) => {
  293. if (dataItem.name == adName) {
  294. //确定点击行政区
  295. _self.$emit('mapClick', {
  296. 'onClickAdCode': dataItem.adCode,
  297. 'onClickAdName': dataItem.name
  298. });
  299. }
  300. });
  301. }
  302. });
  303. this.firstToOn = false;
  304. }
  305. },
  306. getAddvGeoData: function (adCode) {
  307. // if(adCode=="120000"){
  308. // adCode = "120100";
  309. // }
  310. let geoJsonName = adCode + "DATA.json";
  311. return axios.get('/src/assets/addvGeoData/' + geoJsonName);
  312. },
  313. },
  314. //生命周期 - 创建完成(可以访问当前this实例)
  315. created() {
  316. },
  317. //生命周期 - 挂载完成(可以访问DOM元素)
  318. mounted() {
  319. // this.refreshTheChart();
  320. },
  321. beforeCreate() {
  322. }, //生命周期 - 创建之前
  323. beforeMount() {
  324. }, //生命周期 - 挂载之前
  325. beforeUpdate() {
  326. }, //生命周期 - 更新之前
  327. updated() {
  328. }, //生命周期 - 更新之后
  329. beforeDestroy() {
  330. }, //生命周期 - 销毁之前
  331. destroyed() {
  332. }, //生命周期 - 销毁完成
  333. activated() {
  334. }, //如果页面有keep-alive缓存功能,这个函数会触发
  335. }
  336. </script>
  337. <style scoped>
  338. </style>