You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WaterPrimitive.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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) {
  12. super()
  13. this._positions = Parse.parsePositions(positions)
  14. this._delegate = new Cesium.GroundPrimitive({
  15. geometryInstances: new Cesium.GeometryInstance({
  16. geometry: {}
  17. }),
  18. asynchronous: true
  19. })
  20. this.type = Overlay.getOverlayType('water_primitive')
  21. this._state = State.INITIALIZED
  22. }
  23. set positions(positions) {
  24. this._positions = Parse.parsePositions(positions)
  25. this._delegate.geometryInstances.geometry = Cesium.PolygonGeometry.fromPositions(
  26. {
  27. positions: Transform.transformWGS84ArrayToCartesianArray(
  28. this._positions
  29. ),
  30. height: this._style?.height,
  31. extrudedHeight: this._style?.extrudedHeight,
  32. closeTop: this._style?.closeTop,
  33. closeBottom: this._style?.closeBottom,
  34. vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT
  35. }
  36. )
  37. return this
  38. }
  39. get positions() {
  40. return this._positions
  41. }
  42. /**
  43. *
  44. * @private
  45. */
  46. _setAppearance() {
  47. if (!this._style) {
  48. return
  49. }
  50. this._delegate.appearance = new Cesium.EllipsoidSurfaceAppearance({
  51. material: Cesium.Material.fromType('Water', {
  52. baseWaterColor:
  53. this._style?.baseWaterColor || new Cesium.Color(0.2, 0.3, 0.6, 1.0),
  54. blendColor:
  55. this._style?.blendColor || new Cesium.Color(0.0, 1.0, 0.699, 1.0),
  56. specularMap: this._style?.specularMap || Cesium.Material.DefaultImageId,
  57. normalMap: this._style?.normalMap || Cesium.Material.DefaultImageId,
  58. frequency: this._style?.frequency || 1000.0,
  59. animationSpeed: this._style?.animationSpeed || 0.01,
  60. amplitude: this._style?.amplitude || 10,
  61. specularIntensity: this._style?.specularIntensity || 0.5
  62. })
  63. })
  64. }
  65. _mountedHook() {
  66. /**
  67. * set the positions
  68. */
  69. this.positions = this._positions
  70. /**
  71. * set the appearance
  72. */
  73. !this._delegate.appearance && this._setAppearance()
  74. }
  75. /**
  76. * Sets Style
  77. * @param style
  78. * @returns {WaterPrimitive}
  79. */
  80. setStyle(style) {
  81. if (Object.keys(style).length === 0) {
  82. return this
  83. }
  84. this._style = style
  85. if (this._style?.classificationType) {
  86. this._delegate.classificationType = this._style.classificationType
  87. }
  88. this._setAppearance()
  89. return this
  90. }
  91. }
  92. Overlay.registerType('water_primitive')
  93. export default WaterPrimitive