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


    实现效果如下:

    功能菜单如下:

    加载倾斜影像核心代码:

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

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

    1. function jxuTime() {
    2. // 创建 SampledPositionProperty 对象
    3. var positionProperty = new Cesium.SampledPositionProperty();
    4. // 添加一系列位置和时间样本
    5. positionProperty.addSample(Cesium.JulianDate.now(), Cesium.Cartesian3.fromDegrees(108.927007, 34.256505, 50));
    6. positionProperty.addSample(Cesium.JulianDate.addSeconds(Cesium.JulianDate.now(), 5, new Cesium.JulianDate()), Cesium.Cartesian3.fromDegrees(108.929620, 34.252350, 50));
    7. // 创建实体并设置模型
    8. var entity = viewer.entities.add({
    9. name: 'plane',
    10. position: positionProperty,
    11. model: {
    12. uri: ".//Apps//SampleData//image2d//air.glb",
    13. scale: 2,
    14. minimumPixelSize: 128,
    15. maximumScale: 2000,
    16. runAnimations: true,
    17. clampAnimations: true,
    18. show: true
    19. }
    20. });
    21. }

    电子围栏

    1. //绘制电子围栏
    2. function GetRoute4() {
    3. function PolylineTrailLinkMaterialProperty(color, duration) {
    4. this._definitionChanged = new Cesium.Event();
    5. this._color = undefined;
    6. this._colorSubscription = undefined;
    7. this.color = color;
    8. this.duration = duration;
    9. this._time = (new Date()).getTime();
    10. }
    11. Object.defineProperties(PolylineTrailLinkMaterialProperty.prototype, {
    12. isConstant: {
    13. get: function () {
    14. return false;
    15. }
    16. },
    17. definitionChanged: {
    18. get: function () {
    19. return this._definitionChanged;
    20. }
    21. },
    22. color: Cesium.createPropertyDescriptor('color')
    23. });
    24. PolylineTrailLinkMaterialProperty.prototype.getType = function (time) {
    25. return 'PolylineTrailLink';
    26. }
    27. PolylineTrailLinkMaterialProperty.prototype.getValue = function (time, result) {
    28. if (!Cesium.defined(result)) {
    29. result = {};
    30. }
    31. result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
    32. result.image = Cesium.Material.PolylineTrailLinkImage;
    33. result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
    34. return result;
    35. }
    36. PolylineTrailLinkMaterialProperty.prototype.equals = function (other) {
    37. return this === other || (other instanceof PolylineTrailLinkMaterialProperty && Property.equals(this._color, other._color))
    38. };
    39. Cesium.PolylineTrailLinkMaterialProperty = PolylineTrailLinkMaterialProperty;
    40. Cesium.Material.PolylineTrailLinkType = 'PolylineTrailLink';
    41. Cesium.Material.PolylineTrailLinkImage = "../Cesium-1.75/img/colors1.png";//图片
    42. Cesium.Material.PolylineTrailLinkSource = "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
    43. {\n\
    44. czm_material material = czm_getDefaultMaterial(materialInput);\n\
    45. vec2 st = materialInput.st;\n\
    46. vec4 colorImage = texture2D(image, vec2(fract(st.s - time), st.t));\n\
    47. material.alpha = colorImage.a * color.a;\n\
    48. material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
    49. return material;\n\
    50. }"/*"czm_material czm_getMaterial(czm_materialInput materialInput)\n\
    51. {\n\
    52. czm_material material = czm_getDefaultMaterial(materialInput);\n\
    53. vec2 st = materialInput.st;\n\
    54. vec4 colorImage = texture2D(image, vec2(fract(st.t - time), st.t));\n\
    55. material.alpha = colorImage.a * color.a;\n\
    56. material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
    57. return material;\n\
    58. }" //从下向上*/
    59. // 着色器从上到下
    60. /* "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
    61. {\n\
    62. czm_material material = czm_getDefaultMaterial(materialInput);\n\
    63. vec2 st = materialInput.st;\n\
    64. vec4 colorImage = texture2D(image, vec2(fract(-(st.t + time)), st.t));\n\
    65. material.alpha = colorImage.a * color.a;\n\
    66. material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
    67. return material;\n\
    68. }"
    69. //顺时针
    70. "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
    71. {\n\
    72. czm_material material = czm_getDefaultMaterial(materialInput);\n\
    73. vec2 st = materialInput.st;\n\
    74. vec4 colorImage = texture2D(image, vec2(fract(-(st.s + time)), st.t));\n\
    75. material.alpha = colorImage.a * color.a;\n\
    76. material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
    77. return material;\n\
    78. }";
    79. //逆时针
    80. "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
    81. {\n\
    82. czm_material material = czm_getDefaultMaterial(materialInput);\n\
    83. vec2 st = materialInput.st;\n\
    84. vec4 colorImage = texture2D(image, vec2(fract(st.s - time), st.t));\n\
    85. material.alpha = colorImage.a * color.a;\n\
    86. material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
    87. return material;\n\
    88. }"
    89. */
    90. Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineTrailLinkType, {
    91. fabric: {
    92. type: Cesium.Material.PolylineTrailLinkType,
    93. uniforms: {
    94. color: new Cesium.Color(1.0, 0.0, 0.0, 0.9),
    95. image: Cesium.Material.PolylineTrailLinkImage,
    96. time: 2
    97. },
    98. source: Cesium.Material.PolylineTrailLinkSource
    99. },
    100. translucent: function (material) {
    101. return true;
    102. }
    103. })
    104. three = viewer.entities.add({
    105. name: 'yscNoNeedEntity',
    106. wall: {
    107. positions: Cesium.Cartesian3.fromDegreesArrayHeights([
    108. 108.92536, 34.25199, 130.0,//左下
    109. 108.92990, 34.25200, 130.0,//右下
    110. 108.92973, 34.25477, 130.0,//右上
    111. 108.92510, 34.25476, 130.0,//左上
    112. 108.92536, 34.25199, 130.0,//左下
    113. ]),
    114. material: new Cesium.PolylineTrailLinkMaterialProperty(Cesium.Color.BLUE, 3000),
    115. }
    116. })
    117. viewer.flyTo(three)
    118. }

    下次再续写吧,忙了!

  • 相关阅读:
    商品销售管理系统java+mysql
    页面上时间显示为数字 后端返回给前端 response java系统
    OpenGL环境搭建
    渗透测试之内核安全系列课程:Rootkit技术初探(六)
    算法|Day49 动态规划17
    设计模式-备忘录模式(Memento)
    Hololens 2 新建自定义按钮
    Spring Boot中的Redis自动配置与使用
    【java_wxid项目】【第八章】【Apache ShardingSphere集成】
    springboot基础(79):通过pdf模板生成文件
  • 原文地址:https://blog.csdn.net/OuNuo5280/article/details/137863355