cesium加载倾斜影像数据(模拟雨、雪、雾、无人机飞行、测距、箭头标绘、电子围栏等)

博客提及加载倾斜影像核心代码,还包括无人机特定方向飞行(通过按钮实现)以及电子围栏等内容,作者表示后续再续写。

加载倾斜影像核心代码:

      var palaceTileset = new Cesium.Cesium3DTileset({
        url: 'http://127.0.0.1:9002/tileset.json',
        //控制切片视角显示的数量,可调整性能
        maximumScreenSpaceError: 0.1,
        maximumNumberOfLoadedTiles: 10000,
      })
      //添加到场景
      viewer.scene.primitives.add(palaceTileset);
      //控制模型的位置
      palaceTileset.readyPromise.then(function (palaceTileset) {
        viewer.scene.primitives.add(palaceTileset);
        var terrainProvider = new Cesium.EllipsoidTerrainProvider();
        viewer.terrainProvider = terrainProvider;
        var heightOffset = -370; //改变3Dtiles的高度
        var boundingSphere = palaceTileset.boundingSphere;
        var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
        var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
        var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);
        var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
        palaceTileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
        viewer.zoomTo(palaceTileset, new Cesium.HeadingPitchRange(0.5, -0.2, palaceTileset.boundingSphere.radius *
          1.0));
      });

无人机特定方向飞行(按钮实现):

function jxuTime() {

  // 创建 SampledPositionProperty 对象
  var positionProperty = new Cesium.SampledPositionProperty();

  // 添加一系列位置和时间样本
  positionProperty.addSample(Cesium.JulianDate.now(), Cesium.Cartesian3.fromDegrees(108.927007, 34.256505, 50));
  positionProperty.addSample(Cesium.JulianDate.addSeconds(Cesium.JulianDate.now(), 5, new Cesium.JulianDate()), Cesium.Cartesian3.fromDegrees(108.929620, 34.252350, 50));

  // 创建实体并设置模型
  var entity = viewer.entities.add({
    name: 'plane',
    position: positionProperty,
    model: {
      uri: ".//Apps//SampleData//image2d//air.glb",
      scale: 2,
      minimumPixelSize: 128,
      maximumScale: 2000,
      runAnimations: true,
      clampAnimations: true,
      show: true
    }
  });
}

电子围栏:

//绘制电子围栏
function GetRoute4() {
  function PolylineTrailLinkMaterialProperty(color, duration) {
    this._definitionChanged = new Cesium.Event();
    this._color = undefined;
    this._colorSubscription = undefined;
    this.color = color;
    this.duration = duration;
    this._time = (new Date()).getTime();
  }

  Object.defineProperties(PolylineTrailLinkMaterialProperty.prototype, {
    isConstant: {
      get: function () {
        return false;
      }
    },
    definitionChanged: {
      get: function () {
        return this._definitionChanged;
      }
    },
    color: Cesium.createPropertyDescriptor('color')
  });

  PolylineTrailLinkMaterialProperty.prototype.getType = function (time) {
    return 'PolylineTrailLink';
  }
  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 = Cesium.Material.PolylineTrailLinkImage;
    result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
    return result;
  }
  PolylineTrailLinkMaterialProperty.prototype.equals = function (other) {
    return this === other || (other instanceof PolylineTrailLinkMaterialProperty && Property.equals(this._color, other._color))
  };

  Cesium.PolylineTrailLinkMaterialProperty = PolylineTrailLinkMaterialProperty;
  Cesium.Material.PolylineTrailLinkType = 'PolylineTrailLink';
  Cesium.Material.PolylineTrailLinkImage = "../Cesium-1.75/img/colors1.png";//图片
  Cesium.Material.PolylineTrailLinkSource = "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\
 }"/*"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.t - time), st.t));\n\
        material.alpha = colorImage.a * color.a;\n\
        material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
        return material;\n\
    }" //从下向上*/
  // 着色器从上到下
  /* "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.t + time)), st.t));\n\
       material.alpha = colorImage.a * color.a;\n\
       material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
       return material;\n\
   }"
   //顺时针
   "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\
 }";
 //逆时针
 "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\
 }"
   */

  Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineTrailLinkType, {
    fabric: {
      type: Cesium.Material.PolylineTrailLinkType,
      uniforms: {
        color: new Cesium.Color(1.0, 0.0, 0.0, 0.9),
        image: Cesium.Material.PolylineTrailLinkImage,
        time: 2
      },
      source: Cesium.Material.PolylineTrailLinkSource
    },
    translucent: function (material) {
      return true;
    }
  })

  three = viewer.entities.add({
    name: 'yscNoNeedEntity',
    wall: {
      positions: Cesium.Cartesian3.fromDegreesArrayHeights([
        108.92536, 34.25199, 130.0,//左下
        108.92990, 34.25200, 130.0,//右下
        108.92973, 34.25477, 130.0,//右上
        108.92510, 34.25476, 130.0,//左上
        108.92536, 34.25199, 130.0,//左下
      ]),
      material: new Cesium.PolylineTrailLinkMaterialProperty(Cesium.Color.BLUE, 3000),
    }
  })

  viewer.flyTo(three)
}

下次再续写吧,忙了!

评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

道1993

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值