Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

DrawPolyline.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 = new Polyline(
  44. Transform.transformCartesianArrayToWGS84Array(this._positions)
  45. ).setStyle(this._style)
  46. this._options.onDrawStop && this._options.onDrawStop(polyline)
  47. }
  48. /**
  49. *
  50. * @param position
  51. * @returns {boolean}
  52. * @private
  53. */
  54. _onDrawAnchor(position) {
  55. this._positions.push(position)
  56. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  57. }
  58. }
  59. export default DrawPolyline