三步完成echers展示离线地图

1.首先要去阿里云提供的地图选择器网站选择你需要下载的地图矢量数据。链接

以湖北省为例:

 2.复制上图中的JSON API,在浏览器输入json api链接,可以看到数据格式是很规整的json数据,在浏览器中右键保存为json格式数据,如本文保存为hubei.json。如图所示;

 3.将json文件放到你需要的项目中,并引入。

// ...全局引入echerts
// 引入json文件
import hubei from './Json/hubei.json'

export default {

    //  ....省略
    mounted(){
         echarts.registerMap('湖北省', hubei)
         this.getEcharts()
    },
    metheds: {
        getEcharts() {
                let myChart = echarts.init(document.getElementById('mapChart'));
                let option = {
                    roamController: {
                    show: true,
                    x: 'right',
                    // mapTypeControl: {
                    //     '湖北省': true
                    // }
                    },
                    // geo: {
                    //     itemStyle: {
                    //         areaColor: 'transparent'
                    //     }
                    // },
                    series: [{
                        type: 'map',
                        map: '湖北省',
                        roam: false,
                        label: {
                            normal: {
                                show: true,
                                position: "centerTop",
                                height: 20,
                                padding: 3,
                                rich: {
                                    d: {
                                        color: '#fff',
                                        textBorderColor: '#000',
                                        textBorderWidth: 1,
                                        fontSize: 10,
                                        lineHeight: 24,
                                        width: 50,
                                        height: 24,
                                        marginTop: 20,
                                        align: 'center'
                                    },

                                },
                                formatter: '{d|{b}}',
                                textStyle: {
                                    color: "#ccc",
                                    fontSize: "10",
                                },
                            },
                        },
                        itemStyle: {
                            normal: {
                                color: 'transparent',
                                borderColor: '#3e91be',
                                areaColor: 'transparent',
                                areaStyle: { areaColor: 'transparent', },
                                textStyle: {
                                    color: 'red' //省份字体颜色
                                }
                            },
                        },
                        data: [],
                    }],
                }
                myChart.setOption(option)
                window.onresize = myChart.resize
            },

    }
}

4.展示

 tips: 如果你需要其他格式的文件,可以使用在线转换工具。 在线转换工具

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值