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.

Point.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-01-06 15:03:25
  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 { Util } from '@dc-modules/utils'
  9. import { Transform } from '@dc-modules/transform'
  10. import Overlay from '../Overlay'
  11. const DEF_STYLE = {
  12. pixelSize: 8,
  13. outlineColor: Cesium.Color.BLUE,
  14. outlineWidth: 2
  15. }
  16. class Point extends Overlay {
  17. constructor(position) {
  18. super()
  19. this._delegate = new Cesium.Entity({ point: {} })
  20. this._position = Parse.parsePosition(position)
  21. this._state = State.INITIALIZED
  22. }
  23. get type() {
  24. return Overlay.getOverlayType('point')
  25. }
  26. set position(position) {
  27. this._position = Parse.parsePosition(position)
  28. this._delegate.position = Transform.transformWGS84ToCartesian(
  29. this._position
  30. )
  31. return this
  32. }
  33. get position() {
  34. return this._position
  35. }
  36. _mountedHook() {
  37. /**
  38. * set the location
  39. */
  40. this.position = this._position
  41. /**
  42. * initialize the Overlay parameter
  43. */
  44. Util.merge(this._delegate.point, DEF_STYLE, this._style)
  45. }
  46. /**
  47. * Set style
  48. * @param style
  49. * @returns {Point}
  50. */
  51. setStyle(style) {
  52. if (!style || Object.keys(style).length === 0) {
  53. return this
  54. }
  55. delete style['position']
  56. Util.merge(this._style, style)
  57. Util.merge(this._delegate.point, DEF_STYLE, this._style)
  58. return this
  59. }
  60. /**
  61. * Parse from entity
  62. * @param entity
  63. * @returns {any}
  64. */
  65. static fromEntity(entity) {
  66. let point = undefined
  67. let now = Cesium.JulianDate.now()
  68. let position = Transform.transformCartesianToWGS84(
  69. entity.position.getValue(now)
  70. )
  71. point = new Point(position)
  72. point.attr = {
  73. ...entity?.properties?.getValue(now)
  74. }
  75. return point
  76. }
  77. }
  78. Overlay.registerType('point')
  79. export default Point