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.

GatheringPlace.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 23:00:27
  4. */
  5. import State from '@dc-modules/state/State'
  6. import Parse from '@dc-modules/parse/Parse'
  7. import { Util, PlotUtil } from '@dc-modules/utils'
  8. import { Transform } from '@dc-modules/transform'
  9. import Overlay from '../Overlay'
  10. const { Cesium } = DC.Namespace
  11. const HALF_PI = Math.PI / 2
  12. const FITTING_COUNT = 100
  13. class GatheringPlace extends Overlay {
  14. constructor(positions) {
  15. super()
  16. this._positions = Parse.parsePositions(positions)
  17. this._delegate = new Cesium.Entity({ polygon: {} })
  18. this.t = 0.4
  19. this.type = Overlay.getOverlayType('gathering_place')
  20. this._state = State.INITIALIZED
  21. }
  22. set positions(positions) {
  23. this._positions = Parse.parsePositions(positions)
  24. this._delegate.polygon.hierarchy = this._getHierarchy()
  25. return this
  26. }
  27. get positions() {
  28. return this._positions
  29. }
  30. _getHierarchy() {
  31. let pnts = Parse.parsePolygonCoordToArray(this._positions)[0]
  32. if (this._positions.length === 2) {
  33. let mid = PlotUtil.mid(pnts[0], pnts[1])
  34. let d = PlotUtil.distance(pnts[0], mid) / 0.9
  35. let pnt = PlotUtil.getThirdPoint(pnts[0], mid, HALF_PI, d, true)
  36. pnts = [pnts[0], pnt, pnts[1]]
  37. }
  38. let mid = PlotUtil.mid(pnts[0], pnts[2])
  39. pnts.push(mid, pnts[0], pnts[1])
  40. let normals = []
  41. for (let i = 0; i < pnts.length - 2; i++) {
  42. let pnt1 = pnts[i]
  43. let pnt2 = pnts[i + 1]
  44. let pnt3 = pnts[i + 2]
  45. let normalPoints = PlotUtil.getBisectorNormals(this.t, pnt1, pnt2, pnt3)
  46. normals = normals.concat(normalPoints)
  47. }
  48. let count = normals.length
  49. normals = [normals[count - 1]].concat(normals.slice(0, count - 1))
  50. let pList = []
  51. for (let i = 0; i < pnts.length - 2; i++) {
  52. let pnt1 = pnts[i]
  53. let pnt2 = pnts[i + 1]
  54. pList.push(pnt1)
  55. for (let t = 0; t <= FITTING_COUNT; t++) {
  56. let pnt = PlotUtil.getCubicValue(
  57. t / FITTING_COUNT,
  58. pnt1,
  59. normals[i * 2],
  60. normals[i * 2 + 1],
  61. pnt2
  62. )
  63. pList.push(pnt)
  64. }
  65. pList.push(pnt2)
  66. }
  67. return new Cesium.PolygonHierarchy(
  68. Transform.transformWGS84ArrayToCartesianArray(Parse.parsePositions(pList))
  69. )
  70. }
  71. _mountedHook() {
  72. /**
  73. * set the location
  74. */
  75. this.positions = this._positions
  76. }
  77. /**
  78. *
  79. * @param text
  80. * @param textStyle
  81. * @returns {GatheringPlace}
  82. */
  83. setLabel(text, textStyle) {
  84. return this
  85. }
  86. /**
  87. * Sets Style
  88. * @param style
  89. * @returns {GatheringPlace}
  90. */
  91. setStyle(style) {
  92. if (Object.keys(style).length === 0) {
  93. return this
  94. }
  95. delete style['positions']
  96. this._style = style
  97. Util.merge(this._delegate.polygon, this._style)
  98. return this
  99. }
  100. }
  101. Overlay.registerType('gathering_place')
  102. export default GatheringPlace