antv g2绘制中国地图及每个省份区域单独展示

  1. 使用技术: antv g2
  2. 地图文件:https://gw.alipayobjects.com/os/antvdemo/assets/data/china-provinces.geo.json
    该文件可以直接在线引入,也可以下载到本地使用,在这里我是直接下载到本地的
  3. html代码
<template>
    <div class="map-wrapper">
        <div class="content" ref="mapChart">
        	<!-- 装载地图的容器-->
            <div id="map" ></div>
        </div>
    </div>
</template>
  1. 引入文件
    引入的前提是本地需要安装dataset和@antv/g2
import DataSet from '@antv/data-set'
import * as G2 from "@antv/g2"
import GeoJSON from '../js/map.json'
  1. 绘制地图
data() {
   
        return {
   
            userView: null,
            GeoJSON,
            ds: '',
            mapDv: null
        }
    },
    created() {
   
    },
    watch: {
   
        data(val) {
   
            val.forEach(item => {
   
                GeoJSON.features.forEach(ele => {
   
                    if (ele.properties.name.indexOf(item.name) > -1) {
   
                        item.name = ele.properties.name
                    }
                })
            })
            const userDv = this.formateData(val)
            this.userView.changeData(userDv)
        }
    },
    methods: {
   
        init() {
   
            const chartWidth = this.$refs.mapChart.clientWidth
            const chartHeight = this.$refs.mapChart.clientHeight
            this.chart = new G2.Chart({
   
                container: 'map',
                width: chartWidth,
                height: chartHeight,
                padding: [30]
            })
            this.chart.scale({
   
                longitude: {
   
                    nice: false,
                    sync: true
                },
              
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值