map.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <template>
  2. <div style="width: 680px">
  3. <div ref="charts" style="width: 100%;height: 920px;margin-top: -80px"></div>
  4. <img
  5. id="mapBackground"
  6. src="@/assets/images/main/map_bg.jpg"
  7. alt=""
  8. style="display: none"
  9. />
  10. <img
  11. v-if="showBack"
  12. @click="beBack(sign)"
  13. src="@/assets/images/main/back.png"
  14. style="width: 34px;height: 30px;cursor: pointer;position: absolute;right: 50px;bottom: 50px;"
  15. />
  16. </div>
  17. </template>
  18. <script>
  19. import * as echarts from "echarts";
  20. import shanxi from "./shanxi.json"
  21. import 大同市 from '@/views/screen/map/大同市.json'
  22. import 朔州市 from '@/views/screen/map/朔州市.json'
  23. import 忻州市 from '@/views/screen/map/忻州市.json'
  24. import 吕梁市 from '@/views/screen/map/吕梁市.json'
  25. import 太原市 from '@/views/screen/map/太原市.json'
  26. import 阳泉市 from '@/views/screen/map/阳泉市.json'
  27. import 晋中市 from '@/views/screen/map/晋中市.json'
  28. import 临汾市 from '@/views/screen/map/临汾市.json'
  29. import 长治市 from '@/views/screen/map/长治市.json'
  30. import 运城市 from '@/views/screen/map/运城市.json'
  31. import 晋城市 from '@/views/screen/map/晋城市.json'
  32. import { getProjectByAppOrg } from '@/api/screen/service'
  33. // 临汾市
  34. import 安泽县 from "./临汾市/安泽县.json";
  35. import 大宁县 from "./临汾市/大宁县.json";
  36. import 汾西县 from "./临汾市/汾西县.json";
  37. import 浮山县 from "./临汾市/浮山县.json";
  38. import 古县 from "./临汾市/古县.json";
  39. import 洪洞县 from "./临汾市/洪洞县.json";
  40. import 侯马市 from "./临汾市/侯马市.json";
  41. import 霍州市 from "./临汾市/霍州市.json";
  42. import 吉县 from "./临汾市/吉县.json";
  43. import 蒲县 from "./临汾市/蒲县.json";
  44. import 曲沃县 from "./临汾市/曲沃县.json";
  45. import 隰县 from "./临汾市/隰县.json";
  46. import 乡宁县 from "./临汾市/乡宁县.json";
  47. import 襄汾县 from "./临汾市/襄汾县.json";
  48. import 尧都区 from "./临汾市/尧都区.json";
  49. import 翼城县 from "./临汾市/翼城县.json";
  50. import 永和县 from "./临汾市/永和县.json";
  51. // 长治市
  52. import 壶关县 from "./长治市/壶关县.json";
  53. import 黎城县 from "./长治市/黎城县.json";
  54. import 潞城区 from "./长治市/潞城区.json";
  55. import 潞州区 from "./长治市/潞州区.json";
  56. import 平顺县 from "./长治市/平顺县.json";
  57. import 沁县 from "./长治市/沁县.json";
  58. import 沁源县 from "./长治市/沁源县.json";
  59. import 上党区 from "./长治市/上党区.json";
  60. import 屯留区 from "./长治市/屯留区.json";
  61. import 武乡县 from "./长治市/武乡县.json";
  62. import 襄垣县 from "./长治市/襄垣县.json";
  63. import 长子县 from "./长治市/长子县.json";
  64. // 运城市
  65. import 河津市 from "./运城市/河津市.json";
  66. import 稷山县 from "./运城市/稷山县.json";
  67. import 绛县 from "./运城市/绛县.json";
  68. import 临猗县 from "./运城市/临猗县.json";
  69. import 平陆县 from "./运城市/平陆县.json";
  70. import 芮城县 from "./运城市/芮城县.json";
  71. import 万荣县 from "./运城市/万荣县.json";
  72. import 闻喜县 from "./运城市/闻喜县.json";
  73. import 夏县 from "./运城市/夏县.json";
  74. import 新绛县 from "./运城市/新绛县.json";
  75. import 盐湖区 from "./运城市/盐湖区.json";
  76. import 永济市 from "./运城市/永济市.json";
  77. import 垣曲县 from "./运城市/垣曲县.json";
  78. //晋城市
  79. import 城区 from "./晋城市/城区.json";
  80. import 高平市 from "./晋城市/高平市.json";
  81. import 陵川县 from "./晋城市/陵川县.json";
  82. import 沁水县 from "./晋城市/沁水县.json";
  83. import 阳城县 from "./晋城市/阳城县.json";
  84. import 泽州县 from "./晋城市/泽州县.json";
  85. //吕梁市
  86. import 方山县 from "./吕梁市/方山县.json";
  87. import 汾阳市 from "./吕梁市/汾阳市.json";
  88. import 交城县 from "./吕梁市/交城县.json";
  89. import 交口县 from "./吕梁市/交口县.json";
  90. import 岚县 from "./吕梁市/岚县.json";
  91. import 离石区 from "./吕梁市/离石区.json";
  92. import 临县 from "./吕梁市/临县.json";
  93. import 柳林县 from "./吕梁市/柳林县.json";
  94. import 娄烦县 from "./吕梁市/娄烦县.json";
  95. import 石楼县 from "./吕梁市/石楼县.json";
  96. import 文水县 from "./吕梁市/文水县.json";
  97. import 孝义市 from "./吕梁市/孝义市.json";
  98. import 兴县 from "./吕梁市/兴县.json";
  99. import 中阳县 from "./吕梁市/中阳县.json";
  100. //太原市
  101. import 古交市 from "./太原市/古交市.json";
  102. import 尖草坪区 from "./太原市/尖草坪区.json";
  103. import 娄烦县2 from "./太原市/娄烦县.json";
  104. import 清徐县 from "./太原市/清徐县.json";
  105. import 万柏林区 from "./太原市/万柏林区.json";
  106. import 小店区 from "./太原市/小店区.json";
  107. import 杏花岭区 from "./太原市/杏花岭区.json";
  108. import 阳曲县 from "./太原市/阳曲县.json";
  109. import 迎泽区 from "./太原市/迎泽区.json";
  110. //阳泉市
  111. import 城区2 from "./阳泉市/城区.json";
  112. import 郊区 from "./阳泉市/郊区.json";
  113. import 矿区 from "./阳泉市/矿区.json";
  114. import 平定县 from "./阳泉市/平定县.json";
  115. import 盂县 from "./阳泉市/盂县.json";
  116. //晋中市
  117. import 和顺县 from "./晋中市/和顺县.json";
  118. import 介休市 from "./晋中市/介休市.json";
  119. import 灵石县 from "./晋中市/灵石县.json";
  120. import 平遥县 from "./晋中市/平遥县.json";
  121. import 祁县 from "./晋中市/祁县.json";
  122. import 寿阳县 from "./晋中市/寿阳县.json";
  123. import 太谷区 from "./晋中市/太谷区.json";
  124. import 昔阳县 from "./晋中市/昔阳县.json";
  125. import 榆次区 from "./晋中市/榆次区.json";
  126. import 榆社县 from "./晋中市/榆社县.json";
  127. import 左权县 from "./晋中市/左权县.json";
  128. //大同市
  129. import 广灵县 from "./大同市/广灵县.json";
  130. import 浑源县 from "./大同市/浑源县.json";
  131. import 灵丘县 from "./大同市/灵丘县.json";
  132. import 平城区 from "./大同市/平城区.json";
  133. import 天镇县 from "./大同市/天镇县.json";
  134. import 新荣区 from "./大同市/新荣区.json";
  135. import 阳高县 from "./大同市/阳高县.json";
  136. import 云冈区 from "./大同市/云冈区.json";
  137. import 云州区 from "./大同市/云州区.json";
  138. import 左云县 from "./大同市/左云县.json";
  139. //朔州市
  140. import 怀仁市 from "./朔州市/怀仁市.json";
  141. import 平鲁区 from "./朔州市/平鲁区.json";
  142. import 山阴县 from "./朔州市/山阴县.json";
  143. import 朔城区 from "./朔州市/朔城区.json";
  144. import 应县 from "./朔州市/应县.json";
  145. import 右玉县 from "./朔州市/右玉县.json";
  146. //忻州市
  147. import 保德县 from "./忻州市/保德县.json";
  148. import 代县 from "./忻州市/代县.json";
  149. import 定襄县 from "./忻州市/定襄县.json";
  150. import 繁峙县 from "./忻州市/繁峙县.json";
  151. import 河曲县 from "./忻州市/河曲县.json";
  152. import 静乐县 from "./忻州市/静乐县.json";
  153. import 岢岚县 from "./忻州市/岢岚县.json";
  154. import 宁武县 from "./忻州市/宁武县.json";
  155. import 偏关县 from "./忻州市/偏关县.json";
  156. import 神池县 from "./忻州市/神池县.json";
  157. import 五台县 from "./忻州市/五台县.json";
  158. import 五寨县 from "./忻州市/五寨县.json";
  159. import 忻府区 from "./忻州市/忻府区.json";
  160. import 原平市 from "./忻州市/原平市.json";
  161. let imgElement
  162. export default {
  163. props: {
  164. list1: Array,
  165. list2: Array
  166. },
  167. data(){
  168. return{
  169. backName: null,
  170. backAppOrg: null,
  171. sign: null,
  172. projectList: [],
  173. area: [
  174. { name: "太原市", appOrg: "1A003" },
  175. { name: "大同市", appOrg: "1B001" },
  176. { name: "阳泉市", appOrg: "1C001" },
  177. { name: "长治市", appOrg: "1D001" },
  178. { name: "晋城市", appOrg: "1E001" },
  179. { name: "朔州市", appOrg: "1F001" },
  180. { name: "晋中市", appOrg: "1K001" },
  181. { name: "临汾市", appOrg: "1L001" },
  182. { name: "忻州市", appOrg: "1H001" },
  183. { name: "运城市", appOrg: "1M001" },
  184. { name: "吕梁市", appOrg: "1J001" }
  185. ],
  186. points: [
  187. { name: "太原市", coordinate: [111.8493, 37.9570], appOrg: "1A003", x: "1", y: "2" },
  188. { name: "大同市", coordinate: [113.3002, 40.0768], appOrg: "1B001", x: "1", y: "2" },
  189. { name: "阳泉市", coordinate: [113.3805, 38.3563], appOrg: "1C001", x: "1", y: "2" },
  190. { name: "长治市", coordinate: [113.1163, 36.6254], appOrg: "1D001", x: "1", y: "2" },
  191. { name: "晋城市", coordinate: [112.2113, 35.4007], appOrg: "1E001", x: "1", y: "2" },
  192. { name: "朔州市", coordinate: [112.4329, 39.6312], appOrg: "1F001", x: "1", y: "2" },
  193. { name: "晋中市", coordinate: [113.3827, 37.1870], appOrg: "1K001", x: "1", y: "2" },
  194. { name: "临汾市", coordinate: [111.1286, 36.2582], appOrg: "1L001", x: "1", y: "2" },
  195. { name: "忻州市", coordinate: [112.7341, 38.3167], appOrg: "1H001", x: "1", y: "2" },
  196. { name: "运城市", coordinate: [111.0069, 35.4264], appOrg: "1M001", x: "1", y: "2" },
  197. { name: "吕梁市", coordinate: [111.1443, 37.1183], appOrg: "1J001", x: "1", y: "2" }
  198. ],
  199. appOrg: "10001",
  200. showBack: false,
  201. dataSource: {
  202. 大同市: 大同市,
  203. 朔州市: 朔州市,
  204. 忻州市: 忻州市,
  205. 吕梁市: 吕梁市,
  206. 太原市: 太原市,
  207. 阳泉市: 阳泉市,
  208. 晋中市: 晋中市,
  209. 临汾市: 临汾市,
  210. 长治市: 长治市,
  211. 运城市: 运城市,
  212. 晋城市: 晋城市,
  213. 安泽县: 安泽县,
  214. 大宁县: 大宁县,
  215. 汾西县: 汾西县,
  216. 浮山县: 浮山县,
  217. 古县: 古县 ,
  218. 洪洞县: 洪洞县,
  219. 侯马市: 侯马市,
  220. 霍州市: 霍州市,
  221. 吉县: 吉县 ,
  222. 蒲县: 蒲县 ,
  223. 曲沃县: 曲沃县,
  224. 隰县: 隰县 ,
  225. 乡宁县: 乡宁县,
  226. 襄汾县: 襄汾县,
  227. 尧都区: 尧都区,
  228. 翼城县: 翼城县,
  229. 永和县: 永和县,
  230. 壶关县: 壶关县,
  231. 黎城县: 黎城县,
  232. 潞城区: 潞城区,
  233. 潞州区: 潞州区,
  234. 平顺县: 平顺县,
  235. 沁县: 沁县 ,
  236. 沁源县: 沁源县,
  237. 上党区: 上党区,
  238. 屯留区: 屯留区,
  239. 武乡县: 武乡县,
  240. 襄垣县: 襄垣县,
  241. 长子县: 长子县,
  242. 河津市: 河津市,
  243. 稷山县: 稷山县,
  244. 绛县: 绛县 ,
  245. 临猗县: 临猗县,
  246. 平陆县: 平陆县,
  247. 芮城县: 芮城县,
  248. 万荣县: 万荣县,
  249. 闻喜县: 闻喜县,
  250. 夏县: 夏县 ,
  251. 新绛县: 新绛县,
  252. 盐湖区: 盐湖区,
  253. 永济市: 永济市,
  254. 垣曲县: 垣曲县,
  255. 城区: 城区 ,
  256. 高平市: 高平市,
  257. 陵川县: 陵川县,
  258. 沁水县: 沁水县,
  259. 阳城县: 阳城县,
  260. 泽州县: 泽州县,
  261. 方山县: 方山县,
  262. 汾阳市: 汾阳市,
  263. 交城县: 交城县,
  264. 交口县: 交口县,
  265. 岚县: 岚县 ,
  266. 离石区: 离石区,
  267. 临县: 临县 ,
  268. 柳林县: 柳林县,
  269. 娄烦县: 娄烦县,
  270. 石楼县: 石楼县,
  271. 文水县: 文水县,
  272. 孝义市: 孝义市,
  273. 兴县: 兴县 ,
  274. 中阳县: 中阳县,
  275. 古交市: 古交市 ,
  276. 尖草坪区: 尖草坪区,
  277. 娄烦县2: 娄烦县2,
  278. 清徐县: 清徐县 ,
  279. 万柏林区: 万柏林区,
  280. 小店区: 小店区 ,
  281. 杏花岭区: 杏花岭区,
  282. 阳曲县: 阳曲县 ,
  283. 迎泽区: 迎泽区 ,
  284. 城区2: 城区2,
  285. 郊区: 郊区 ,
  286. 矿区: 矿区 ,
  287. 平定县: 平定县,
  288. 盂县: 盂县 ,
  289. 和顺县: 和顺县,
  290. 介休市: 介休市,
  291. 灵石县: 灵石县,
  292. 平遥县: 平遥县,
  293. 祁县: 祁县 ,
  294. 寿阳县: 寿阳县,
  295. 太谷区: 太谷区,
  296. 昔阳县: 昔阳县,
  297. 榆次区: 榆次区,
  298. 榆社县: 榆社县,
  299. 左权县: 左权县,
  300. 广灵县: 广灵县,
  301. 浑源县: 浑源县,
  302. 灵丘县: 灵丘县,
  303. 平城区: 平城区,
  304. 天镇县: 天镇县,
  305. 新荣区: 新荣区,
  306. 阳高县: 阳高县,
  307. 云冈区: 云冈区,
  308. 云州区: 云州区,
  309. 左云县: 左云县,
  310. 怀仁市: 怀仁市,
  311. 平鲁区: 平鲁区,
  312. 山阴县: 山阴县,
  313. 朔城区: 朔城区,
  314. 应县: 应县 ,
  315. 右玉县: 右玉县,
  316. 保德县: 保德县,
  317. 代县: 代县 ,
  318. 定襄县: 定襄县,
  319. 繁峙县: 繁峙县,
  320. 河曲县: 河曲县,
  321. 静乐县: 静乐县,
  322. 岢岚县: 岢岚县,
  323. 宁武县: 宁武县,
  324. 偏关县: 偏关县,
  325. 神池县: 神池县,
  326. 五台县: 五台县,
  327. 五寨县: 五寨县,
  328. 忻府区: 忻府区,
  329. 原平市: 原平市,
  330. }
  331. }
  332. },
  333. created () {},
  334. mounted() {},
  335. methods: {
  336. start(){
  337. this.$nextTick(() => {
  338. let i = 0
  339. for (let it of this.points){
  340. it.x = this.list1[i]
  341. it.y = this.list2[i]
  342. i++
  343. }
  344. imgElement = document.getElementById("mapBackground");
  345. setTimeout(() => {
  346. this.initCharts();
  347. }, 500);
  348. });
  349. },
  350. initCharts() {
  351. this.charts = echarts.init(this.$refs["charts"]);
  352. const option = {
  353. // 设置背景颜色,"transparent" 表示透明背景
  354. backgroundColor: "transparent",
  355. // 提示浮窗(Tooltip)配置
  356. tooltip: {
  357. show: true, // 是否显示 tooltip
  358. trigger: "item", // 触发类型,"item" 表示鼠标悬浮在图形上时触发
  359. formatter: (params) => // 格式化提示框内容
  360. params.seriesType === "scatter"
  361. ? `在建项目:${params.data.x}<br/>施工项目:${params.data.y}`
  362. : params.name, // 如果是 scatter 图表,显示额外数据,否则显示地区名称
  363. backgroundColor: "rgba(66,85,87,0.71)", // 提示框背景颜色(半透明黑色)
  364. borderColor: "rgba(56,236,250,0.6)", // 边框颜色
  365. borderWidth: 1,
  366. triggerOn: "mousemove", // 鼠标移动时触发
  367. enterable: true, // 允许鼠标移动到 tooltip 内部(适用于可点击 tooltip)
  368. textStyle: {
  369. color: "#fff", // 文字颜色
  370. fontSize: 12, // 字体大小
  371. overflow: "break", // 文字超出时换行
  372. },
  373. padding: [5, 10], // 提示框内边距
  374. },
  375. // 地理坐标系组件(用于地图绘制)
  376. geo: {
  377. map: "shanxi", // 使用 "shanxi" 地图
  378. zoom: 1.1, // 初始缩放比例(可调整地图大小)
  379. itemStyle: {
  380. borderColor: "#11F6F2", // 地图区域边界颜色
  381. borderWidth: 5, // 边界宽度
  382. shadowColor: "#0E7683", // 地图阴影颜色
  383. shadowBlur: 0, // 阴影模糊度
  384. shadowOffsetX: 5, // 阴影水平偏移
  385. shadowOffsetY: 13, // 阴影垂直偏移
  386. },
  387. layoutCenter: ["50%", "50%"], // 控制地图的中心位置
  388. },
  389. // 图表数据系列(series)
  390. series: [
  391. {
  392. type: "map", // 地图类型
  393. map: "shanxi", // 绑定的地图名称(与 `geo` 对应)
  394. zoom: 1.1, // 缩放级别
  395. itemStyle: {
  396. areaColor: { image: imgElement, repeat: "no-repeat" }, // 地图区域背景颜色(使用图片填充)
  397. borderColor: "#11F4F0", // 地图边界颜色
  398. borderWidth: 1, // 地图边界宽度
  399. },
  400. emphasis: {
  401. itemStyle: {
  402. areaColor: "#0D7481", // 鼠标悬浮时的区域颜色
  403. },
  404. },
  405. select: { disabled: true }, // 禁用地图的选中状态,防止点击后颜色锁定
  406. label: {
  407. show: true, // 显示区域名称
  408. color: "#FFF", // 文字颜色
  409. fontSize: 16, // 文字大小
  410. fontWeight: 500, // 字重
  411. emphasis: { color: "#fff" }, // 悬浮时的文字颜色
  412. },
  413. data: this.area
  414. },
  415. {
  416. type: "scatter", // 散点图(用于标注特殊位置)
  417. coordinateSystem: "geo", // 使用 `geo` 作为坐标系
  418. symbol: "image://" + require("@/assets/zhang/myMap/projectPosition.png"), // 自定义标记(图片)
  419. symbolSize: [30, 20], // 标记大小(宽 30,高 20)
  420. label: {
  421. show: true, // 直接显示数值
  422. position: 'top',
  423. formatter: (params) => // 格式化提示框内容
  424. params.seriesType === "scatter"
  425. ? `{myStyle|在建:${params.data.x}}\n{myStyle|施工:${params.data.y}}`
  426. : params.name,
  427. rich:{
  428. myStyle: {
  429. color: "#fff", // 文字颜色
  430. fontSize: 12, // 字体大小
  431. lineHeight: 18
  432. }
  433. },
  434. borderColor: "rgba(56,236,250)", // 边框颜色
  435. backgroundColor: "#0E7884",
  436. borderWidth: 1,
  437. padding: [4, 5], // 文字内边距(可选)
  438. borderRadius: 2, // 文字框圆角(可选)
  439. },
  440. data: this.points.map(({ name, coordinate, appOrg, x, y }) => ({
  441. name, // 点名称
  442. value: coordinate, // 经纬度坐标
  443. appOrg,
  444. x, // 额外数据(在建项目数)
  445. y, // 额外数据(施工项目数)
  446. })),
  447. },
  448. ],
  449. };
  450. // 地图注册,第一个参数的名字必须和option.geo.map一致
  451. echarts.registerMap("shanxi",shanxi)
  452. this.charts.setOption(option);
  453. // 监听点击事件
  454. this.charts.on("click", (params) => {
  455. if (params.componentType === "geo") {
  456. // 点击的是地图区域
  457. console.log("Clicked map area: ", params.name);
  458. } else if (params.componentType === "series") {
  459. // 点击的是自定义图标(scatter)
  460. this.appOrg = params.data.appOrg
  461. this.$emit('transmit', this.appOrg)
  462. // 销毁当前图表实例
  463. this.charts.dispose();
  464. // 重新初始化并设置新的配置项
  465. this.$nextTick(() => {
  466. getProjectByAppOrg(this.appOrg).then((res) => {
  467. if (Number(res.code) === 200) {
  468. for (let it of res.data){
  469. let coordinate = []
  470. let obj = {}
  471. coordinate.push(it.abscissa)
  472. coordinate.push(it.ordinate)
  473. obj.coordinate = coordinate
  474. obj.name = it.projectName
  475. obj.appOrg = it.appOrg
  476. obj.subdivision = it.subdivision
  477. this.projectList.push(obj)
  478. }
  479. this.sign = 1
  480. this.backAppOrg = this.appOrg
  481. this.initChildren(params.name) // 重新初始化图表
  482. this.showBack = true
  483. }
  484. })
  485. });
  486. }
  487. });
  488. },
  489. initChildren(cityName){
  490. this.backName = cityName
  491. this.childCharts = echarts.init(this.$refs["charts"]);
  492. const geoData = this.dataSource[cityName].features.map((feature) => ({
  493. name: feature.properties.name,
  494. value: feature.properties.appOrg,
  495. properties: feature.properties // 绑定 properties
  496. }));
  497. const option = {
  498. // 设置背景颜色,"transparent" 表示透明背景
  499. backgroundColor: "transparent",
  500. // 提示浮窗(Tooltip)配置
  501. tooltip: {
  502. show: true, // 是否显示 tooltip
  503. trigger: "item", // 触发类型,"item" 表示鼠标悬浮在图形上时触发
  504. formatter: `{b}`,
  505. backgroundColor: "rgba(5,13,21,0.25)", // 提示框背景颜色(半透明黑色)
  506. borderColor: "rgba(0, 0, 0, 0.16)", // 边框颜色
  507. triggerOn: "mousemove", // 鼠标移动时触发
  508. enterable: true, // 允许鼠标移动到 tooltip 内部(适用于可点击 tooltip)
  509. textStyle: {
  510. color: "#fff", // 文字颜色
  511. fontSize: 12, // 字体大小
  512. overflow: "break", // 文字超出时换行
  513. },
  514. padding: 3, // 提示框内边距
  515. },
  516. // 地理坐标系组件(用于地图绘制)
  517. geo: {
  518. map: "child", // 使用 "shanxi" 地图
  519. zoom: 1.1, // 初始缩放比例(可调整地图大小)
  520. itemStyle: {
  521. borderColor: "#11F6F2", // 地图区域边界颜色
  522. borderWidth: 5, // 边界宽度
  523. shadowColor: "#0E7683", // 地图阴影颜色
  524. shadowBlur: 0, // 阴影模糊度
  525. shadowOffsetX: 5, // 阴影水平偏移
  526. shadowOffsetY: 13, // 阴影垂直偏移
  527. },
  528. layoutCenter: ["50%", "50%"], // 控制地图的中心位置
  529. },
  530. // 图表数据系列(series)
  531. series: [
  532. {
  533. type: "map", // 地图类型
  534. map: "child", // 绑定的地图名称(与 `geo` 对应)
  535. zoom: 1.1, // 缩放级别
  536. itemStyle: {
  537. areaColor: { image: imgElement, repeat: "no-repeat" }, // 地图区域背景颜色(使用图片填充)
  538. borderColor: "#11F4F0", // 地图边界颜色
  539. borderWidth: 1, // 地图边界宽度
  540. },
  541. emphasis: {
  542. itemStyle: {
  543. areaColor: "#0D7481", // 鼠标悬浮时的区域颜色
  544. },
  545. },
  546. select: { disabled: true }, // 禁用地图的选中状态,防止点击后颜色锁定
  547. label: {
  548. show: true, // 显示区域名称
  549. color: "#11F6F2", // 文字颜色
  550. fontSize: 12, // 文字大小
  551. emphasis: { color: "#11F6F2" }, // 悬浮时的文字颜色
  552. },
  553. data: geoData
  554. },
  555. {
  556. type: "scatter", // 散点图(用于标注特殊位置)
  557. coordinateSystem: "geo", // 使用 `geo` 作为坐标系
  558. symbol: "image://" + require("@/assets/images/main/map/xian.png"), // 自定义标记
  559. symbolSize: 12, // 标记的大小
  560. data: this.projectList.filter(({ subdivision }) => subdivision <= 10).map(({ name, coordinate }) => ({
  561. name, // 点名称
  562. value: coordinate // 经纬度坐标
  563. })),
  564. },
  565. {
  566. type: "scatter", // 散点图(用于标注特殊位置)
  567. coordinateSystem: "geo", // 使用 `geo` 作为坐标系
  568. symbol: 'circle', // 自定义标记
  569. symbolSize: 12, // 标记的大小
  570. itemStyle: {
  571. color: 'yellow'
  572. },
  573. data: this.projectList.filter(({ subdivision }) => subdivision > 10).map(({ name, coordinate }) => ({
  574. name, // 点名称
  575. value: coordinate // 经纬度坐标
  576. })),
  577. }
  578. ]
  579. };
  580. echarts.registerMap("child", this.dataSource[cityName])
  581. this.childCharts.setOption(option);
  582. this.childCharts.on("click", (params) => {
  583. if (params.componentType === "geo") {
  584. // 点击的是地图区域
  585. console.log("Clicked map area: ", params.name);
  586. } else if (params.componentType === "series") {
  587. // 点击的是自定义图标(scatter)
  588. console.log(params.data.value)
  589. this.appOrg = params.data.value
  590. this.$emit('transmit', this.appOrg)
  591. // 销毁当前图表实例
  592. this.childCharts.dispose();
  593. // 重新初始化并设置新的配置项
  594. this.$nextTick(() => {
  595. this.projectList = []
  596. getProjectByAppOrg(this.appOrg).then((res) => {
  597. if (Number(res.code) === 200) {
  598. for (let it of res.data){
  599. let coordinate = []
  600. let obj = {}
  601. coordinate.push(it.abscissa)
  602. coordinate.push(it.ordinate)
  603. obj.coordinate = coordinate
  604. obj.name = it.projectName
  605. this.projectList.push(obj)
  606. }
  607. this.sign = 2
  608. this.initChildrenEx(params.name) // 重新初始化图表
  609. this.showBack = true
  610. }
  611. })
  612. });
  613. }
  614. });
  615. },
  616. initChildrenEx(cityName){
  617. this.childExCharts = echarts.init(this.$refs["charts"]);
  618. const option = {
  619. // 设置背景颜色,"transparent" 表示透明背景
  620. backgroundColor: "transparent",
  621. // 提示浮窗(Tooltip)配置
  622. tooltip: {
  623. show: true, // 是否显示 tooltip
  624. trigger: "item", // 触发类型,"item" 表示鼠标悬浮在图形上时触发
  625. formatter: `{b}`,
  626. backgroundColor: "rgba(5,13,21,0.25)", // 提示框背景颜色(半透明黑色)
  627. borderColor: "rgba(0, 0, 0, 0.16)", // 边框颜色
  628. triggerOn: "mousemove", // 鼠标移动时触发
  629. enterable: true, // 允许鼠标移动到 tooltip 内部(适用于可点击 tooltip)
  630. textStyle: {
  631. color: "#fff", // 文字颜色
  632. fontSize: 12, // 字体大小
  633. overflow: "break", // 文字超出时换行
  634. },
  635. padding: 3, // 提示框内边距
  636. },
  637. // 地理坐标系组件(用于地图绘制)
  638. geo: {
  639. map: "childEx", // 使用 "shanxi" 地图
  640. zoom: 1.1, // 初始缩放比例(可调整地图大小)
  641. itemStyle: {
  642. borderColor: "#11F6F2", // 地图区域边界颜色
  643. borderWidth: 5, // 边界宽度
  644. shadowColor: "#0E7683", // 地图阴影颜色
  645. shadowBlur: 0, // 阴影模糊度
  646. shadowOffsetX: 5, // 阴影水平偏移
  647. shadowOffsetY: 13, // 阴影垂直偏移
  648. },
  649. layoutCenter: ["50%", "50%"], // 控制地图的中心位置
  650. },
  651. // 图表数据系列(series)
  652. series: [
  653. {
  654. type: "map", // 地图类型
  655. map: "childEx", // 绑定的地图名称(与 `geo` 对应)
  656. zoom: 1.1, // 缩放级别
  657. itemStyle: {
  658. areaColor: { image: imgElement, repeat: "no-repeat" }, // 地图区域背景颜色(使用图片填充)
  659. borderColor: "#11F4F0", // 地图边界颜色
  660. borderWidth: 1, // 地图边界宽度
  661. },
  662. emphasis: {
  663. itemStyle: {
  664. areaColor: "#0D7481", // 鼠标悬浮时的区域颜色
  665. },
  666. },
  667. select: { disabled: true }, // 禁用地图的选中状态,防止点击后颜色锁定
  668. label: {
  669. show: true, // 显示区域名称
  670. color: "#11F6F2", // 文字颜色
  671. fontSize: 12, // 文字大小
  672. emphasis: { color: "#11F6F2" }, // 悬浮时的文字颜色
  673. }
  674. },
  675. {
  676. type: "scatter", // 散点图(用于标注特殊位置)
  677. coordinateSystem: "geo", // 使用 `geo` 作为坐标系
  678. symbol: 'circle', // 自定义标记
  679. symbolSize: 10, // 标记的大小
  680. itemStyle: {
  681. color: 'yellow'
  682. },
  683. data: this.projectList.map(({ name, coordinate }) => ({
  684. name, // 点名称
  685. value: coordinate // 经纬度坐标
  686. })),
  687. },
  688. ]
  689. };
  690. echarts.registerMap("childEx", this.dataSource[cityName])
  691. this.childExCharts.setOption(option);
  692. },
  693. beBack(sign){
  694. if (sign === 1){
  695. this.sign = 0
  696. this.projectList = []
  697. this.childCharts.dispose();
  698. this.initCharts()
  699. this.showBack = false
  700. this.appOrg = "10001"
  701. this.$emit('transmit', this.appOrg)
  702. }
  703. else {
  704. this.projectList = []
  705. this.childExCharts.dispose();
  706. this.appOrg = this.backAppOrg
  707. this.$emit('transmit', this.appOrg)
  708. this.$nextTick(() => {
  709. getProjectByAppOrg(this.appOrg).then((res) => {
  710. if (Number(res.code) === 200) {
  711. for (let it of res.data){
  712. let coordinate = []
  713. let obj = {}
  714. coordinate.push(it.abscissa)
  715. coordinate.push(it.ordinate)
  716. obj.coordinate = coordinate
  717. obj.name = it.projectName
  718. obj.appOrg = it.appOrg
  719. obj.subdivision = it.subdivision
  720. this.projectList.push(obj)
  721. }
  722. this.sign = 1
  723. this.initChildren(this.backName)
  724. this.showBack = true
  725. }
  726. })
  727. });
  728. }
  729. }
  730. },
  731. };
  732. </script>
  733. <style scoped>
  734. </style>