在Vue项目中引入 ECharts 3D 路径图 Flights GL(需安装echarts、echarts-gl、jQuery依赖,已踩坑)_vue 获取echarts下载后的图片路径

(2)然后,同样在 src 下 main.js 中全局引入 echarts-gl;

import 'echarts-gl'

(3)已全局引入,单页面中无需再引。

3.jQuery 包的下载

(1)通过 npm 安装 jQuery;

npm install jquery --save

(2)在 src 下 main.js 中引入 jQuery;

import jquery from 'jquery';
Vue.prototype.$ = jquery;

(3)在需要使用到 jQuery 的页面中引入;

import $ from "jquery"
4.小结

npm 下载依赖:

npm install echarts --save;
npm i echarts-gl@1.1.0 -S;
npm install jquery --save;

main.js 中:

import echarts from 'echarts'
import 'echarts-gl'
import jquery from 'jquery'

Vue.prototype.$ = jquery;
Vue.prototype.$echarts = echarts;

页面文件中:

import $ from "jquery"; //引入jQuery
import 'echarts/map/js/world.js' //必须引入世界地图

注意世界地图必须在页面中引入,否则3d路径图依然无法呈现。


三、完整代码

<template>
  <div class="login_new">
    <div id="main" style="width: 100%;height: 10rem"></div>
  </div>
</template>

<script>
  import * as echarts from 'echarts';
  import 'echarts-gl';
  import $ from "jquery"; //引入jQuery
  import 'echarts/map/js/world.js' //必须引入世界地图

  export default {
    name: "login_new",
    methods: {
      //绘制3D路径图
      draw() {
        var ROOT_PATH = 'https://cdn.jsdelivr.net/gh/apache/echarts-website@asf-site/examples';
        var myChart = this.$echarts.init(document.getElementById('main'));
        var option;

        var uploadedDataURL = ROOT_PATH + '/data-gl/asset/data/flights.json';
        myChart.showLoading();
        $.getJSON(uploadedDataURL, function (data) {
          myChart.hideLoading();

          function getAirportCoord(idx) {
            return [data.airports[idx][3], data.airports[idx][4]];
          }

          var routes = data.routes.map(function (airline) {
            return [getAirportCoord(airline[1]), getAirportCoord(airline[2])];
          });
          myChart.setOption({
            geo3D: {
              map: 'world',
              shading: 'realistic',
              silent: true, //鼠标设置为不触发事件
              environment: '#333', //背景色
              realisticMaterial: {
                roughness: 0.8,
                metalness: 0
              },
              postEffect: {
                enable: true
              },
              groundPlane: {
                show: false
              },
              light: {
                main: {
                  intensity: 1,
                  alpha: 30
                },
                ambient: {
                  intensity: 0
                }
              },
              viewControl: {
                distance: 70, //地图缩放程度
                alpha: 89, //地图翻转程度
                panMouseButton: 'left',
                rotateMouseButton: 'right',
                
                rotateSensitivity: false,  //地图是否能旋转
                zoomSensitivity: false //地图是否能缩放
              },
              itemStyle: {
                color: '#000' //地图的颜色
              },
              regionHeight: 0.5 //地图高度
            },
            series: [
              {
                type: 'lines3D',
                coordinateSystem: 'geo3D',
                effect: { // 特效线的配置
                  show: true,
                  trailWidth: 1,
                  trailOpacity: 0.5,
                  trailLength: 0.2,
                  constantSpeed: 5 //特效固定速度
                },
                blendMode: 'lighter',
                lineStyle: { //特效线
                  width: 0.2,
                  opacity: 0.05


### 最后

我可以将最近整理的前端面试题分享出来,其中包含**HTML、CSS、JavaScript、服务端与网络、Vue、浏览器、数据结构与算法**等等,还在持续整理更新中,希望大家都能找到心仪的工作。


**篇幅有限,仅展示部分截图:**

![](https://img-blog.csdnimg.cn/img_convert/ff6b8e636a356a01389cd2de0211d347.png)

![](https://img-blog.csdnimg.cn/img_convert/b24f32dd81ead796fa80c27c763d262c.png)

![](https://img-blog.csdnimg.cn/img_convert/c6265dc2681708533916a8d7910506b3.png)
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值