Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

GeoTools.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * @Author : Caven Chen
  3. */
  4. import Parse from '../parse/Parse'
  5. import { getLib } from '../../global-api/index.js'
  6. class GeoTools {
  7. /**
  8. *
  9. * @param position
  10. * @param radius
  11. * @param steps
  12. * @returns {*[]}
  13. */
  14. static pointBuffer(position, radius, steps = 8) {
  15. const turf = getLib("turf")
  16. if(!turf) {
  17. throw 'missing turf'
  18. }
  19. const point = turf.point(Parse.parsePointCoordToArray(position))
  20. const buffered = turf.buffer(point, radius, { units: 'meters', steps })
  21. return buffered?.geometry?.coordinates[0] || []
  22. }
  23. /**
  24. *
  25. * @param positions
  26. * @param radius
  27. * @param steps
  28. * @returns {*[]}
  29. */
  30. static polylineBuffer(positions, radius, steps = 8) {
  31. const turf = getLib("turf")
  32. if(!turf) {
  33. throw 'missing turf'
  34. }
  35. const polyline = turf.lineString(Parse.parsePolylineCoordToArray(positions))
  36. const buffered = turf.buffer(polyline, radius, { units: 'meters', steps })
  37. return buffered?.geometry?.coordinates[0] || []
  38. }
  39. /**
  40. *
  41. * @param positions
  42. * @param radius
  43. * @param steps
  44. * @returns {*[]}
  45. */
  46. static polygonBuffer(positions, radius, steps = 8) {
  47. const turf = getLib("turf")
  48. if(!turf) {
  49. throw 'missing turf'
  50. }
  51. const polygon = turf.polygon(Parse.parsePolygonCoordToArray(positions, true))
  52. const buffered = turf.buffer(polygon, radius, { units: 'meters', steps })
  53. return buffered?.geometry?.coordinates[0] || []
  54. }
  55. /**
  56. *
  57. * @param center
  58. * @param radius
  59. * @param startAngle
  60. * @param endAngle
  61. * @param steps
  62. * @returns {*[]}
  63. */
  64. static sector(center, radius, startAngle, endAngle, steps = 64) {
  65. const turf = getLib("turf")
  66. if(!turf) {
  67. throw 'missing turf'
  68. }
  69. const point = turf.point(Parse.parsePointCoordToArray(center))
  70. const sector = turf.sector(point, radius, startAngle, endAngle, {
  71. units: 'meters',
  72. steps,
  73. })
  74. return sector?.geometry?.coordinates[0] || []
  75. }
  76. /**
  77. *
  78. * @param positions
  79. * @param factor
  80. * @returns {*[]}
  81. */
  82. static transformPolylineScale(positions, factor) {
  83. const turf = getLib("turf")
  84. if(!turf) {
  85. throw 'missing turf'
  86. }
  87. const polyline = turf.lineString(Parse.parsePolylineCoordToArray(positions))
  88. const scaledPolyline = turf.transformScale(polyline, factor)
  89. return scaledPolyline?.geometry?.coordinates || []
  90. }
  91. /**
  92. *
  93. * @param positions
  94. * @param factor
  95. * @returns {*[]}
  96. */
  97. static transformPolygonScale(positions, factor) {
  98. const turf = getLib("turf")
  99. if(!turf) {
  100. throw 'missing turf'
  101. }
  102. const polygon = turf.polygon(Parse.parsePolygonCoordToArray(positions, true))
  103. const scaledPolygon = turf.transformScale(polygon, factor)
  104. return scaledPolygon?.geometry?.coordinates[0] || []
  105. }
  106. /**
  107. *
  108. * @param positions
  109. * @param angle
  110. * @returns {*[]}
  111. */
  112. static transformPolylineRotate(positions, angle) {
  113. const turf = getLib("turf")
  114. if(!turf) {
  115. throw 'missing turf'
  116. }
  117. const polyline = turf.lineString(Parse.parsePolylineCoordToArray(positions))
  118. const rotatedPolyline = turf.transformRotate(polyline, angle)
  119. return rotatedPolyline?.geometry?.coordinates || []
  120. }
  121. /**
  122. *
  123. * @param positions
  124. * @param angle
  125. * @returns {*[]}
  126. */
  127. static transformPolygonRotate(positions, angle) {
  128. const turf = getLib("turf")
  129. if(!turf) {
  130. throw 'missing turf'
  131. }
  132. const polygon = turf.polygon(Parse.parsePolygonCoordToArray(positions, true))
  133. const rotatedPolyline = turf.transformRotate(polygon, angle)
  134. return rotatedPolyline?.geometry?.coordinates[0] || []
  135. }
  136. }
  137. export default GeoTools