vue下echarts的地图配置(3d悬浮效果)

一.实现效果

图片上面的水印是公司软件自带的

二.html块代码

<div class="source-map-panel" id="chinaMap" ref="mapRef"></div>

 三.主代码

this.myChart = this.$echarts.init(document.getElementById("chinaMap")); // 这里是为了获得容器所在位置
      let options = {};
      options.tooltip = getTooltip(this);        //设置鼠标移动上去参数配置
      options.geo = getGeo(this);            //设置地图底层(实现3d效果)
      options.series = getSeries(this);    //设置地图数据

      this.myChart.setOption(options);

 四.配置数据

toolTip配置js文件如下 

import {toWan} from '@/utils/public.js'
export const getTooltip = (that) => {
    return {
        enterable: true, // 鼠标是否可进入提示框浮层中\
        hideDelay: 200, // 浮层隐藏的延迟
        confine: true,
        position: function (point, params, dom, rect, size) {
            // 提示框位置
            let x = 0; // x坐标位置
            let y = 0; // y坐标位置

            // 当前鼠标位置
            let pointX = point[0];
            let pointY = point[1];

            // 提示框大小
            let boxWidth = size.contentSize[0];
            let boxHeight = size.contentSize[1];

            if (boxWidth > pointX) {
                x = 5; // 自己定个x坐标值,以防出屏
                y -= 15; // 防止点被覆盖住,可根据情况自行调节
            } else {
                // 左边放的下
                x = pointX - boxWidth - 15;
            }

            if (boxHeight + 20 > pointY) {
                y = pointY + 15;
            } else if (boxHeight > pointY) {
                y = 5;
            } else {
                // 上边放得下
                y += pointY - boxHeight;
            }
            return [point[0] - boxWidth - 20, point[1] - 30];
        },

        backgroundColor: "rgba(255, 255, 255, 0.7)",
        padding: [15, 15, 15, 15],

        formatter: (params) => {
            let sumaryAmount, sumaryCnt, userCnt;
            var htmlStr = "";
            if (that.mapList) {
                let list = that.mapList;
                let dataList = list.filter(item => {
                    return item.name === params.name //判断返回数据的name和实际散点的name相同
                })
                if (dataList.length > 0) {
                    sumaryAmount = dataList[0].amount;
                    sumaryCnt = dataList[0].count;
                    userCnt = dataList[0].traderCount;
                    htmlStr = `<div class="tooltip-style" style="position:relative;">
                          <span style="margin-bottom: 10px;color: #0081CC;font-size:20px;font-weight:600;padding-top: 0">${params.name}</span><br />
                          <div style="line-height:30px;margin-top:10px">
                          <span style="color: #333;font-size:14px">融资金额(万元):  ${sumaryAmount?sumaryAmount:''}</span><br />
                          <span style="color: #333;font-size:14px">融资笔数(笔):  ${sumaryCnt?sumaryCnt:''}</span><br />
                          <span style="color: #333;font-size:14px">融资笔数(人):  ${userCnt?userCnt:''}</span><br />
                          </div>
                        </div>`;
                }
                return htmlStr;
            }
        },

        extraCssText: "box-shadow: 4px 6px 25px 0px rgba(163, 177, 190, 0.4), inset 0px 0px 2px 0px #FFFFFF; backdropFilter: blur(4px);border-radius:12px;width:auto;",
        textStyle: {
            fontSize: 16,
            color: "#fff",
        },
    }
}

geo配置数据如下: 

export const getGeo = (that) => {
    //这里设置为地图的阴影
    return [{ // 这个是重点 —— 这里设置为地图的阴影
        map: 'china',
        roam: false, // 禁止拖拽
        silent: true, // 禁止hover效果
        zoom: that.zoomSize, // 地图比例
        center: [105.194115019531, 36.582111640625], // 地图中心位置, 此处的纬度与下面的center相差1度是形成阴影的距离,可自己随意调整
        itemStyle: {
            normal: {
                borderColor: 'transparent',
                areaColor: "rgb(1,42,170)",
            },
        },
        regions: [{
            name: "南海诸岛",
            itemStyle: {
                // 隐藏地图
                normal: {
                    opacity: 0, // 为 0 时不绘制该图形
                }
            },
            label: {
                show: false // 隐藏文字
            }
        }],
    }]
}

 series配置如下:

export const getSeries = (that) => {
    // 此处为真正的地图
    let series = [{
        name: "", // 浮动框的标题
        type: "map",
        map: "china",
        zoom: that.zoomSize,
        layoutSize: "100%",
        emphasis: {
            // 鼠标hover是否显示内容,
            label: {
                //用于显示地图文本内容
                show: true,
                textStyle: {
                    color: "#fff",
                },
            },
        },
        label: {
            //这儿自定义图形样式
            // 地图标注
            normal: {
                show: false, // 是否显示对应地名
                textStyle: {
                    // color: "#fff",
                },
            },
        },
        center: [105.194115019531, 35.582111640625], // 设置地图中心
        itemStyle: {
            // 地图的样式
            normal: {
                borderColor: "#FFFFFF", // 省份边框颜色
                areaColor: {
                    type: "linear",
                    x: 0,
                    y: 1,
                    x2: 0,
                    y2: 0,
                    colorStops: [{
                            offset: 0,
                            color: "rgb(93,170,242)", // 100% 处的颜色
                        },
                        {
                            offset: 1,
                            color: "rgb(2,128,241)", // 0% 处的颜色

                        },
                    ],
                    global: false, // 缺省为 false
                },
                borderWidth: 1, // 省份边框宽度
                // shadowColor: "rgba(100,255,238,0.5)", // 省份边框阴影
                shadowColor: "rgba(255,255,255,0.5)", // 省份边框阴影
                shadowBlur: 5, // 省份边框聚焦
            },
            emphasis: {
                // 鼠标hover显示
                show: false,
                //areaColor: "#0D30D4",
                areaColor: {
                    type: "linear",
                    x: 1,
                    y: 0,
                    x2: 0,
                    y2: 0,
                    colorStops: [{
                            offset: 0,
                            color: "rgb(243,135,36)", // 0% 处的颜色
                        },
                        {
                            offset: 1,
                            color: "rgb(218,172,113)", // 100% 处的颜色
                        },
                    ],
                    global: false, // 缺省为 false
                },
                color: "#fff",
                // textStyle: {
                //   color: "#fff",
                // },
            },
        },

        data: that.mapList,
    }]

    if (that.mapList && that.mapList.length > 0) {
        that.mapList.forEach(item => {
            item.itemStyle = {
                // 单个区域的样式设置
                color: "rgb(251, 189, 108)",
                opacity: 1,
            }
        })
    }

    return series;
}

五.其他配置数据说明

1. zoomSize设置值为1.4

2.series数据格式为:[{name:'四川省',amount:'123456'},{name:'海南省,amount:'456'}]

3.加上地图适配

mounted() {
    window.addEventListener("resize", this.handleResize);
  },

handleResize() {
      // 地图自适应缩放
      this.myChart.resize();
      let domWidth =
        document.body.clientWidth || document.documentElement.clientWidth;
      if (domWidth > 1440) {
        return {
          "this.zoomSzie": 1.6,
        };
      } else {
        return {
          "this.zoomSzie": 1.2,
        };
      }
    },

  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
抱歉,作为AI语言模型,我无法给出代码示例。但是,我可以提供一些指导,帮助您开始使用VueEcharts创建3D地图效果。 1. 安装EchartsVue 在开始之前,您需要安装EchartsVue。可以使用npm或yarn来安装它们,例如: ``` npm install echarts vue ``` 或者 ``` yarn add echarts vue ``` 2. 导入EchartsVueVue组件中导入EchartsVue: ``` import Vue from 'vue' import echarts from 'echarts' ``` 3. 创建一个容器 在模板中创建一个容器,它将用于呈现3D地图: ``` <template> <div id="map-container" style="width: 100%; height: 100%;"></div> </template> ``` 4. 在mounted钩子函数中创建地图 在mounted钩子函数中,使用Echarts创建一个3D地图: ``` mounted() { const chart = echarts.init(document.getElementById('map-container')); echarts.registerMap('world', worldData); chart.setOption({ tooltip: {}, visualMap: { min: 0, max: 100, splitNumber: 5, inRange: { color: ['#50a3ba', '#eac736', '#d94e5d'] }, textStyle: { color: '#fff' } }, series: [{ type: 'map3D', map: 'world', shading: 'lambert', label: { show: true }, itemStyle: { color: '#DDDDDD' }, emphasis: { itemStyle: { color: '#FFD700' }, label: { show: true } }, light: { main: { intensity: 1.2, shadow: true }, ambient: { intensity: 0.3 } } }] }); } ``` 在上面的代码中,我们首先使用`echarts.registerMap()`方法注册地图数据。然后,我们设置了一些基本的选项,例如tooltip、visualMap和series。最后,我们创建一个`map3D`系列,将地图呈现为3D形式。 5. 运行应用程序 现在,您可以运行Vue应用程序并查看3D地图效果了! 这只是一个简单的示例,您可以根据需要调整选项和样式来创建更复杂的3D地图效果
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

一路追求匠人精神

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

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

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

打赏作者

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

抵扣说明:

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

余额充值