Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

DrawPolygon.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 20:55:14
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { PlotEventType } from '@dc-modules/event'
  7. import { Transform } from '@dc-modules/transform'
  8. import { Polygon } from '@dc-modules/overlay'
  9. import Draw from './Draw'
  10. const DEF_STYLE = {
  11. material: Cesium.Color.YELLOW.withAlpha(0.6),
  12. fill: true
  13. }
  14. class DrawPolygon 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. polygon: {
  30. ...this._style,
  31. hierarchy: new Cesium.CallbackProperty(() => {
  32. if (this._positions.length > 2) {
  33. return new Cesium.PolygonHierarchy(this._positions)
  34. } else {
  35. return null
  36. }
  37. }, false)
  38. }
  39. })
  40. this._layer.entities.add(this._delegate)
  41. }
  42. /**
  43. *
  44. * @private
  45. */
  46. _stopdHook() {
  47. let polygon = null
  48. if (this._positions.length) {
  49. polygon = new Polygon(
  50. Transform.transformCartesianArrayToWGS84Array(this._positions)
  51. ).setStyle(this._style)
  52. }
  53. this._options.onDrawStop && this._options.onDrawStop(polygon)
  54. }
  55. /**
  56. *
  57. * @param position
  58. * @private
  59. */
  60. _onDrawAnchor(position) {
  61. this._positions.push(position)
  62. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  63. }
  64. }
  65. export default DrawPolygon