全球 geoJson
https://blog.csdn.net/qq_42566295/article/details/81132823

省市区事件预警可视化

image.png

  1. <template>
  2. <div class="chart" ref="box"/>
  3. </template>
  4. <script>
  5. import {
  6. onMounted, getCurrentInstance, defineComponent
  7. } from 'vue';
  8. import { ProvinceData } from 'china-map-geojson';
  9. import * as echarts from 'echarts/core';
  10. import {
  11. TitleComponent,
  12. ToolboxComponent,
  13. TooltipComponent,
  14. VisualMapComponent,
  15. GeoComponent
  16. } from 'echarts/components';
  17. import {
  18. MapChart
  19. } from 'echarts/charts';
  20. import {
  21. CanvasRenderer
  22. } from 'echarts/renderers';
  23. echarts.use(
  24. [
  25. TitleComponent, ToolboxComponent, TooltipComponent,
  26. VisualMapComponent, GeoComponent, MapChart, CanvasRenderer
  27. ]
  28. );
  29. const cityCenter = ProvinceData.Jiangsu.features.map((item) => {
  30. const { name, cp } = item.properties
  31. return { name, cp, value: Math.random() * 100 }
  32. });
  33. export default defineComponent({
  34. setup() {
  35. onMounted(() => {
  36. const { ctx } = getCurrentInstance();
  37. const element = ctx.$refs.box;
  38. // 基于准备好的dom,初始化echarts实例
  39. const myChart = echarts.init(element);
  40. // 注册地图
  41. echarts.registerMap('Jiangsu', ProvinceData.Jiangsu);
  42. // 绘制图表
  43. myChart.setOption({
  44. visualMap: [
  45. { // 地图视觉映射
  46. type: 'continuous',
  47. show: true,
  48. max: 100,
  49. seriesIndex: [0], // map
  50. inRange: {
  51. color: ['#a5dcf4', '#006edd']
  52. }
  53. }
  54. ],
  55. geo: [ // 地图的基本配置
  56. {
  57. map: 'Jiangsu',
  58. roam: false, // 是否允许鼠标滚轮缩放
  59. zoom: 1.1, // 默认显示级别
  60. // geoIndex: -1,
  61. scaleLimit: { // 缩放级别
  62. min: 0,
  63. max: 3
  64. },
  65. itemStyle: { // 阴影效果
  66. normal: {
  67. areaColor: '#013C62',
  68. shadowColor: '#013C62',
  69. shadowBlur: 20,
  70. shadowOffsetX: -5,
  71. shadowOffsetY: 15
  72. }
  73. }
  74. }
  75. ],
  76. series: [
  77. { // 地图的高级配置,会覆盖 geo的配置,双地图有阴影效果
  78. type: 'map',
  79. mapType: 'Jiangsu',
  80. geoIndex: 1,
  81. scaleLimit: { // 缩放级别
  82. min: 0, max: 3
  83. },
  84. roam: false,
  85. zoom: 1.1, // 默认显示级别
  86. label: {
  87. show: true,
  88. color: '#fff',
  89. emphasis: {
  90. color: '#fff'
  91. }
  92. },
  93. itemStyle: {
  94. normal: {
  95. borderColor: '#2980b9',
  96. borderWidth: 1,
  97. areaColor: '#12235c'
  98. },
  99. emphasis: {
  100. areaColor: '#fa8c16',
  101. borderWidth: 0,
  102. }
  103. },
  104. data: cityCenter
  105. },
  106. {
  107. type: 'effectScatter',
  108. coordinateSystem: 'geo',
  109. // value 必须是个极坐标系
  110. data: [{ value: cityCenter[0].cp, city: cityCenter[0].name }],
  111. z: 5,
  112. symbolSize: 8,
  113. label: {
  114. normal: {
  115. show: true,
  116. formatter (params) {
  117. const { city, info } = params.data
  118. return `{fline|地点:${city}}\n{tline|${info || '发生化工厂爆炸'}}`;
  119. },
  120. position: 'top',
  121. backgroundColor: 'rgba(254,174,33,.8)',
  122. padding: [0, 0],
  123. borderRadius: 3,
  124. lineHeight: 32,
  125. color: '#f7fafb',
  126. rich: {
  127. fline: {
  128. padding: [0, 10, 10, 10],
  129. color: '#fff'
  130. },
  131. tline: {
  132. padding: [10, 10, 0, 10],
  133. color: '#fff'
  134. }
  135. }
  136. },
  137. emphasis: {
  138. show: true
  139. }
  140. },
  141. itemStyle: {
  142. color: '#feae21',
  143. // color: '#fff'
  144. }
  145. },
  146. {
  147. type: 'effectScatter',
  148. coordinateSystem: 'geo',
  149. z: 5,
  150. data: [{ value: cityCenter[2].cp, city: cityCenter[2].name }],
  151. symbolSize: 14,
  152. label: {
  153. normal: {
  154. show: true,
  155. formatter (params) {
  156. const { city, info } = params.data
  157. return `{fline|地点:${city}}\n{tline|${info || '冰雹和大范围强雷暴大风'}}`;
  158. },
  159. position: 'top',
  160. backgroundColor: 'rgba(233,63,66,.9)',
  161. padding: [0, 0],
  162. borderRadius: 3,
  163. lineHeight: 32,
  164. color: '#fff',
  165. rich: {
  166. fline: {
  167. padding: [0, 10, 10, 10],
  168. color: '#fff'
  169. },
  170. tline: {
  171. padding: [10, 10, 0, 10],
  172. color: '#fff'
  173. }
  174. }
  175. },
  176. emphasis: {
  177. show: true
  178. }
  179. },
  180. itemStyle: {
  181. color: '#e93f42'
  182. }
  183. },
  184. ]
  185. });
  186. });
  187. },
  188. });
  189. </script>
  190. <style scoped>
  191. .chart {
  192. height: 480px;
  193. }
  194. </style>