Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DrawPolyline.js 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 Draw from './Draw'
  8. class DrawPolyline extends Draw {
  9. constructor(style) {
  10. super(style)
  11. }
  12. /**
  13. *
  14. * @private
  15. */
  16. _mountedHook() {
  17. this.drawTool.tooltipMess = '左击选择点位,右击结束'
  18. this._delegate = new Cesium.Entity({
  19. polyline: {
  20. ...this._style,
  21. positions: new Cesium.CallbackProperty(() => {
  22. return this._positions
  23. }, false)
  24. }
  25. })
  26. this._layer.entities.add(this._delegate)
  27. }
  28. /**
  29. *
  30. * @param position
  31. * @returns {boolean}
  32. * @private
  33. */
  34. _onDrawAnchor(position) {
  35. let len = this._positions.length
  36. this._positions.push(position)
  37. if (len > 0) {
  38. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  39. }
  40. if (len >= this._options.maxAnchorSize) {
  41. this._positions.pop()
  42. this.drawTool.fire(PlotEventType.DRAW_STOP, position)
  43. }
  44. }
  45. }
  46. export default DrawPolyline