center-map.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <!--
  2. * @Author: daidai
  3. * @Date: 2022-03-01 11:17:39
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2022-05-07 10:59:56
  6. * @FilePath: \web-pc\src\pages\big-screen\view\indexs\center-map.vue
  7. -->
  8. <template>
  9. <div class="centermap">
  10. <div class="maptitle">
  11. <div class="zuo"></div>
  12. <span class="titletext">{{ maptitle }}</span>
  13. <div class="you"></div>
  14. </div>
  15. <div class="mapwrap">
  16. <dv-border-box-13 >
  17. <div class="quanguo" @click="getData(-1)" v-if="code !== 'china' && userCode == -1">
  18. 中国
  19. </div>
  20. <Echart id="CenterMap" :options="options" ref="CenterMap" />
  21. </dv-border-box-13>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import xzqCode from "../../utils/map/xzqCode";
  27. // import { currentGET } from 'api/modules'
  28. import { GETNOBASE } from './api'
  29. export default {
  30. data() {
  31. return {
  32. maptitle: "设备分布图",
  33. options: {},
  34. code: "china",
  35. userCode: -1,//-1 代表中国 用户权限的行政区code
  36. echartBindClick: false
  37. };
  38. },
  39. created() { },
  40. mounted() {
  41. // console.log(xzqCode);
  42. this.getData()
  43. },
  44. methods: {
  45. getData(code) {
  46. let res = {
  47. data:{
  48. dataList:[
  49. {
  50. name: "重庆",
  51. value: 382
  52. },
  53. {
  54. name: "湖南省",
  55. value: 179
  56. }, {
  57. name: "江西省",
  58. value: 766
  59. }
  60. ],
  61. regionCode:-1
  62. }
  63. }
  64. if (!code) {
  65. this.userCode = res.data.regionCode;
  66. }
  67. this.getGeojson(res.data.regionCode, res.data.dataList);
  68. this.mapclick();
  69. // currentGET('big8',{regionCode:code}).then(res => {
  70. // console.log('设备分布', res);
  71. // if (res.success) {
  72. // if (!code) {
  73. // this.userCode = res.data.regionCode;
  74. // }
  75. // this.getGeojson(res.data.regionCode, res.data.dataList);
  76. // this.mapclick();
  77. // } else {
  78. // this.$Message.warning(res.msg)
  79. // }
  80. // })
  81. },
  82. getGeojson(name, mydata) {
  83. if (name == -1) {
  84. name = 'china'
  85. }
  86. this.code = name;
  87. GETNOBASE("./map-geojson/" + name + ".json").then((res) => {
  88. // console.log('地图行政区划', name, res);
  89. let cityCenter = {};
  90. let arr = res.features;
  91. arr.map((item) => {
  92. cityCenter[item.properties.name] =
  93. item.properties.centroid || item.properties.center;
  94. });
  95. let newData = [];
  96. // console.log('中心点',cityCenter);
  97. mydata.map((item) => {
  98. if (cityCenter[item.name]) {
  99. let color = this.getColor(item.value);
  100. newData.push({
  101. name: item.name,
  102. value: cityCenter[item.name].concat(item.value),
  103. // itemStyle: {
  104. // color: color,
  105. // borderColor: color,
  106. // // borderWidth: 4,
  107. // },
  108. });
  109. }
  110. });
  111. let mapjson = echarts.getMap(name);
  112. if (!mapjson) {
  113. echarts.registerMap(name, res);
  114. }
  115. this.init(name, mydata, newData);
  116. });
  117. },
  118. getColor(num) {
  119. if (num > 0 && num < 9) {
  120. return "#035cf5";
  121. } else if (num > 10 && num < 49) {
  122. return "#3375e4";
  123. } else if (num > 50 && num < 199) {
  124. return "#6797ef";
  125. } else if (num > 200 && num < 499) {
  126. return "#96b5ef";
  127. } else if (num > 500 && num < 9999) {
  128. return "#bacae8";
  129. } else if (num > 1000) {
  130. return "#3FF4FF";
  131. } else {
  132. return "";
  133. }
  134. },
  135. init(name, data, data2) {
  136. let top = 45;
  137. let zoom = 1.05;
  138. if (name == "china") {
  139. top = 140;
  140. zoom = 1.42;
  141. }
  142. let option = {
  143. backgroundColor: "rgba(0,0,0,0)",
  144. tooltip: {
  145. show: false,
  146. },
  147. legend: {
  148. show: false,
  149. },
  150. visualMap: {
  151. left: 20,
  152. bottom: 20,
  153. pieces: [
  154. { gte: 1000, label: "1000个以上" }, // 不指定 max,表示 max 为无限大(Infinity)。
  155. { gte: 600, lte: 999, label: "600-999个" },
  156. { gte: 200, lte: 599, label: "200-599个" },
  157. { gte: 50, lte: 199, label: "49-199个" },
  158. { gte: 10, lte: 49, label: "10-49个" },
  159. { lte: 9, label: "1-9个" }, // 不指定 min,表示 min 为无限大(-Infinity)。
  160. ],
  161. inRange: {
  162. // 渐变颜色,从小到大
  163. color: [
  164. "#c3d7df",
  165. "#5cb3cc",
  166. "#8abcd1",
  167. "#66a9c9",
  168. "#2f90b9",
  169. "#1781b5",
  170. ],
  171. },
  172. textStyle: {
  173. color: "#fff",
  174. },
  175. },
  176. geo: {
  177. map: name,
  178. roam: false,
  179. selectedMode: false, //是否允许选中多个区域
  180. zoom: zoom,
  181. top: top,
  182. aspectScale: 0.78,
  183. tooltip: {
  184. show: false,
  185. },
  186. label: {
  187. show: false,
  188. }, //地图中文字内容及样式控制
  189. itemStyle: {
  190. areaColor: "rgba(0,0,0,0)",
  191. borderColor: "rgba(0,0,0,0)",
  192. },
  193. emphasis: {
  194. disabled: true,
  195. },
  196. },
  197. series: [
  198. {
  199. name: "MAP",
  200. type: "map",
  201. mapType: name,
  202. aspectScale: 0.78,
  203. data: data,
  204. // data: [1,100],
  205. selectedMode: false, //是否允许选中多个区域
  206. zoom: zoom,
  207. geoIndex: 1,
  208. top: top,
  209. tooltip: {
  210. show: true,
  211. formatter: function (params) {
  212. if (params.data) {
  213. return params.name + ":" + params.data["value"];
  214. } else {
  215. return params.name;
  216. }
  217. },
  218. backgroundColor: "rgba(0,0,0,.6)",
  219. borderColor: "rgba(147, 235, 248, .8)",
  220. textStyle: {
  221. color: "#FFF",
  222. },
  223. },
  224. label: {
  225. show: false,
  226. color: "#000",
  227. // position: [-10, 0],
  228. formatter: function (val) {
  229. // console.log(val)
  230. if (val.data !== undefined) {
  231. return val.name.slice(0, 2);
  232. } else {
  233. return "";
  234. }
  235. },
  236. rich: {},
  237. emphasis: { show: false },
  238. },
  239. itemStyle: {
  240. borderColor: "rgba(147, 235, 248, .8)",
  241. borderWidth: 1,
  242. areaColor: {
  243. type: "radial",
  244. x: 0.5,
  245. y: 0.5,
  246. r: 0.8,
  247. colorStops: [
  248. {
  249. offset: 0,
  250. color: "rgba(147, 235, 248, 0)", // 0% 处的颜色
  251. },
  252. {
  253. offset: 1,
  254. color: "rgba(147, 235, 248, .2)", // 100% 处的颜色
  255. },
  256. ],
  257. globalCoord: false, // 缺为 false
  258. },
  259. shadowColor: "rgba(128, 217, 248, .3)",
  260. shadowOffsetX: -2,
  261. shadowOffsetY: 2,
  262. shadowBlur: 10,
  263. emphasis: {
  264. areaColor: "#389BB7",
  265. borderWidth: 1,
  266. },
  267. },
  268. },
  269. {
  270. data: data2,
  271. type: "effectScatter",
  272. coordinateSystem: "geo",
  273. symbolSize: function (val) {
  274. return 4;
  275. // return val[2] / 50;
  276. },
  277. legendHoverLink: true,
  278. showEffectOn: "render",
  279. rippleEffect: {
  280. // period: 4,
  281. scale: 6,
  282. color: "rgba(255,255,255, 1)",
  283. brushType: "fill",
  284. },
  285. tooltip: {
  286. show: true,
  287. formatter: function (params) {
  288. if (params.data) {
  289. return params.name + ":" + params.data["value"][2];
  290. } else {
  291. return params.name;
  292. }
  293. },
  294. backgroundColor: "rgba(0,0,0,.6)",
  295. borderColor: "rgba(147, 235, 248, .8)",
  296. textStyle: {
  297. color: "#FFF",
  298. },
  299. },
  300. label: {
  301. formatter: (param) => {
  302. return param.name.slice(0, 2);
  303. },
  304. fontSize: 11,
  305. offset: [0, 2],
  306. position: "bottom",
  307. textBorderColor: "#fff",
  308. textShadowColor: "#000",
  309. textShadowBlur: 10,
  310. textBorderWidth: 0,
  311. color: "#FFF",
  312. show: true,
  313. },
  314. // colorBy: "data",
  315. itemStyle: {
  316. color: "rgba(255,255,255,1)",
  317. borderColor: "rgba(2255,255,255,2)",
  318. borderWidth: 4,
  319. shadowColor: "#000",
  320. shadowBlur: 10,
  321. },
  322. },
  323. ],
  324. };
  325. this.options = option;
  326. },
  327. message(text) {
  328. this.$Message({
  329. text: text,
  330. type: 'warning'
  331. })
  332. },
  333. mapclick() {
  334. if (this.echartBindClick || this.userCode !== -1) return
  335. //单击切换到级地图,当mapCode有值,说明可以切换到下级地图
  336. this.$refs.CenterMap.chart.on("click", (params) => {
  337. // console.log(params);
  338. let xzqData = xzqCode[params.name];
  339. if (xzqData) {
  340. this.getData(xzqData.adcode);
  341. } else {
  342. this.message("暂无下级地市!");
  343. }
  344. });
  345. this.echartBindClick = true
  346. },
  347. },
  348. };
  349. </script>
  350. <style lang='scss' scoped>
  351. .centermap {
  352. margin-bottom: 30px;
  353. .maptitle {
  354. height: 60px;
  355. display: flex;
  356. justify-content: center;
  357. padding-top: 10px;
  358. box-sizing: border-box;
  359. .titletext {
  360. font-size: 28px;
  361. font-weight: 900;
  362. letter-spacing: 6px;
  363. background: linear-gradient(92deg,
  364. #0072ff 0%,
  365. #00eaff 48.8525390625%,
  366. #01aaff 100%);
  367. -webkit-background-clip: text;
  368. -webkit-text-fill-color: transparent;
  369. margin: 0 10px;
  370. }
  371. .zuo,
  372. .you {
  373. background-size: 100% 100%;
  374. width: 29px;
  375. height: 20px;
  376. margin-top: 8px;
  377. }
  378. .zuo {
  379. background: url("../../assets/images/xiezuo.png") no-repeat;
  380. }
  381. .you {
  382. background: url("../../assets/images/xieyou.png") no-repeat;
  383. }
  384. }
  385. .mapwrap {
  386. height: 548px;
  387. width: 100%;
  388. // padding: 0 0 10px 0;
  389. box-sizing: border-box;
  390. position: relative;
  391. .quanguo {
  392. position: absolute;
  393. right: 20px;
  394. top: -46px;
  395. width: 80px;
  396. height: 28px;
  397. border: 1px solid #00eded;
  398. border-radius: 10px;
  399. color: #00f7f6;
  400. text-align: center;
  401. line-height: 26px;
  402. letter-spacing: 6px;
  403. cursor: pointer;
  404. box-shadow: 0 2px 4px rgba(0, 237, 237, 0.5),
  405. 0 0 6px rgba(0, 237, 237, 0.4);
  406. }
  407. }
  408. }
  409. </style>