当前位置:   article > 正文

Cesium 全景漫游_cesium 添加全景

cesium 添加全景

这两天由于别人提出的需求,在cesium上加载全景漫游功能,于是自己也仿照别人网站的案例模拟写了一个全景漫游功能;

先晒个成果:

这是提前设定好的路径进行漫游,也可以自己绘制路径进行漫游;也可以在漫游过程中动态改变漫游姿态;

下面为面板:

以下为部分核心代码,后续会慢慢上传代码:

  1. //开始漫游
  2. var f_property = $this.setProperty(paths, times);
  3. $this.flightEntity = viewer.entities.add({
  4. position: f_property,
  5. orientation: new Cesium.VelocityOrientationProperty(f_property),
  6. point: {
  7. color: new Cesium.Color.fromCssColorString("#FFFF00").withAlpha(0.2),
  8. pixelSize: 1
  9. },
  10. });
  11. viewer.trackedEntity = $this.flightEntity;
  12. //视角变换
  13. var matrix3Scratch = new Cesium.Matrix3();
  14. function getModelMatrix(entity, time, result) {
  15. var position = Cesium.Property.getValueOrUndefined(entity.position, time, new Cesium.Cartesian3());
  16. if (!Cesium.defined(position)) {
  17. return undefined;
  18. }
  19. var orientation = Cesium.Property.getValueOrUndefined(entity.orientation, time, new Cesium.Quaternion());
  20. if (!Cesium.defined(orientation)) {
  21. result = Cesium.Transforms.eastNorthUpToFixedFrame(position, undefined, result);
  22. } else {
  23. result = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromQuaternion(orientation, matrix3Scratch),
  24. position, result);
  25. }
  26. return result;
  27. }
  28. var scratch = new Cesium.Matrix4();
  29. $this.renderListener = function(e) {
  30. var time = viewer.clock.currentTime.secondsOfDay - viewer.clock.startTime.secondsOfDay;
  31. //viewer.camera.positionCartographic.height = 2000 + $this.limitCamera(f_property);
  32. if ($this.flightEntity && $this.isFollowModel) {
  33. getModelMatrix($this.flightEntity, viewer.clock.currentTime, scratch);
  34. var transformX = $this.followedX || 50; //距离运动点的距离(后方)
  35. var transformZ = $this.followedZ || 10; //距离运动点的高度(上方)
  36. viewer.scene.camera.lookAtTransform(scratch, new Cesium.Cartesian3(-transformX, 0, transformZ));
  37. }
  38. }
  39. viewer.scene.preRender.addEventListener($this.renderListener);

 

 

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

闽ICP备14008679号