Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DrawPolyline.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 20:54:37
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { PlotEventType } from '@dc-modules/event'
  7. import { Transform } from '@dc-modules/transform'
  8. import { Polyline } from '@dc-modules/overlay'
  9. import Draw from './Draw'
  10. const DEF_STYLE = {
  11. width: 3,
  12. material: Cesium.Color.YELLOW.withAlpha(0.6)
  13. }
  14. class DrawPolyline extends Draw {
  15. constructor(style) {
  16. super()
  17. this._style = {
  18. ...DEF_STYLE,
  19. ...style
  20. }
  21. }
  22. /**
  23. *
  24. * @private
  25. */
  26. _mountedHook() {
  27. this.drawTool.tooltipMess = '左击选择点位,右击结束'
  28. this._delegate = new Cesium.Entity({
  29. polyline: {
  30. ...this._style,
  31. positions: new Cesium.CallbackProperty(() => {
  32. return this._positions
  33. }, false)
  34. }
  35. })
  36. this._layer.entities.add(this._delegate)
  37. }
  38. /**
  39. *
  40. * @private
  41. */
  42. _stopdHook() {
  43. let polyline = null
  44. if (this._positions.length) {
  45. polyline = new Polyline(
  46. Transform.transformCartesianArrayToWGS84Array(this._positions)
  47. ).setStyle(this._style)
  48. }
  49. this._options.onDrawStop && this._options.onDrawStop(polyline)
  50. }
  51. /**
  52. *
  53. * @param position
  54. * @returns {boolean}
  55. * @private
  56. */
  57. _onDrawAnchor(position) {
  58. let len = this._positions.length
  59. this._positions.push(position)
  60. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  61. if (len >= this._options.maxAnchorSize) {
  62. this._positions.pop()
  63. this.drawTool.fire(PlotEventType.DRAW_STOP)
  64. }
  65. }
  66. }
  67. export default DrawPolyline