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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 20:54:37
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { Transform } from '@dc-modules/transform'
  7. import { Polyline } from '@dc-modules/overlay'
  8. import Draw from './Draw'
  9. const DEF_STYLE = {
  10. width: 3,
  11. material: Cesium.Color.YELLOW.withAlpha(0.6)
  12. }
  13. class DrawPolyline extends Draw {
  14. constructor(style) {
  15. super()
  16. this._style = {
  17. ...DEF_STYLE,
  18. ...style
  19. }
  20. this._tooltipMess = '左击选择点位,右击结束'
  21. }
  22. _mountEntity() {
  23. this._delegate = new Cesium.Entity({
  24. polyline: {
  25. ...this._style,
  26. positions: new Cesium.CallbackProperty(() => {
  27. return this._positions
  28. }, false)
  29. }
  30. })
  31. this._layer.add(this._delegate)
  32. }
  33. _onClick(e) {
  34. let position = this._clampToGround ? e.surfacePosition : e.position
  35. if (!position) {
  36. return false
  37. }
  38. let len = this._positions.length
  39. if (len === 0) {
  40. this._positions.push(position)
  41. this.createAnchor(position)
  42. this._floatingAnchor = this.createAnchor(position)
  43. }
  44. this._positions.push(position)
  45. this.createAnchor(position)
  46. }
  47. _onRightClick(e) {
  48. this.unbindEvent()
  49. let polyline = new Polyline(
  50. Transform.transformCartesianArrayToWGS84Array(this._positions)
  51. )
  52. polyline.setStyle(this._style)
  53. this._plotEvent.raiseEvent(polyline)
  54. }
  55. }
  56. export default DrawPolyline