cesium 实现流动效果(河流具有流向的流动效果)

效果:粒子流动、河流真实水面流动、河面具有流向的流动 

图片资源:三个随意取用其一

一、创建PolylineTrailLinkMaterialProperty.js文件

/*
      ����������
      color 颜色
      duration 时间
      trailImage 图片
  */
      function PolylineTrailLinkMaterialProperty(color, trailImage , duration) {
        this._definitionChanged = new Cesium.Event();
        this._color = undefined;
        this._colorSubscription = undefined;
        this.color = color;
        this.duration = duration;
        this.trailImage  = trailImage ;
        this._time = (new Date()).getTime();
      }
      
      /**
       * �Զ������
       */
       function _getPolylineShader() {
        var materail =
          "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
          {\n\
                czm_material material = czm_getDefaultMaterial(materialInput);\n\
                vec2 st = materialInput.st;\n\
                vec4 colorImage = texture2D(image, vec2(fract(st.s - time), st.t));\n\
                material.alpha = colorImage.a * color.a;\n\
                material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
                return material;\n\
          }";
    
          return materail
      }
      
      Object.defineProperties(PolylineTrailLinkMaterialProperty.prototype, {
        isConstant: {
          //�������Ƿ����ʱ��仯,Ϊtrueʱֻ���ȡһ����ֵ
          get: function () {
            return false;
          }
        },
        definitionChanged: {
          get: function () {
            return this._definitionChanged;
          }
        },
        color: Cesium.createPropertyDescriptor('color')
      });
      
      var MaterialType = 'polylineType' + parseInt(Math.random() * 1000);
      PolylineTrailLinkMaterialProperty.prototype.getType = function (time) {
        return MaterialType;
      }
      
      PolylineTrailLinkMaterialProperty.prototype.getValue = function (time, result) {
        if (!Cesium.defined(result)) {
          result = {};
        }
        result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
        result.image = this.trailImage;
        result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
        return result;
      }
      
      PolylineTrailLinkMaterialProperty.prototype.equals = function (other) {
        return this === other ||
          (other instanceof PolylineTrailLinkMaterialProperty &&
            Cesium.Property.equals(this._color, other._color) &&
            Cesium.Property.equals(this._image, other._image)) 
      }
      
      Cesium.Material._materialCache.addMaterial(MaterialType, {
        fabric: {
          type: MaterialType,
          uniforms: {
            color: new Cesium.Color(1.0, 0.0, 0.0, 0.5),
            image: Cesium.Material.DefaultImageId,
            time: -20
          },
          source: _getPolylineShader()
        },
        translucent: function (material) {
          return true;
        }
      });
      Cesium.PolylineTrailLinkMaterialProperty = PolylineTrailLinkMaterialProperty;

二、引入

a、在原生html里面使用

<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <script src="Build/Cesium/Cesium.js"></script>
    <link rel="stylesheet" href="Build/Cesium/Widgets/widgets.css">
	<script src="Build/polylineTrailLinkMaterialProperty.js"></script>
    <script>
        var viewer = null;
        function initMap() {
        Cesium.Ion.defaultAccessToken = '你的token'
        viewer = new Cesium.Viewer('cesiumContainer',{
            // terrainProvider: createWorldTerrain(),
            sceneMode: 0,
            geocoder: false, // 位置查找工具
            homeButton: false, // 视角返回初始位置
            sceneModePicker: false, // 选择视角的模式(球体、平铺、斜视平铺)
            baseLayerPicker: false, // 图层选择器(地形影像服务)
            navigationHelpButton: false, // 导航帮助(手势,鼠标)
            animation: false, // 左下角仪表盘(动画器件)
            timeline: false, // 底部时间线
            fullscreenButton: false, // 全屏
            vrButton: false, // VR
            infoBox: false, //小弹窗
            selectionIndicator: false, //去除绿框
        })

        

        if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) {
          //判断是否支持图像渲染像素化处理
          viewer.resolutionScale = window.devicePixelRatio;
        }
        viewer.scene.fxaa = true;
        viewer.scene.postProcessStages.fxaa.enabled = true;
        // 隐藏版权
        viewer._cesiumWidget._creditContainer.style.display = "none";

        viewer.scene.sun.show = false;
        viewer.scene.moon.show = false;
        viewer.scene.skyBox.show = false; //关闭天空盒,否则会显示天空颜色
        viewer.scene.undergroundMode = true;
        viewer.scene.globe.show = true;
      }
  
  
      //绘制水面波浪效果
      function drawWater() {
        viewer.entities.add({
          name: 'PolylineTrail',
          polyline: {
            positions: Cesium.Cartesian3.fromDegreesArrayHeights([
              118.20366966044915, 24.866028005772108, 0,
              118.19298304961832, 24.862935624944335, 0,
              118.18460402405577, 24.857932968917897, 0,
              118.18064925095011, 24.853764129812788, 0,
              118.17441189116022, 24.85260606759165, 0
            ]),
            //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            clampToGround: true,
            width: 40,
            material: new PolylineTrailLinkMaterialProperty(Cesium.Color.CYAN, image3, 10000),    
          },
        });
      }
      function load() {
        initMap();
          viewer.camera.setView({
              destination: Cesium.Cartesian3.fromDegrees(118.18460402405577,24.857932968917897, 8000),
              orientation: {
                  heading: Cesium.Math.toRadians(0.0),
                  pitch: Cesium.Math.toRadians(-45),
                  roll: 0.0
              }
          })
        drawWater();
      }
    </script>
</head>
<body onload="load()" >
	<div id="cesiumContainer" style="width:100vw;height:100vh;">
    </div>
</body>
</html>

 b、在vue3中使用

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Cesium是一种开源的虚拟地球浏览器,可以用于呈现三维地球上的地理空间数据。Cesium通过其强大的图形渲染引擎和开放的插件系统,可以实现流动效果。 要实现流动,首先需要将动态数据加载到Cesium中。Cesium支持各种数据格式,如GeoJSON、KML、Shapefile等,可以通过加载这些数据文件来获取实时或历史地理空间数据。数据可以包含地球表面上的对象,例如河流、风向、海洋流等。将这些数据加载到Cesium中后,即可在三维地球上呈现流动效果。 在数据加载后,可以使用Cesium提供的API来实现流动效果。例如,可以使用Cesium的动画功能来控制时间流逝,并在地球上移动对象。这样,地球上的河流、风向箭头或海洋流线就可以随着时间的推移动态展示其流动状态。通过调整时间流逝的速度和其他动画参数,可以实现不同的流动效果,从而更好地展示地理空间数据。 此外,Cesium还支持自定义流动效果。开发人员可以使用Cesium的开放插件系统创建自定义的流动效果。通过使用Cesium的图形渲染引擎和JavaScript编程接口,可以实现各种各样的流动效果,满足不同的需求和创意。 总之,Cesium通过其强大的图形渲染引擎和开放的插件系统,可以实现流动效果。通过加载动态数据,并使用Cesium的动画功能或自定义插件,可以在三维地球上展示各种流动状态的地理空间数据。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值