小元
博客
详情文字在这里缓缓展开
静候你翻开这一页

echarts系列之 - 中国地图

echarts地图的应用,有关echarts中国地图区域的实现

echarts实现中国地图


   效果图:

1713507159395.png


   说明:

       该效果为简单的中国区域图,在下方的代码中无法支持它实现点击某个城市后放大显示当前城市的操作?。


   前提准备:

       该效果基于Vue2 + Echarts实现,所以您应该满足以上条件。

       V u e 请  参 考?  https://cn.vuejs.org/guide/introduction.html

       Echarts请参考 ?  https://echarts.apache.org/zh/index.html

          中国JSON数据 ? https://pan.quark.cn/s/1f91f6dce387

          Echarts的安装:

cnpm i echarts -S

 

   代码:

       china.json 的数据来源于上面的中国JSON数据

<template>
  <div class="mapBox">
    <div ref="refMap" id="refMap" class="maps"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts';

import chinaMap from './china.json';

export default {
  data() {
    return {
      myChart: undefined,
      cityPointSet: chinaMap.features.map((r) => ({
        name: r.properties.name,
        center: r.properties.center,
        centroid: r.properties.centroid,
      })),
      cityPoint: [],
    };
  },
  methods: {
    drawMap() {
      echarts.registerMap('china', { geoJSON: chinaMap });
      const myChart = echarts.init(document.getElementById('refMap'));

      const option = {
        geo: {
          map: 'china',
          aspectScale: 0.85,
          layoutCenter: ['50%', '56%'],
          layoutSize: '113%',
          itemStyle: {
            normal: {
              shadowColor: '#8ec1d6',
              shadowOffsetX: 0,
              shadowOffsetY: 15,
              opacity: 1,
            },
            emphasis: {
              areaColor: '#276fce',
            },
          },
          regions: [{
            name: '南海诸岛',
            itemStyle: {
              areaColor: 'rgba(0, 10, 52, 1)',
              borderColor: 'rgba(0, 10, 52, 1)',
              normal: {
                opacity: 0,
                label: {
                  show: false,
                  color: '#009cc9',
                },
              },
            },
            label: {
              show: false,
              color: '#FFFFFF',
              fontSize: 12,
            },
          }],
        },
        series: [
          // 常规地图
          {
            type: 'map',
            mapType: 'china',
            aspectScale: 0.85,
            // 地图位置
            layoutCenter: ['50%', '56%'],
            layoutSize: '113%',
            zoom: 1,
            roam: false,
            scaleLimit: {
              min: 1,
              max: 2,
            },
            // 各区域名称样式配置
            itemStyle: {
              normal: {
                areaColor: '#010508',
                borderColor: '#5c7f8e',
                borderWidth: 1.5,
                label: {
                  show: true,
                  color: '#fff',
                },
              },
              // 区域选中后的配置
              emphasis: {
                areaColor: '#02102b',
                borderColor: '#e49e03',
                label: {
                  show: true,
                  color: '#fff',
                },
              },
            },
            select: {
              itemStyle: {
                areaColor: '#010508',
                borderColor: 'yellow',
              },
              label: {
                show: true,
                color: '#fff',
              },
            },
            data: [],
          },
        ],
      };

      myChart.setOption(option);
      this.myChart = myChart;
      // 默认选中第一项区域高亮
      this.myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: 0,
      });
    },
  },
  mounted() {
    setTimeout(() => {
      this.drawMap();
    }, 200);
  },
};
</script>

<style>
*{
  margin: 0;
  padding: 0;
}
.mapBox{
  width: 100%;
  height: 100vh;
  background: #040d1c;
  display: flex;
  align-items: center;
  justify-content: space-around;
  color: #fff;
}
.maps{
  width: 927px;
  height: 800px;
}

</style>


  ?如果感觉本文章对您有所帮助的话,点个赞吧~?

渝ICP备2024031078号-1
本网站一切内容不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
如无意中侵犯了企业或个人的知识产权等,请及时通过电子邮件(1102905617@qq.com)告知我,本网站将会给予删除。
最新公告
😊访客你好,很高兴你的到来,本博客仍在建设中,还有些许功能尚在开发中,最后祝你在此能有所收获。
💥小元博客第三代自2025年9月上线以来,2026/08/09日迎来了它的第三次更新本次更新内容如下:
1. 文章详情页样式变更,由原来的弹窗改为单独的页面。
2. 使用Nuxt对项目进行了SEO优化,优化了搜索引擎的抓取和索引。
3. 对验签进行了优化,降低了请求被误触发拦截的概率。
4. 移动端也正在稳步推进中,在不久的将来会与大家见面。
5. 修复了首页黄历节日不显示的问题,以及其它bug的修复。