当前位置:   article > 正文

vue3+echarts实现3D地球+飞线_echart 3d地图散点,飞线

echart 3d地图散点,飞线

效果图

1、下载

        指令

  1. npm install echarts --save
  2. npm install echarts-gl

我的版本:

2、html容器

<div ref="worldBox" style="width: 500px;height: 500px;"></div>

3、js代码

  1. <script setup>
  2. import { onMounted,ref} from 'vue'
  3. import * as echarts from "echarts";
  4. import "echarts-gl";
  5. import earthBg from "../../assets/echarts/earth-bg.png";//导入背景纹理
  6. const worldBox = ref(null)
  7. onMounted(async () => {
  8. world_fun();
  9. });
  10. const world_fun = () =>{
  11. var BlChart = echarts.init(worldBox.value);
  12. var option = {
  13. globe: {
  14. baseTexture: earthBg, // 地球表面覆盖的图片
  15. shading: 'color', // 地球中三维图形的着色效果
  16. zoom: 2,
  17. viewControl: {
  18. autoRotate: true, // 自动旋转
  19. autoRotateSpeed: 3, //物体自转的速度,单位为角度 / 秒,默认为10也就是36秒转一圈。
  20. autoRotateAfterStill: 2, // 在鼠标静止操作后恢复自动旋转的时间间隔,默认 3s
  21. rotateSensitivity: 2, // 旋转操作的灵敏度,值越大越灵敏.设置为0后无法旋转。[1, 0]只能横向旋转.[0, 1]只能纵向旋转
  22. targetCoord: [116.46, 39.92], // 定位到北京
  23. maxDistance: 400,
  24. minDistance: 200
  25. }
  26. },
  27. series: [{
  28. name: "lines3D",
  29. type: "lines3D",
  30. coordinateSystem: "globe",
  31. effect: {
  32. show: true,
  33. },
  34. blendMode: "lighter",
  35. lineStyle: {
  36. color:'#fff',
  37. width: 1,
  38. },
  39. data: [],
  40. silent: false,
  41. }, ],
  42. };
  43. // 随机数据 i控制线数量
  44. for (let i = 0; i < 30; i++) {
  45. option.series[0].data = option.series[0].data.concat(randomData());
  46. }
  47. BlChart.setOption(option);
  48. window.onresize = () => {
  49. BlChart.resize();
  50. };
  51. }
  52. // 随机生成起始及终点经纬度坐标
  53. const randomData = () => {
  54. let name = "随机点" + Math.random().toFixed(5) * 100000;
  55. // 起点经纬度-北京
  56. let longitude = 116.2,
  57. latitude = 39.56;
  58. // 随机终点经纬度
  59. let longitude2 = Math.random() * 360 - 180;
  60. let latitude2 = Math.random() * 180 - 90;
  61. return {
  62. coords: [
  63. [longitude, latitude],
  64. [longitude2, latitude2],
  65. ],
  66. value: (Math.random() * 3000).toFixed(2),
  67. };
  68. }
  69. </script>

附加纹理

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/99170
推荐阅读
相关标签
  

闽ICP备14008679号