Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

WaterPrimitive.js 2.7KB

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