mapdata.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <moduleEnclosure>
  3. <zj-page-container>
  4. <map-data-statistics />
  5. <zj-page-fill>
  6. <div style="
  7. width: 100%;
  8. height: 100%;
  9. overflow: hidden;
  10. position: relative;
  11. ">
  12. <div id="chart_7" class="chart t_btn9" style="width: 100%; height: 100%"></div>
  13. <div class="leixingxianshi">
  14. <div class="viewfilediv">
  15. <div class="zfx" style="width:60px; background: linear-gradient(to right, #6ada40,#ebe24a,#d73921);"></div>
  16. </div>
  17. </div>
  18. </div>
  19. </zj-page-fill>
  20. </zj-page-container>
  21. </moduleEnclosure>
  22. </template>
  23. <script>
  24. import zhejiang from './js/zhejiang.js';
  25. import moduleEnclosure from '@/components/moduleEnclosure.vue';
  26. import mapDataStatistics from './mapDataStatistics.vue';
  27. import * as echarts from 'echarts';
  28. import { bigGetRegion, bigGetLarge9, bigGetLarge10 } from '@/api/common.js';
  29. // 计算 GeoJSON 数据的边界框
  30. function calculateBoundingBox(geoJsonData) {
  31. let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
  32. geoJsonData.features.forEach((feature) => {
  33. const coordinates = feature.geometry.coordinates;
  34. const type = feature.geometry.type;
  35. if (type === 'Polygon') {
  36. coordinates.forEach((polygon) => {
  37. polygon.forEach((coord) => {
  38. minX = Math.min(minX, coord[0]);
  39. minY = Math.min(minY, coord[1]);
  40. maxX = Math.max(maxX, coord[0]);
  41. maxY = Math.max(maxY, coord[1]);
  42. });
  43. });
  44. } else if (type === 'MultiPolygon') {
  45. coordinates.forEach((multiPolygon) => {
  46. multiPolygon.forEach((polygon) => {
  47. polygon.forEach((coord) => {
  48. minX = Math.min(minX, coord[0]);
  49. minY = Math.min(minY, coord[1]);
  50. maxX = Math.max(maxX, coord[0]);
  51. maxY = Math.max(maxY, coord[1]);
  52. });
  53. });
  54. });
  55. }
  56. });
  57. return { minX, minY, maxX, maxY };
  58. }
  59. export default {
  60. components: {
  61. moduleEnclosure,
  62. mapDataStatistics,
  63. },
  64. data() {
  65. return {
  66. list: [],
  67. geoCoordMap: zhejiang.features.map(function (item) {
  68. return {
  69. name: item.properties.name,
  70. value: item.properties.center,
  71. };
  72. }),
  73. data: zhejiang.features.map(function (item) {
  74. return {
  75. name: item.properties.name,
  76. };
  77. }),
  78. cIndex: 0,
  79. oldcIndex: 0,
  80. myChart: null,
  81. getLarge9: [],
  82. getLarge10: []
  83. };
  84. },
  85. computed: {
  86. userInfo() {
  87. return JSON.parse(localStorage.getItem('greemall_user'))
  88. },
  89. },
  90. watch:{
  91. "userInfo.type":{
  92. handler(newVal, oldVal) {
  93. if(this.userInfo){
  94. if (this.userInfo.type == 2){
  95. this.getbigGetLarge9({ country: 100000 });
  96. }else{
  97. this.getbigGetLarge10({ province:this.userInfo.province, city: this.userInfo.city });
  98. }
  99. }
  100. },
  101. deep: true,
  102. immediate: true,
  103. }
  104. },
  105. methods: {
  106. getbigGetLarge9(pam) {
  107. bigGetLarge9().then(res => {
  108. this.getLarge9 = res.data
  109. this.getLarge10 = []
  110. this.echart_7(pam);
  111. })
  112. },
  113. getbigGetLarge10(pam) {
  114. bigGetLarge10(pam).then(res => {
  115. this.getLarge9 = []
  116. this.getLarge10 = res.data
  117. this.echart_7({ province:this.userInfo.province, city: this.userInfo.city });
  118. })
  119. },
  120. echart_7(pam) {
  121. var that = this;
  122. if (that.myChart) {
  123. that.myChart.dispose();
  124. }
  125. bigGetRegion(pam).then(res => {
  126. // 初始化 ECharts 实例
  127. that.myChart = echarts.init(document.getElementById('chart_7'));
  128. const geoJsonData = JSON.parse(res.data);
  129. // 计算边界框
  130. const boundingBox = calculateBoundingBox(geoJsonData);
  131. // 计算中心点
  132. const center = [
  133. (boundingBox.minX + boundingBox.maxX) / 2,
  134. (boundingBox.minY + boundingBox.maxY) / 2
  135. ];
  136. echarts.registerMap('china', geoJsonData);
  137. // 指定城市和颜色
  138. var cityColors = {};
  139. this.getLarge9.map(name => {
  140. cityColors[name] = "#009eff";
  141. });
  142. this.getLarge10.map(item => {
  143. cityColors[item.area] = item.num<=2 ? "#6ada40" : item.num<=4 ? "#ebe24a" : item.num > 4 ? "#d73921" : "none"
  144. });
  145. console.log(this.getLarge9, this.getLarge10, cityColors)
  146. // 构建 series 数据
  147. var seriesData = Object.keys(cityColors).map(function (city) {
  148. return {
  149. name: city,
  150. itemStyle: {
  151. normal: {
  152. areaColor: cityColors[city],
  153. borderColor: 'none'
  154. },
  155. emphasis: {
  156. areaColor: cityColors[city],
  157. borderColor: 'none'
  158. }
  159. },
  160. };
  161. });
  162. var mapcon = {
  163. itemStyle: {
  164. normal: {
  165. borderColor: 'rgba(0,144,255, 1)',
  166. borderWidth: 1,
  167. areaColor: {
  168. type: 'radial',
  169. x: 0.4,
  170. y: 0.5,
  171. r: 1,
  172. colorStops: [
  173. {
  174. offset: 0,
  175. color: 'rgba(0,144,255, 0)', // 0% 处的颜色
  176. },
  177. {
  178. offset: 1,
  179. color: 'rgba(0,144,255, .1)', // 100% 处的颜色
  180. },
  181. {
  182. offset: 1,
  183. color: 'rgba(0,144,255, 1)', // 100% 处的颜色
  184. },
  185. ],
  186. globalCoord: false, // 缺省为 false
  187. },
  188. shadowColor: 'rgba(0,144,255, 1)',
  189. shadowOffsetX: -1,
  190. shadowOffsetY: 1,
  191. shadowBlur: 10,
  192. },
  193. emphasis: {
  194. areaColor: '#0082ff',
  195. borderWidth: 0,
  196. },
  197. },
  198. select: {
  199. // 地图选中区域样式
  200. label: {
  201. // 选中区域的label(文字)样式
  202. color: '#fff',
  203. },
  204. itemStyle: {
  205. // 选中区域的默认样式
  206. areaColor: '#7024fb',
  207. },
  208. },
  209. animation: false,
  210. };
  211. // 配置项
  212. var option = {
  213. tooltip: {
  214. trigger: 'item',
  215. formatter: '{b}'
  216. },
  217. geo: {
  218. map: 'china',
  219. roam: true,
  220. zoom: pam.country ? 1.3 : pam.city ? 4.5 : pam.province ? 1.7 : 2, // 设置缩放比例
  221. center: center,
  222. ...mapcon,
  223. regions: [
  224. ...seriesData,
  225. {
  226. name: "南海诸岛",
  227. itemStyle: {
  228. normal: {
  229. opacity: 0,
  230. }
  231. },
  232. label: {
  233. show: false
  234. }
  235. }
  236. ]
  237. },
  238. series: [{
  239. type: 'map',
  240. map: 'china',
  241. ...mapcon,
  242. geoIndex: 0,
  243. data: seriesData
  244. }]
  245. };
  246. // 使用配置项生成图表
  247. that.myChart.setOption(option);
  248. // 监听点击事件
  249. that.myChart.on('click', function (params) {
  250. });
  251. });
  252. },
  253. },
  254. };
  255. </script>
  256. <style scoped lang="scss">
  257. .leixingxianshi {
  258. // width: 120px;
  259. height: auto;
  260. position: absolute;
  261. bottom: 0px;
  262. right: -10px;
  263. }
  264. .viewfilediv {
  265. width: 100%;
  266. height: auto;
  267. display: flex;
  268. flex-direction: row;
  269. align-items: center;
  270. &:not(:last-child) {
  271. margin-bottom: 10px;
  272. }
  273. span {
  274. font-size: 14px;
  275. font-family: Source Han Sans CN, Source Han Sans CN-Regular;
  276. font-weight: 400;
  277. text-align: right;
  278. color: #8ab1dc;
  279. }
  280. }
  281. .zfx {
  282. width: 14px;
  283. height: 14px;
  284. margin-right: 6px;
  285. }
  286. .c1 {
  287. background: linear-gradient(0deg, #21c8fb 0%, #21c8fb 100%);
  288. }
  289. .c2 {
  290. background: linear-gradient(0deg, #ffc737 0%, #ffc737 100%);
  291. }
  292. .c3 {
  293. background: linear-gradient(0deg, #ea539b 0%, #e34691 100%);
  294. }
  295. .c4 {
  296. background: linear-gradient(0deg, #59cfe6 0%, #59cfe6 100%);
  297. }
  298. .c5 {
  299. background: linear-gradient(0deg, #8061ff 0%, #8061ff 100%);
  300. }
  301. .c6 {
  302. color: #e15960 !important;
  303. }
  304. .c7 {
  305. color: #ffffff !important;
  306. }
  307. .c8 {
  308. color: #ff9900 !important;
  309. }
  310. .c9 {
  311. background: linear-gradient(0deg, #3ce783 0%, #3ce783 100%);
  312. }
  313. </style>