vue3中使用echarts区域地图

首先讲清楚一点,实现区域地图,需要边缘区域的经纬度。那么经纬度的数据源自哪里呢?当然我白嫖啦~

白嫖网站:https://datav.aliyun.com/portal/school/atlas/area_selector

 

直接拿这个url

也就是说 需要发送请求。我们直接就fetch请求,或者axiso,我就用axios测试一下吧。

代码:

#html
<template>
	<div>
		<!-- 地图 -->
		<div id="map_view" style="width: 50vw;height: 600px;"></div>
	</div>
</template>

js部分(用了语法糖): 

import { onMounted } from 'vue';
import request from '../api/index'
import * as echarts from "echarts";

onMounted(() => {
  const mapOption = {
    animation: true,
    geo: {
      map: 'hunan',
      zoom: 1.2,
      label: {
        show: true,
        color: '#fff',
        fontSize: 25
      },
      // 选中状态下的多边形和标签样式
      emphasis: {
        itemStyle: {
          color: '#008ff2', //地图背景色
          borderColor: '#516a89', //省市边界线00fcff 516a89
          borderWidth: 1
        },
        label: {
          color: '#fff'
        }
      },
      roam: true,// 允许缩放
      itemStyle: {
        normal: {
          color: '#100c2a', //地图背景色
          borderColor: '#516a89', //省市边界线00fcff 516a89
          borderWidth: 1,
        },
      }
    }
  }

  const mapChart = echarts.init(document.getElementById('map_view'));
  request.get('https://geo.datav.aliyun.com/areas_v3/bound/430000_full.json').then(res => {
    echarts.registerMap('hunan', res.data);
    mapChart.setOption(mapOption);
  })
})
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值