• Vue2 + Echarts实现3D地图下钻


    一、npm安装组件:

    1. "echarts": "5.4.0",
    2. "echarts-gl": "^2.0.9",
    3. "element-china-area-data": "^5.0.2",

    二、Vue页面

    1. <template>
    2. <div class="Map3D" id="Map3D" ref="Map3D" @click="toBack"></div>
    3. </template>
    4. <script>
    5. import LongNanJson from '../../../public/static/city/longnan.json';
    6. import axios from 'axios';
    7. import {TextToCode} from "element-china-area-data";
    8. import 'echarts-gl'
    9. export default {
    10. data() {
    11. return {
    12. chartMap: {},
    13. option: null,
    14. };
    15. },
    16. props: {},
    17. created() {
    18. },
    19. mounted() {
    20. this.$nextTick(() => {
    21. this.initMap();
    22. });
    23. window.addEventListener('resize', this.resize)
    24. },
    25. beforeDestroy() {
    26. if (!this.chartMap) {
    27. return
    28. }
    29. this.chartMap.dispose()
    30. this.chartMap = null
    31. window.removeEventListener('resize', this.resize)
    32. },
    33. methods: {
    34. // 初始化地图
    35. initMap() {
    36. this.chartMap = this.$echarts.init(document.querySelector('.Map3D'));
    37. this.chartMap = this.$echarts.init(this.$refs.Map3D);
    38. this.$echarts.registerMap('LongNan', LongNanJson)
    39. this.option = {
    40. series: [
    41. {
    42. type: 'map3D',
    43. name: '地图',
    44. selectedMode: 'single', // 地图高亮单选
    45. regionHeight: 5, // 地图高度
    46. map: 'LongNan',
    47. viewControl: {
    48. distance: 120, // 地图视角 控制初始大小
    49. alpha: 50,// 倾斜角度
    50. rotateSensitivity: [1, 1]
    51. },
    52. label: {
    53. show: true, // 是否显示名字
    54. color: '#fff', // 文字颜色
    55. fontSize: 18, // 文字大小
    56. fontWeight: 'bold', // 文字大小
    57. },
    58. itemStyle: {
    59. color: '#224a7b', // 地图背景颜色
    60. borderWidth: 1, // 分界线width
    61. borderColor: '#207fce', // 分界线颜色
    62. opacity: 0.72
    63. },
    64. emphasis: {
    65. label: {
    66. show: true, // 是否显示高亮
    67. textStyle: {
    68. color: 'yellow' // 高亮文字颜色
    69. }
    70. },
    71. itemStyle: {
    72. color: '#007ee8', // 地图高亮颜色
    73. borderColor: '#6becf5'// 分界线颜色
    74. }
    75. },
    76. light: {
    77. main: {
    78. color: '#fff',
    79. intensity: 1,
    80. shadow: true,
    81. shadowQuality: 'high',
    82. alpha: 25, //
    83. beta: 20
    84. },
    85. ambient: {
    86. color: '#fff',
    87. intensity: 0.6
    88. }
    89. }
    90. }
    91. ]
    92. };
    93. this.chartMap.setOption(this.option)
    94. this.chartMap.on('click', (param) => {
    95. event.stopPropagation() // 阻止冒泡
    96. if (param.name) {
    97. const areaCode = TextToCode['甘肃省']['陇南市'][param.name].code;
    98. this.getCountyOption(areaCode)
    99. }
    100. });
    101. },
    102. // 显示各区县地图
    103. getCountyOption(areaCode) {
    104. axios.get('static/county/' + areaCode + '.json').then((result) => {
    105. this.$echarts.registerMap(areaCode, result.data)
    106. this.option.series[0].map = areaCode
    107. this.chartMap.setOption(this.option, true);
    108. });
    109. },
    110. // 点击页面, 返回显示中国地图
    111. toBack() {
    112. this.$echarts.registerMap('LongNan', LongNanJson)
    113. this.option.series[0].map = 'LongNan'
    114. this.chartMap.setOption(this.option, true);
    115. },
    116. resize() {
    117. this.chartMap.resize()
    118. },
    119. },
    120. };
    121. </script>
    122. <style lang="scss" scoped>
    123. .Map3D {
    124. width: 100%;
    125. height: 100%;
    126. }
    127. </style>

  • 相关阅读:
    JAVA该怎么学习,到公司会学的一样吗
    【ICer的脚本练习】“精通各种语言的hello world!“
    Slurm基本使用
    异构计算技术分析
    java Date
    高新技术企业认定八大条件、八大领域、四项指标
    STM32单片机蓝牙APP手势语音温控电风扇落地扇人体感应
    spring cloud nacos服务搭建
    小程序源码:独立后台带分销功能月老办事处交友盲盒-多玩法安装简单
    跨平台应用开发进阶(二十七)安卓应用加固签名后应用无法打开
  • 原文地址:https://blog.csdn.net/oschina_41140683/article/details/134014275