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.

Draw.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. /**
  46. *
  47. * @param position
  48. * @param isCenter
  49. * @returns {*}
  50. */
  51. createAnchor(position, isCenter = false) {
  52. return this._layer.add({
  53. position: position,
  54. billboard: {
  55. image: isCenter ? this._options.icon_center : this._options.icon_anchor,
  56. width: this._options.icon_size[0],
  57. height: this._options.icon_size[1],
  58. eyeOffset: new Cesium.Cartesian3(0, 0, -500),
  59. heightReference:
  60. this._viewer.scene.mode === Cesium.SceneMode.SCENE3D &&
  61. this._clampToGround
  62. ? Cesium.HeightReference.CLAMP_TO_GROUND
  63. : Cesium.HeightReference.NONE
  64. }
  65. })
  66. }
  67. /**
  68. *
  69. * @param plot
  70. * @param clampToGround
  71. */
  72. start(plot, clampToGround) {
  73. this._viewer = plot.viewer
  74. this._tooltip = plot.viewer.tooltip
  75. this._layer = plot.overlayLayer
  76. this._plotEvent = plot.plotEvent
  77. this._options = plot.options
  78. this._clampToGround = clampToGround
  79. this._mountEntity()
  80. this.bindEvent()
  81. }
  82. }
  83. export default Draw