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.

DC.Point.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-01-06 15:03:25
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-02-01 18:29:54
  6. */
  7. import Cesium from '@/namespace'
  8. import Overlay from '../Overlay'
  9. const DEF_STYLE = {
  10. pixelSize: 8,
  11. outlineColor: Cesium.Color.BLUE,
  12. outlineWidth: 2
  13. }
  14. DC.Point = class extends Overlay {
  15. constructor(position) {
  16. if (!position || !(position instanceof DC.Position)) {
  17. throw new Error('the position invalid')
  18. }
  19. super()
  20. this._position = position
  21. this._delegate = new Cesium.Entity()
  22. this._state = DC.OverlayState.INITIALIZED
  23. this.type = DC.OverlayType.POINT
  24. }
  25. set position(position) {
  26. this._position = position
  27. }
  28. get position() {
  29. return this._position
  30. }
  31. /**
  32. * prepare entity
  33. */
  34. _prepareDelegate() {
  35. /**
  36. * set the location
  37. */
  38. this._delegate.position = new Cesium.CallbackProperty(time => {
  39. return DC.T.transformWSG84ToCartesian(this._position)
  40. })
  41. /**
  42. * set the orientation
  43. */
  44. this._delegate.orientation = new Cesium.CallbackProperty(time => {
  45. return Cesium.Transforms.headingPitchRollQuaternion(
  46. DC.T.transformWSG84ToCartesian(this._position),
  47. new Cesium.HeadingPitchRoll(
  48. Cesium.Math.toRadians(this._position.heading),
  49. Cesium.Math.toRadians(this._position.pitch),
  50. Cesium.Math.toRadians(this._position.roll)
  51. )
  52. )
  53. })
  54. /**
  55. * initialize the Overlay parameter
  56. */
  57. this._delegate.point = {
  58. ...DEF_STYLE,
  59. ...this._style
  60. }
  61. this._delegate.layer = this._layer
  62. this._delegate.overlayId = this._id
  63. }
  64. /**
  65. *
  66. * @param {*} style
  67. */
  68. setStyle(style) {
  69. if (Object.keys(style).length === 0) {
  70. return
  71. }
  72. this._style = style
  73. this._delegate.point && DC.Util.merge(this._delegate.point, DEF_STYLE, this._style)
  74. return this
  75. }
  76. }