问答

在Vue中使用echarts-gl的setOption显示错误的问题

作者:admin 2021-05-07 我要评论

template div id="chart" /div/templatescriptimport echarts from '@/../static/js/echarts.js'import echartsgl from '@/../static/js/echarts-gl.min.js'impo...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)
<template>
  <div id="chart">
  </div>
</template>
<script>
import echarts from '@/../static/js/echarts.js'
import echartsgl from '@/../static/js/echarts-gl.min.js'
import mapboxgl from '@/../static/js/mapbox-gl.js'
import roadData from '@/../static/js/road_converted.json'
export default {
  name: 'chart',
  data () {
    return {
      dataAll:{},//记录路段信息
      theColorRamp: ['#FF0000', '#FF7D00', '#FFFF00', '#00FF00', '#00FFFF', '#0000FF', '#FF00FF', '#fdae61', '#f46d43', '#d73027'],
      theCenter: [121.437467, 31.216173],// 中心点坐标
      theZoom:  14, //视角远近 数字
      theBear:  90, // 地图旋转角度,正北为0,正东为90,正西为270,以此类推
      thePitch: 30,// 地图俯瞰角度,0为顶视图,60以上效果甚微
      mapstyle:'mapbox://styles/mapbox/light-v9',
      mapAccessToken: 'pk.eyJ1IjoibG9nd2hlbiIsImEiOiJja2pyOTB1eWsxZTdwMnlvODFtazN2cmJyIn0.jw35YLEDiRIFboGkVA2MyA',
      theColor: 'rgb(200,40,0)',// 路线颜色
      theWidth: 10, // 路线粗细
      theOpac: 0.15 // 透明度 0-1
    }
  },
  methods: {
    initmap()
    {
      let myChart=echarts.init(document.getElementById('chart'))
       window.mapboxgl = mapboxgl
       mapboxgl.accessToken=this.mapAccessToken
       this.dataAll=roadData.features.map(function(theD){
          return {
            coords:theD.geometry.coordinates,
            lineStyle: {
                        color: 'red',
                        width: 10,
                        opacity: 0.15
                    }
         }
       })
       console.log(this.dataAll)
       console.log(myChart)
       let option={
          mapbox: {
           center: this.theCenter,
           zoom: this.theZoom,
           pitch: this.thePitch,
           bearing: this.theBear,
           style: this.mapstyle,
         },
         series:[
            {
                 type: 'lines3D',
                 coordinateSystem: 'mapbox',
                 blendMode: 'lighter', //让数据集中的区域因为叠加而产生高亮的效果。
                 blendMode: 'source-over',
                 polyline: true, //是否为多段线
                 data: this.dataAll
             }
            ],
       }
       myChart.setOption(option);
    }
   },
    mounted: function () {
      this.$nextTick(()=>{
         this.initmap()
      })
    }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
#chart{
position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
</style>

如果使用原生JS效果如下:
image
但是实际效果如图:像从中劈开了一样 路段并没有叠加上去。
image

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 在Vue中使用echarts-gl的setOption显示

    在Vue中使用echarts-gl的setOption显示

  • go的线程在实际中的实践?

    go的线程在实际中的实践?

  • H5页面如何隐藏video 原本的 control

    H5页面如何隐藏video 原本的 control

  • umi dev后想访问文件夹下的js失败

    umi dev后想访问文件夹下的js失败

腾讯云代理商
海外云服务器