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.8KB

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