mapdata.vue 8.5 KB

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