echarts 3D地图

通过echats echats-gl 实现的3D地图页面。

先上效果图:
在这里插入图片描述
1.通过外边js引入方式,引入必要的js压缩文件

<script src="/static/vue-v2/vue.js"></script>
<script src="/static/assets/echarts-v5/echarts.min.js"></script>
<script src="/static/assets/echarts-v5/echarts-gl.min.js"></script> 
2.新建mixins混入的map.js 文件`

var mixins = {
data() {
return {
city: [],//数据格式
min: 0,
max: 300,
currentMouseOverIndex: null,
hasMap: false,
cityJson: null,
regionCode: ‘tangshan’,
chart: ‘’,
};
},
watch: {
},
mounted() {
window.addEventListener(“resize”, this.handleWindowResize);
this.getJson(‘唐山市’)
},
methods: {
// 返回上一级
backHistory() {
this.getJson(‘唐山市’)
},
// 引入json
getJson(name,paramsData=[], isInit = true) {
//通过 fetch 方法引入json
fetch(/static/index/js/map/${name}.json)
.then(response => response.json())
.then(data => {
let cityData = [];
if (isInit) {
data.features.map(el => {
const obj = { //city数据格式
name: el.properties.name,
code: el.properties.adcode,
value: Math.floor(Math.random() * (500 - 100) + 100)
};
cityData.push(obj)
});
this.city = cityData;
}else{
this.city=paramsData
}

                this.cityJson = data;
            
                let alphabets = [];
                for (let i = 65; i <= 90; i++) {
                    alphabets.push(String.fromCharCode(i));
                }
                let regionCode = ""
                for (let i = 0; i < 10; i++) {
                    regionCode += alphabets[Math.floor(Math.random() * 25)];
                } 
                //regionCode 随机生成的,地图名称要用到
                this.echartschange(regionCode, this.city);
            });

    },
    /**
     * 当窗口缩放时,echart动态调整自身大小
     */
    handleWindowResize() {
        if (!this.chart) return;
        this.chart.resize();
    },
    handleData(city) {
        let max = Math.max.apply(
            Math,
            city.map((item) => {
                return item.value;
            })
        );
        this.max = Math.ceil(max / 7) * 7;
        // 最小值 1
        let min = Math.min.apply(
            Math,
            city.map((item) => {
                return item.value;
            })
        );
        this.min = Math.floor(min);
    },
    echartschange(regionCode, cityData) {
        this.chart && this.chart.clear();
        let city = cityData ? cityData : this.city;
        if (!city || city.length === 0) return;
        this.handleData(city);
        console.log('mainchart:', this.$refs.mainchart)
        let that = this;
        this.chart = echarts.init(this.$refs.mainchart);
        
        echarts.registerMap(regionCode, this.cityJson); 
        let option = {
            tooltip: {
                formatter: function (params) {
                    let result = "";
                    result = `
			                  <div style="width:196px;height:120px;margin-top:-12px;background:#192E5E; ">
			                    <div style="width:100%;overflow:hidden;font-size:16px;font-weight:bold;color: #12C49B;padding:10px 0 4px 0"> 
			                      <span style="display:inline-block">${params.name}</span>
			                    </div>
			                    <div style="font-size:14px;padding:2px 0 2px 0">
			                      <span style="color:rgba(203, 255, 248, 1)">项目数量</span>
			                      <span style="color:rgba(18, 196, 155, 1)">${params.data.value}</span>
			                    </div> 
			                  </div>
           				 `;
                    return result;
              
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

长影缚苍龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值