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.

DrawPolygon.js 973B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 Draw from './Draw'
  8. class DrawPolygon 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. polygon: {
  20. ...this._style,
  21. hierarchy: new Cesium.CallbackProperty(() => {
  22. if (this._positions.length > 2) {
  23. return new Cesium.PolygonHierarchy(this._positions)
  24. } else {
  25. return null
  26. }
  27. }, false)
  28. }
  29. })
  30. this._layer.entities.add(this._delegate)
  31. }
  32. /**
  33. *
  34. * @param position
  35. * @private
  36. */
  37. _onDrawAnchor(position) {
  38. this._positions.push(position)
  39. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  40. }
  41. }
  42. export default DrawPolygon