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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-01-31 19:45:32
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { MouseEventType } from '@dc-modules/event'
  7. class Draw {
  8. constructor() {
  9. this._viewer = undefined
  10. this._delegate = undefined
  11. this._floatingAnchor = undefined
  12. this._clampToGround = true
  13. this._tooltip = undefined
  14. this._tooltipMess = '单击选择点位'
  15. this._layer = undefined
  16. this._plotEvent = undefined
  17. this._options = {}
  18. this._positions = []
  19. }
  20. _mountEntity() {}
  21. _onClick(e) {}
  22. _onMouseMove(e) {
  23. this._tooltip.showAt(e.windowPosition, this._tooltipMess)
  24. if (this._floatingAnchor) {
  25. let position = this._clampToGround ? e.surfacePosition : e.position
  26. if (!position) {
  27. return false
  28. }
  29. this._floatingAnchor.position.setValue(position)
  30. this._positions.pop()
  31. this._positions.push(position)
  32. }
  33. }
  34. _onRightClick(e) {}
  35. bindEvent() {
  36. this._viewer.on(MouseEventType.CLICK, this._onClick, this)
  37. this._viewer.on(MouseEventType.MOUSE_MOVE, this._onMouseMove, this)
  38. this._viewer.on(MouseEventType.RIGHT_CLICK, this._onRightClick, this)
  39. }
  40. unbindEvent() {
  41. this._viewer.off(MouseEventType.CLICK, this._onClick, this)
  42. this._viewer.off(MouseEventType.MOUSE_MOVE, this._onMouseMove, this)
  43. this._viewer.off(MouseEventType.RIGHT_CLICK, this._onRightClick, this)
  44. }
  45. createAnchor(position, isCenter = false) {
  46. return this._layer.add({
  47. position: position,
  48. billboard: {
  49. image: isCenter ? this._options.icon_center : this._options.icon_anchor,
  50. width: this._options.icon_size[0],
  51. height: this._options.icon_size[1],
  52. eyeOffset: new Cesium.Cartesian3(0, 0, -500),
  53. heightReference:
  54. this._viewer.scene.mode === Cesium.SceneMode.SCENE3D &&
  55. this._clampToGround
  56. ? Cesium.HeightReference.CLAMP_TO_GROUND
  57. : Cesium.HeightReference.NONE
  58. }
  59. })
  60. }
  61. start(plot) {
  62. this._viewer = plot.viewer
  63. this._tooltip = plot.viewer.tooltip
  64. this._layer = plot.overlayLayer
  65. this._plotEvent = plot.plotEvent
  66. this._options = plot.options
  67. this._clampToGround = plot.options.clampToGround ?? true
  68. this._mountEntity()
  69. this.bindEvent()
  70. }
  71. }
  72. export default Draw