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 1.4KB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 = new Polygon(
  48. Transform.transformCartesianArrayToWGS84Array(this._positions)
  49. ).setStyle(this._style)
  50. this._options.onDrawStop && this._options.onDrawStop(polygon)
  51. }
  52. /**
  53. *
  54. * @param position
  55. * @private
  56. */
  57. _onDrawAnchor(position) {
  58. this._positions.push(position)
  59. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  60. }
  61. }
  62. export default DrawPolygon