WorldMapNew.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <div>
  3. <div class="mapBg">
  4. <div class="worldMap" id="worldMap" ref="worldMap" height="300"></div>
  5. </div>
  6. <div v-if="dialogVisible" style="background:#fff;left:50%;top:30%;
  7. position:absolute;z-index:10000;border:1px oslid red;width:50%;height:300px;">
  8. <h1 align="center">这里是国家地图</h1>
  9. <button style="margin-top:30%;" @click="dialogVisible=false">关闭</button>
  10. </diV>
  11. </div>
  12. </template>
  13. <script>
  14. import * as echarts from 'echarts'
  15. import mapData from '../utils/map.js'
  16. var cityData = [{
  17. name: '长春',
  18. value: [125.299633, 43.914039, 10],
  19. }, ]
  20. var szPoinUrl = "";
  21. let imgBase64 = ''
  22. let tempData1 = [{
  23. name: '环境监测',
  24. value: [-73.97622, 40.757498],
  25. ph: 200,
  26. offset: [70, -58],
  27. padding: [12, 25, 56, 80],
  28. imgurl: '',
  29. }];
  30. export default {
  31. mounted() {
  32. var worldChart = echarts.init(this.$refs["worldMap"]);
  33. echarts.registerMap('world', mapData.registerMapData);
  34. worldChart.setOption(this.option);
  35. worldChart.on("georoam", function (params) {
  36. var option = worldChart.getOption(); //获得option对象
  37. if (params.zoom != null && params.zoom != undefined) {
  38. //捕捉到缩放时
  39. let mo = option.geo[0].zoom
  40. option.geo[0].zoom = option.series[0].zoom; //下层geo的缩放等级跟着上层的geo一起改变
  41. option.geo[0].center = option.series[0].center; //下层的geo的中心位置随着上层geo一起改变
  42. // // 改变标记点随地图放大缩小
  43. // // console.log(option.series)
  44. // let size = option.series[0].zoom/mo
  45. // if(option.series[0].zoom>mo){
  46. // // console.log(option.series)
  47. // option.series[2].symbolSize = [option.series[2].symbolSize[0]*size,option.series[2].symbolSize[1]*size]
  48. // option.series[1].symbolSize=option.series[1].symbolSize*size
  49. // option.series[1].label.fontSize=option.series[1].label.fontSize*size
  50. // }else{
  51. // option.series[2].symbolSize = [option.series[2].symbolSize[0]*size,option.series[2].symbolSize[1]*size]
  52. // option.series[1].symbolSize = option.series[1].symbolSize*size
  53. // option.series[1].label.fontSize = option.series[1].label.fontSize*size
  54. // }
  55. // // 改变标记点end
  56. } else {
  57. //捕捉到拖曳时
  58. option.geo[0].center = option.series[0].center; //下层的geo的中心位置随着上层geo一起改变
  59. }
  60. // myChart.dispatchAction({ //来用程序主动渲染选框
  61. // type: "restore",
  62. // });
  63. worldChart.setOption(option); //设置option
  64. });
  65. //
  66. worldChart.on('click', params => {
  67. console.log(111111111111)
  68. this.dialogVisible = true;
  69. })
  70. },
  71. computed: {
  72. series() {
  73. let res = [{
  74. type: "map",
  75. roam: true,
  76. animationDurationUpdate: true,
  77. label: {
  78. show: !1,
  79. },
  80. tooltip: {
  81. show: !1,
  82. },
  83. itemStyle: {
  84. normal: {
  85. borderColor: "#0F6DAC",
  86. borderWidth: 0.2,
  87. areaColor: {
  88. type: "radial",
  89. x: 0.5,
  90. y: 0.5,
  91. r: 0.8,
  92. colorStops: [{
  93. offset: 0,
  94. color: "#061D35", // 0% 处的颜色
  95. },
  96. {
  97. offset: 1,
  98. color: "#061D35", // 100% 处的颜色
  99. },
  100. ],
  101. globalCoord: true, // 缺省为 false
  102. },
  103. },
  104. emphasis: {
  105. label: {
  106. // show: !1,
  107. color: "#fff",
  108. },
  109. areaColor: "#05223D",
  110. // shadowColor: 'rgb(12,25,50)',
  111. borderWidth: 0.2,
  112. },
  113. },
  114. aspectScale: 0.65, //长宽比
  115. zoom: 1.12,
  116. // roam: false,
  117. map: "world", //使用
  118. // data: this.difficultData //热力图数据 不同区域 不同的底色
  119. }]
  120. tempData1.forEach(item => {
  121. res.push({
  122. type: 'scatter',
  123. coordinateSystem: 'geo',
  124. symbol: szPoinUrl,
  125. symbolSize: [20, 20],
  126. legendHoverLink: true,
  127. z: 99999,
  128. index: 99999,
  129. label: {
  130. show: true,
  131. offset: item.offset, //偏移设置
  132. fontSize: 14,
  133. lineHeight: 23,
  134. backgroundColor: {
  135. image: item.imgurl,
  136. },
  137. borderColor: '#106EAD',
  138. padding: item.padding,
  139. formatter(value) {
  140. return `{name|${value.data.name}\nPH值:${value.data.ph}}`;
  141. },
  142. rich: {
  143. name: {
  144. fontWeight: 'bold',
  145. fontSize: 16,
  146. color: '#fff',
  147. height: 100,
  148. }
  149. },
  150. color: '#fff',
  151. },
  152. data: [item],
  153. showEffectOn: 'render',
  154. rippleEffect: {
  155. brushType: 'stroke',
  156. },
  157. hoverAnimation: true,
  158. zlevel: 9999,
  159. },
  160. )
  161. })
  162. return res
  163. },
  164. option() {
  165. return {
  166. // backgroundColor: '#051421',
  167. backgroundColor: 'transparent',
  168. tooltip: {
  169. trigger: "item",
  170. formatter: function (params, ticket, callback) {
  171. if (params.seriesType == "effectScatter") {
  172. return params.marker + params.data.name + "" + params.data.value[2];
  173. } else if (params.seriesType == "lines") {
  174. return params.data.fromName + " -> " + params.data.toName + "<br />" + params.data.value;
  175. } else {
  176. return params.name;
  177. }
  178. },
  179. },
  180. grid: {
  181. right: '8%',
  182. // top:'5%'
  183. },
  184. geo: {
  185. map: 'world',
  186. aspectScale: 0.65, //长宽比
  187. zoom: 1.12,
  188. show: true,
  189. tooltip: {
  190. show: !1,
  191. },
  192. scaleLimit: {
  193. min: 1,
  194. max: 5,
  195. },
  196. label: {
  197. show: !1,
  198. },
  199. animationDurationUpdate: 0,
  200. roam: true,
  201. itemStyle: {
  202. normal: {
  203. shadowColor: "#164A7C",
  204. shadowOffsetX: 5,
  205. shadowOffsetY: 5,
  206. },
  207. },
  208. },
  209. tooltip: {
  210. trigger: "item",
  211. },
  212. zlevel: 999,
  213. series: this.series
  214. }
  215. }
  216. },
  217. data() {
  218. return {
  219. dialogVisible: false
  220. }
  221. },
  222. }
  223. </script>
  224. <style scoped>
  225. .worldMap {
  226. display: inline-block;
  227. width: 100%;
  228. height: 100vh;
  229. background: #051421;
  230. position: absolute;
  231. z-index: -1;
  232. }
  233. .mapBg {
  234. /* background: #051421;
  235. position: absolute;
  236. z-index: -1; */
  237. }
  238. </style>