Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

WaterPrimitive.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-10-11 18:24:37
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import State from '@dc-modules/state/State'
  7. import Parse from '@dc-modules/parse/Parse'
  8. import { Transform } from '@dc-modules/transform'
  9. import Overlay from '../Overlay'
  10. class WaterPrimitive extends Overlay {
  11. constructor(positions, holes = []) {
  12. super()
  13. this._positions = Parse.parsePositions(positions)
  14. this._holes = holes.map(item => Parse.parsePositions(item))
  15. this._delegate = new Cesium.GroundPrimitive({
  16. geometryInstances: new Cesium.GeometryInstance({
  17. geometry: {}
  18. }),
  19. asynchronous: true
  20. })
  21. this._state = State.INITIALIZED
  22. }
  23. get type() {
  24. return Overlay.getOverlayType('water_primitive')
  25. }
  26. set positions(positions) {
  27. this._positions = Parse.parsePositions(positions)
  28. this._delegate.geometryInstances.geometry = new Cesium.PolygonGeometry({
  29. polygonHierarchy: new Cesium.PolygonHierarchy(
  30. Transform.transformWGS84ArrayToCartesianArray(this._positions),
  31. this._holes.map(
  32. item =>
  33. new Cesium.PolygonHierarchy(
  34. Transform.transformWGS84ArrayToCartesianArray(item)
  35. )
  36. )
  37. ),
  38. height: this._style?.height,
  39. extrudedHeight: this._style?.extrudedHeight,
  40. closeTop: this._style?.closeTop,
  41. closeBottom: this._style?.closeBottom,
  42. vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT
  43. })
  44. return this
  45. }
  46. get positions() {
  47. return this._positions
  48. }
  49. /**
  50. *
  51. * @private
  52. */
  53. _setAppearance() {
  54. if (!this._style) {
  55. return
  56. }
  57. this._delegate.appearance = new Cesium.EllipsoidSurfaceAppearance({
  58. material: Cesium.Material.fromType('Water', {
  59. baseWaterColor:
  60. this._style?.baseWaterColor || new Cesium.Color(0.2, 0.3, 0.6, 1.0),
  61. blendColor:
  62. this._style?.blendColor || new Cesium.Color(0.0, 1.0, 0.699, 1.0),
  63. specularMap: this._style?.specularMap || Cesium.Material.DefaultImageId,
  64. normalMap: this._style?.normalMap || Cesium.Material.DefaultImageId,
  65. frequency: this._style?.frequency || 1000.0,
  66. animationSpeed: this._style?.animationSpeed || 0.01,
  67. amplitude: this._style?.amplitude || 10,
  68. specularIntensity: this._style?.specularIntensity || 0.5
  69. })
  70. })
  71. }
  72. _mountedHook() {
  73. /**
  74. * set the positions
  75. */
  76. this.positions = this._positions
  77. /**
  78. * set the appearance
  79. */
  80. !this._delegate.appearance && this._setAppearance()
  81. }
  82. /**
  83. * Sets Style
  84. * @param style
  85. * @returns {WaterPrimitive}
  86. */
  87. setStyle(style) {
  88. if (Object.keys(style).length === 0) {
  89. return this
  90. }
  91. this._style = style
  92. if (this._style?.classificationType) {
  93. this._delegate.classificationType = this._style.classificationType
  94. }
  95. this._setAppearance()
  96. return this
  97. }
  98. }
  99. Overlay.registerType('water_primitive')
  100. export default WaterPrimitive