Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

GatheringPlace.js 2.8KB

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