Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 20:55:14
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { Transform } from '@dc-modules/transform'
  7. import { Polygon } from '@dc-modules/overlay'
  8. import Draw from './Draw'
  9. const DEF_STYLE = {
  10. material: Cesium.Color.YELLOW.withAlpha(0.6),
  11. fill: true
  12. }
  13. class DrawPolygon extends Draw {
  14. constructor(style) {
  15. super()
  16. this._style = {
  17. ...DEF_STYLE,
  18. ...style
  19. }
  20. this._tooltipMess = '左击选择点位,右击结束'
  21. }
  22. _mountEntity() {
  23. this._delegate = new Cesium.Entity({
  24. polygon: {
  25. ...this._style,
  26. hierarchy: new Cesium.CallbackProperty(() => {
  27. if (this._positions.length > 2) {
  28. return new Cesium.PolygonHierarchy(this._positions)
  29. } else {
  30. return null
  31. }
  32. }, false)
  33. }
  34. })
  35. this._layer.add(this._delegate)
  36. }
  37. _onClick(e) {
  38. let position = this._clampToGround ? e.surfacePosition : e.position
  39. if (!position) {
  40. return false
  41. }
  42. let len = this._positions.length
  43. if (len === 0) {
  44. this._positions.push(position)
  45. this.createAnchor(position)
  46. this._floatingAnchor = this.createAnchor(position)
  47. }
  48. this._positions.push(position)
  49. this.createAnchor(position)
  50. }
  51. _onRightClick(e) {
  52. this.unbindEvent()
  53. let polygon = new Polygon(
  54. Transform.transformCartesianArrayToWGS84Array(this._positions)
  55. )
  56. polygon.setStyle(this._style)
  57. this._plotEvent.raiseEvent(polygon)
  58. }
  59. }
  60. export default DrawPolygon