@pirireis/webglobeplugins 0.17.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/Math/{angle-calculation.js → angle-calculation.ts} +18 -14
  2. package/Math/{arc-cdf-points.js → arc-cdf-points.ts} +329 -272
  3. package/Math/{arc-generate-points-exponantial.js → arc-generate-points-exponantial.ts} +299 -254
  4. package/Math/{arc.js → arc.ts} +421 -292
  5. package/Math/bounds/line-bbox.js +225 -186
  6. package/Math/{circle-cdf-points.js → circle-cdf-points.ts} +143 -78
  7. package/Math/{circle.js → circle.ts} +49 -33
  8. package/Math/{constants.js → constants.ts} +12 -4
  9. package/Math/contour/{quadtreecontours.js → quadtreecontours.ts} +371 -300
  10. package/Math/contour/quadtreecontours1.js +336 -298
  11. package/Math/{finite-line-2d.js → finite-line-2d.ts} +68 -58
  12. package/Math/haversine.ts +33 -0
  13. package/Math/index.js +0 -1
  14. package/Math/juction/{arc-plane.js → arc-plane.ts} +203 -143
  15. package/Math/juction/{line-sphere.js → line-sphere.ts} +32 -22
  16. package/Math/juction/{plane-plane.js → plane-plane.ts} +62 -53
  17. package/Math/{line.js → line.ts} +84 -52
  18. package/Math/matrix4.ts +0 -0
  19. package/Math/mesh/mapbox-delaunay.d.ts +74 -0
  20. package/Math/{methods.js → methods.ts} +182 -107
  21. package/Math/{plane.js → plane.ts} +92 -56
  22. package/Math/{quaternion.js → quaternion.ts} +128 -106
  23. package/Math/roadmap.md +10 -0
  24. package/Math/templete-shapes/{grid-visually-equal.js → grid-visually-equal.ts} +118 -65
  25. package/Math/tessellation/constants.ts +1 -0
  26. package/Math/tessellation/methods.ts +79 -0
  27. package/Math/tessellation/nearest-value-padding.ts +147 -0
  28. package/Math/tessellation/roadmap.md +48 -0
  29. package/Math/tessellation/spherical-triangle-area.ts +127 -0
  30. package/Math/tessellation/tile-merger.ts +578 -0
  31. package/Math/tessellation/triangle-tessellation.ts +533 -0
  32. package/Math/tessellation/types.ts +1 -0
  33. package/Math/types.ts +68 -0
  34. package/Math/utils.js +3 -2
  35. package/Math/{vec3.js → vec3.ts} +227 -151
  36. package/Math/xyz-tile.ts +26 -0
  37. package/algorithms/search-binary.js +14 -16
  38. package/altitude-locator/adaptors.js +0 -1
  39. package/altitude-locator/keymethod.js +0 -1
  40. package/altitude-locator/plugin.js +445 -345
  41. package/altitude-locator/types.js +26 -21
  42. package/compass-rose/compass-rose-padding-flat.js +274 -230
  43. package/compass-rose/{compass-text-writer.js → compass-text-writer.ts} +210 -155
  44. package/compass-rose/index.js +3 -3
  45. package/{constants.js → constants.ts} +8 -6
  46. package/heatwave/datamanager.js +168 -149
  47. package/heatwave/heatwave.js +261 -206
  48. package/heatwave/index.js +5 -5
  49. package/heatwave/isobar.js +340 -303
  50. package/heatwave/{texture-point-sampler.js → texture-point-sampler.ts} +220 -187
  51. package/investigation-tools/draw/tiles/adapters.ts +133 -0
  52. package/investigation-tools/draw/tiles/tiles.ts +162 -0
  53. package/jest.config.js +6 -7
  54. package/package.json +1 -1
  55. package/pin/pin-object-array1.js +381 -300
  56. package/pin/pin-point-totem1.js +77 -60
  57. package/programs/arrowfield/arrow-field.js +89 -60
  58. package/programs/arrowfield/logic.js +173 -141
  59. package/programs/data2legend/density-to-legend.js +86 -68
  60. package/programs/data2legend/point-to-density-texture.js +84 -67
  61. package/programs/float2legendwithratio/index.js +3 -2
  62. package/programs/float2legendwithratio/logic.js +144 -118
  63. package/programs/float2legendwithratio/object.js +141 -104
  64. package/programs/helpers/blender.js +73 -58
  65. package/programs/helpers/{fadeaway.js → fadeaway.ts} +73 -55
  66. package/programs/index.js +19 -20
  67. package/programs/line-on-globe/circle-accurate-3d.js +112 -85
  68. package/programs/line-on-globe/circle-accurate-flat.js +200 -148
  69. package/programs/line-on-globe/degree-padding-around-circle-3d.js +134 -102
  70. package/programs/line-on-globe/index.js +0 -1
  71. package/programs/line-on-globe/lines-color-instanced-flat.js +99 -80
  72. package/programs/line-on-globe/linestrip/data.ts +29 -0
  73. package/programs/line-on-globe/linestrip/{linestrip.js → linestrip.ts} +152 -93
  74. package/programs/line-on-globe/{naive-accurate-flexible.js → naive-accurate-flexible.ts} +175 -126
  75. package/programs/line-on-globe/util.js +8 -5
  76. package/programs/picking/pickable-polygon-renderer.js +129 -98
  77. package/programs/picking/pickable-renderer.js +130 -98
  78. package/programs/point-on-globe/element-globe-surface-glow.js +122 -93
  79. package/programs/point-on-globe/element-point-glow.js +114 -80
  80. package/programs/point-on-globe/square-pixel-point.js +139 -120
  81. package/programs/polygon-on-globe/roadmap.md +8 -0
  82. package/programs/polygon-on-globe/texture-dem-triangles.ts +290 -0
  83. package/programs/{programcache.js → programcache.ts} +134 -126
  84. package/programs/rings/index.js +1 -1
  85. package/programs/rings/partial-ring/{piece-of-pie.js → piece-of-pie.ts} +222 -152
  86. package/programs/totems/camera-totem-attactment-interface.ts +4 -0
  87. package/programs/totems/{camerauniformblock.js → camerauniformblock.ts} +326 -230
  88. package/programs/totems/{canvas-webglobe-info.js → canvas-webglobe-info.ts} +147 -132
  89. package/programs/totems/dem-textures-manager.ts +368 -0
  90. package/programs/totems/{globe-changes.js → globe-changes.ts} +79 -59
  91. package/programs/totems/gpu-selection-uniform-block.js +127 -99
  92. package/programs/totems/{index.js → index.ts} +2 -2
  93. package/programs/two-d/pixel-padding-for-compass.js +101 -87
  94. package/programs/util.js +19 -14
  95. package/programs/vectorfields/logics/{constants.js → constants.ts} +5 -4
  96. package/programs/vectorfields/logics/drawrectangleparticles.ts +182 -0
  97. package/programs/vectorfields/logics/index.js +4 -2
  98. package/programs/vectorfields/logics/particle-ubo.ts +23 -0
  99. package/programs/vectorfields/logics/{pixelbased.js → pixelbased.ts} +119 -84
  100. package/programs/vectorfields/logics/ubo.js +57 -51
  101. package/programs/vectorfields/{pingpongbuffermanager.js → pingpongbuffermanager.ts} +113 -73
  102. package/publish.bat +62 -0
  103. package/range-tools-on-terrain/bearing-line/{adapters.js → adapters.ts} +154 -114
  104. package/range-tools-on-terrain/bearing-line/{plugin.js → plugin.ts} +569 -457
  105. package/range-tools-on-terrain/bearing-line/types.ts +65 -0
  106. package/range-tools-on-terrain/circle-line-chain/{adapters.js → adapters.ts} +104 -85
  107. package/range-tools-on-terrain/circle-line-chain/{chain-list-map.js → chain-list-map.ts} +446 -382
  108. package/range-tools-on-terrain/circle-line-chain/{plugin.js → plugin.ts} +607 -464
  109. package/range-tools-on-terrain/circle-line-chain/types.ts +43 -0
  110. package/range-tools-on-terrain/range-ring/{adapters.js → adapters.ts} +114 -93
  111. package/range-tools-on-terrain/range-ring/{enum.js → enum.ts} +2 -2
  112. package/range-tools-on-terrain/range-ring/{plugin.js → plugin.ts} +444 -377
  113. package/range-tools-on-terrain/range-ring/rangeringangletext.ts +396 -0
  114. package/range-tools-on-terrain/range-ring/types.ts +30 -0
  115. package/semiplugins/interface.ts +14 -0
  116. package/semiplugins/lightweight/{line-plugin.js → line-plugin.ts} +342 -221
  117. package/semiplugins/lightweight/{piece-of-pie-plugin.js → piece-of-pie-plugin.ts} +275 -200
  118. package/semiplugins/shape-on-terrain/{arc-plugin.js → arc-plugin.ts} +616 -472
  119. package/semiplugins/shape-on-terrain/{circle-plugin.js → circle-plugin.ts} +588 -444
  120. package/semiplugins/shape-on-terrain/goal.md +12 -0
  121. package/semiplugins/shape-on-terrain/{padding-1-degree.js → padding-1-degree.ts} +713 -539
  122. package/semiplugins/shape-on-terrain/terrain-polygon/adapters.ts +69 -0
  123. package/semiplugins/shape-on-terrain/terrain-polygon/data/cache-shortcuts.md +20 -0
  124. package/semiplugins/shape-on-terrain/terrain-polygon/data/cache.ts +149 -0
  125. package/semiplugins/shape-on-terrain/terrain-polygon/data/index-polygon-map.ts +58 -0
  126. package/semiplugins/shape-on-terrain/terrain-polygon/data/manager.ts +4 -0
  127. package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.js +196 -0
  128. package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.ts +209 -0
  129. package/semiplugins/shape-on-terrain/terrain-polygon/data/polygon-to-triangles.ts +144 -0
  130. package/semiplugins/shape-on-terrain/terrain-polygon/data/random.ts +165 -0
  131. package/semiplugins/shape-on-terrain/terrain-polygon/data/readme.md +5 -0
  132. package/semiplugins/shape-on-terrain/terrain-polygon/data/types.ts +37 -0
  133. package/semiplugins/shape-on-terrain/terrain-polygon/data/worker-contact.ts +81 -0
  134. package/semiplugins/shape-on-terrain/terrain-polygon/data/worker.js +146 -0
  135. package/semiplugins/shape-on-terrain/terrain-polygon/notes.md +90 -0
  136. package/semiplugins/shape-on-terrain/terrain-polygon/terrain-polygon.ts +265 -0
  137. package/semiplugins/shape-on-terrain/terrain-polygon/types.ts +69 -0
  138. package/semiplugins/shell/bbox-renderer/index.ts +2 -0
  139. package/semiplugins/shell/bbox-renderer/{logic.js → logic.ts} +273 -249
  140. package/semiplugins/shell/bbox-renderer/object.ts +129 -0
  141. package/semiplugins/type.ts +8 -0
  142. package/semiplugins/utility/{container-plugin.js → container-plugin.ts} +126 -94
  143. package/semiplugins/utility/{object-pass-container-plugin.js → object-pass-container-plugin.ts} +101 -80
  144. package/shaders/fragment-toy/firework.js +1 -1
  145. package/shaders/fragment-toy/singularity.js +5 -2
  146. package/terrain-plugin.mmd +83 -0
  147. package/tests/Math/arc-sampling-test.js +367 -0
  148. package/tests/Math/arc-sampling-test.ts +429 -0
  149. package/tests/Math/arc.test.ts +77 -0
  150. package/tests/Math/junction/arc-limit.test.ts +7 -0
  151. package/tests/Math/junction/arc-plane-points.test.ts +196 -0
  152. package/tests/Math/junction/arc-plane.test.ts +172 -0
  153. package/tests/Math/junction/line-sphere.test.ts +127 -0
  154. package/tests/Math/junction/plane-plane.test.ts +91 -0
  155. package/tests/Math/plane-test.ts +17 -0
  156. package/tests/Math/plane.test.ts +43 -0
  157. package/tests/Math/vec3.test.ts +33 -0
  158. package/tracks/point-heat-map/adaptors/timetracksplugin-format-to-this.js +78 -63
  159. package/tracks/point-heat-map/index.js +0 -1
  160. package/tracks/point-heat-map/plugin-webworker.js +148 -121
  161. package/tracks/point-heat-map/point-to-heat-map-flow.js +150 -121
  162. package/tracks/point-heat-map/readme.md +15 -0
  163. package/tracks/point-tracks/key-methods.js +3 -2
  164. package/tracks/point-tracks/plugin.js +487 -393
  165. package/tracks/timetracks/adaptors-line-strip.js +79 -65
  166. package/tracks/timetracks/plugin-line-strip.js +295 -240
  167. package/tracks/timetracks/program-line-strip.js +495 -411
  168. package/tracks/timetracks/programpoint-line-strip.js +137 -109
  169. package/tracks/timetracks/readme.md +1 -0
  170. package/tsconfig.json +22 -0
  171. package/types/@pirireis/webglobe.d.ts +102 -0
  172. package/types/delaunator.d.ts +40 -0
  173. package/types/earcut.d.ts +11 -0
  174. package/types/rbush.d.ts +57 -0
  175. package/types.ts +319 -0
  176. package/util/account/bufferoffsetmanager.js +209 -176
  177. package/util/account/create-buffermap-orchastration.ts +85 -0
  178. package/util/account/index.js +6 -3
  179. package/util/account/single-attribute-buffer-management/{buffer-manager.js → buffer-manager.ts} +151 -117
  180. package/util/account/single-attribute-buffer-management/{buffer-orchestrator.js → buffer-orchestrator.ts} +238 -212
  181. package/util/account/single-attribute-buffer-management/{buffer-orchestrator1.js → buffer-orchestrator1.ts} +184 -159
  182. package/util/account/single-attribute-buffer-management/{index.js → index.ts} +11 -4
  183. package/util/account/single-attribute-buffer-management/{object-store.js → object-store.ts} +76 -55
  184. package/util/account/single-attribute-buffer-management/types.ts +43 -0
  185. package/util/account/util.js +22 -18
  186. package/util/algorithms/index.js +0 -1
  187. package/util/algorithms/search-binary.js +26 -25
  188. package/util/build-strategy/{static-dynamic.js → static-dynamic.ts} +50 -41
  189. package/util/check/index.js +0 -1
  190. package/util/check/typecheck.ts +74 -0
  191. package/util/{frame-counter-trigger.js → frame-counter-trigger.ts} +99 -84
  192. package/util/geometry/{index.js → index.ts} +155 -121
  193. package/util/gl-util/buffer/{attribute-loader.js → attribute-loader.ts} +84 -62
  194. package/util/gl-util/buffer/{index.js → index.ts} +6 -3
  195. package/util/gl-util/draw-options/{methods.js → methods.ts} +47 -32
  196. package/util/gl-util/uniform-block/{manager.js → manager.ts} +232 -190
  197. package/util/{webglobe/gldefaultstates.js → globe-default-gl-states.ts} +5 -4
  198. package/util/helper-methods.ts +9 -0
  199. package/util/index.js +9 -10
  200. package/util/interpolation/index.js +0 -1
  201. package/util/interpolation/timetrack/index.js +9 -2
  202. package/util/interpolation/timetrack/timetrack-interpolator.js +94 -79
  203. package/util/interpolation/timetrack/web-worker.js +51 -46
  204. package/util/picking/{fence.js → fence.ts} +47 -41
  205. package/util/picking/picker-displayer.ts +226 -0
  206. package/util/programs/draw-from-pixel-coords.js +201 -164
  207. package/util/programs/{draw-texture-on-canvas.js → draw-texture-on-canvas.ts} +92 -67
  208. package/util/programs/supersampletotextures.js +130 -97
  209. package/util/programs/texturetoglobe.js +153 -128
  210. package/util/shaderfunctions/{geometrytransformations.js → geometrytransformations.ts} +169 -41
  211. package/util/shaderfunctions/index.js +2 -2
  212. package/util/shaderfunctions/nodata.js +4 -2
  213. package/util/shaderfunctions/noisefunctions.js +10 -7
  214. package/util/{webglobjectbuilders.js → webglobjectbuilders.ts} +446 -358
  215. package/vectorfield/arrowfield/adaptor.js +11 -11
  216. package/vectorfield/arrowfield/index.js +3 -3
  217. package/vectorfield/arrowfield/plugin.js +128 -83
  218. package/vectorfield/waveparticles/adaptor.js +16 -15
  219. package/vectorfield/waveparticles/index.js +3 -3
  220. package/vectorfield/waveparticles/plugin.ts +506 -0
  221. package/vectorfield/wind/adapters/image-to-fields.ts +74 -0
  222. package/vectorfield/wind/adapters/types.ts +12 -0
  223. package/vectorfield/wind/{imagetovectorfieldandmagnitude.js → imagetovectorfieldandmagnitude.ts} +78 -56
  224. package/vectorfield/wind/index.js +5 -5
  225. package/vectorfield/wind/plugin-persistant copy.ts +461 -0
  226. package/vectorfield/wind/plugin-persistant.ts +483 -0
  227. package/vectorfield/wind/plugin.js +883 -671
  228. package/vectorfield/wind/vectorfieldimage.js +27 -23
  229. package/write-text/{context-text-bulk.js → context-text-bulk.ts} +285 -200
  230. package/write-text/context-text3.ts +252 -0
  231. package/write-text/{context-text4.js → context-text4.ts} +231 -145
  232. package/write-text/context-textDELETE.js +125 -94
  233. package/write-text/objectarraylabels/{index.js → index.ts} +2 -2
  234. package/write-text/objectarraylabels/objectarraylabels.d.ts +72 -0
  235. package/write-text/objectarraylabels/objectarraylabels.js +247 -200
  236. package/Math/matrix4.js +0 -1
  237. package/Math/tessellation/earcut/adapters.js +0 -37
  238. package/Math/tessellation/hybrid-triangle-tessellation-meta.js +0 -123
  239. package/Math/tessellation/methods.js +0 -46
  240. package/Math/tessellation/shred-input.js +0 -18
  241. package/Math/tessellation/tile-merger.js +0 -56
  242. package/Math/tessellation/tiler.js +0 -50
  243. package/Math/tessellation/triangle-tessellation-meta.js +0 -516
  244. package/Math/tessellation/triangle-tessellation.js +0 -14
  245. package/Math/tessellation/types.js +0 -1
  246. package/Math/tessellation/zoom-catch.js +0 -1
  247. package/Math/types.js +0 -1
  248. package/programs/line-on-globe/linestrip/data.js +0 -4
  249. package/programs/polygon-on-globe/partial-tesselation.js +0 -1
  250. package/programs/polygon-on-globe/texture-dem-triangle-test-plugin-triangle.js +0 -204
  251. package/programs/polygon-on-globe/texture-dem-triangle-test-plugin.js +0 -118
  252. package/programs/polygon-on-globe/texture-dem-triangles.js +0 -236
  253. package/programs/vectorfields/logics/drawrectangleparticles.js +0 -112
  254. package/programs/vectorfields/logics/ubo-new.js +0 -25
  255. package/range-tools-on-terrain/bearing-line/types.js +0 -1
  256. package/range-tools-on-terrain/circle-line-chain/types.js +0 -1
  257. package/range-tools-on-terrain/range-ring/rangeringangletext.js +0 -331
  258. package/range-tools-on-terrain/range-ring/types.js +0 -9
  259. package/semiplugins/interface.js +0 -1
  260. package/semiplugins/shape-on-terrain/terrain-cover/texture-dem-cover.js +0 -1
  261. package/semiplugins/shell/bbox-renderer/index.js +0 -2
  262. package/semiplugins/shell/bbox-renderer/object.js +0 -65
  263. package/semiplugins/type.js +0 -1
  264. package/types.js +0 -19
  265. package/util/account/create-buffermap-orchastration.js +0 -39
  266. package/util/account/single-attribute-buffer-management/types.js +0 -1
  267. package/util/check/typecheck.js +0 -66
  268. package/util/gl-util/uniform-block/types.js +0 -1
  269. package/util/picking/picker-displayer.js +0 -134
  270. package/util/webglobe/index.js +0 -2
  271. package/util/webglobe/rasteroverlay.js +0 -76
  272. package/vectorfield/waveparticles/plugin.js +0 -290
  273. package/write-text/attached-text-writer.js +0 -95
  274. package/write-text/context-text3.js +0 -167
@@ -1,539 +1,713 @@
1
- // One Degree Padding
2
- /**
3
- * 2d coordinates are loaded ones
4
- * 3d coordinates are calculated on the fly.
5
- *
6
- * 2d paddings are fixed size
7
- * 3d paddings gets shortened as lod increases
8
- *
9
- * color buffer is shared and does not change on unless insert or delete
10
- * changing color can be done by re inserting
11
- *
12
- *
13
- *
14
- */
15
- import { BufferManager } from '../../util/account/single-attribute-buffer-management/buffer-manager';
16
- import { BufferOrchestrator } from '../../util/account/single-attribute-buffer-management/buffer-orchestrator';
17
- import { LineStripProgramCache } from '../../programs/line-on-globe/linestrip/linestrip';
18
- import { opacityCheck, colorCheck } from '../../util/check/typecheck';
19
- import { FrameCounterTrigger } from '../../util/frame-counter-trigger';
20
- const initialCapacity = 2; // initial capacity for the buffer managers
21
- // const _float32Array = new Float32Array(360 * 3 * 2).fill(NaN);
22
- export class Padding1DegreePlugin {
23
- id;
24
- globe = null;
25
- bufferOrchestrator;
26
- bufferManagerMap;
27
- lineProgram = null;
28
- _innerPaddingRatio = 0.95; //
29
- _float32Array = null; // this is used to forward the data to the buffer manager
30
- _uboHandler = null; // this is used to forward the data to the shader program
31
- _bufferNames = ["position2d", "position3d"];
32
- _vao = null; // this is used to store the VAO for the plugin
33
- _freed = false; // this is used to check if the plugin is freed or not
34
- _userOpacity = 1;
35
- _adaptiveOpacityMultiplier = 1;
36
- _dataMap = new Map();
37
- _options = {
38
- bufferType: "STATIC_DRAW",
39
- variativeColorsOn: false,
40
- defaultColor: [1, 1, 1, 1], // white color
41
- defaultHeightFromGroundIn3D: 0.1, // 10 cm from ground
42
- adativePaddingSize: true, // if true, the padding size will be adaptive to the LOD
43
- adaptiveOpacity: true, // if true, the opacity will be adaptive to the LOD
44
- isMSL: false // if true, no elevation of terrain
45
- };
46
- _frameCounterTrigger = null;
47
- constructor(id, options = null) {
48
- this.id = id;
49
- this.bufferManagerMap = new Map();
50
- this.lineProgram = null;
51
- this._options = options ? { ...this._options, ...options } : this._options;
52
- this.bufferOrchestrator = new BufferOrchestrator();
53
- if (this._options.variativeColorsOn) {
54
- this._bufferNames.push("color");
55
- }
56
- }
57
- increaseSpace(amount) {
58
- if (this._freed) {
59
- console.warn("Plugin is freed, cannot increase space");
60
- return;
61
- }
62
- if (this.globe === null) {
63
- console.warn("Globe is not initialized.");
64
- return;
65
- }
66
- if (typeof amount !== "number" || amount <= 0) {
67
- console.warn("Invalid amount, must be a positive number");
68
- return;
69
- }
70
- this.bufferOrchestrator.ensureSpace(amount, this.bufferManagerMap);
71
- }
72
- insertBulk(inputs) {
73
- if (this.globe === null) {
74
- console.warn("Globe is not initialized, cannot insert input");
75
- return;
76
- }
77
- if (this._freed) {
78
- console.warn("Plugin is freed, cannot insert input");
79
- return;
80
- }
81
- const wrapper = [null];
82
- this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
83
- let newItemCount = 0;
84
- for (let i = 0; i < inputs.length; i++) {
85
- if (!this._dataMap.has(inputs[i].key)) {
86
- newItemCount++;
87
- }
88
- }
89
- this.bufferOrchestrator.ensureSpace(newItemCount, this.bufferManagerMap);
90
- for (let i = 0; i < inputs.length; i++) {
91
- const coords = preAdapter(this.globe, inputs[i], this._innerPaddingRatio, null);
92
- const paddingInput = { ...inputs[i], ...coords };
93
- this._dataMap.set(paddingInput.key, paddingInput);
94
- wrapper[0] = paddingInput;
95
- this.bufferOrchestrator.insertBulk(wrapper, this.bufferManagerMap, this._bufferNames);
96
- }
97
- this._float32Array = null;
98
- this.globe?.DrawRender();
99
- }
100
- updateColorRatios(key, colorRatios, drawRender = true) {
101
- if (this._freed) {
102
- console.warn("Plugin is freed, cannot update color");
103
- return;
104
- }
105
- if (this.globe === null) {
106
- console.warn("Globe is not initialized, cannot update color");
107
- return;
108
- }
109
- if (!this._options.variativeColorsOn) {
110
- console.warn("VariativeColors are not enabled");
111
- return;
112
- }
113
- if (!this._dataMap.has(key)) {
114
- console.warn(`Key ${key} does not exist in the data map`);
115
- return;
116
- }
117
- const paddingInput = this._dataMap.get(key);
118
- if (!paddingInput) {
119
- console.warn(`Padding input for key ${key} is not found`);
120
- return;
121
- }
122
- this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
123
- paddingInput.colorsRatios = colorRatios;
124
- this.bufferOrchestrator.updateBulk([paddingInput], this.bufferManagerMap, ["color"]);
125
- this._float32Array = null;
126
- if (drawRender) {
127
- this.globe.DrawRender();
128
- }
129
- }
130
- updateCoordinates(items) {
131
- if (this._freed) {
132
- console.warn("Plugin is freed, cannot update coordinates");
133
- return;
134
- }
135
- if (this.globe === null) {
136
- console.warn("Globe is not initialized, cannot update coordinates");
137
- return;
138
- }
139
- this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
140
- const updateKeys = [];
141
- for (const item of items) {
142
- const paddingInput = this._dataMap.get(item.key);
143
- if (!paddingInput) {
144
- console.warn(`Padding input for key ${item.key} is not found`);
145
- continue;
146
- }
147
- paddingInput.center = item.center;
148
- paddingInput.radius = item.radius;
149
- updateKeys.push(item.key);
150
- }
151
- this._buildPaddings("input", updateKeys);
152
- this._float32Array = null;
153
- this.globe.DrawRender();
154
- }
155
- deleteBulk(keys) {
156
- if (this.globe === null) {
157
- console.warn("Globe is not initialized, cannot delete data");
158
- return;
159
- }
160
- if (this._freed) {
161
- console.warn("Plugin is freed, cannot delete data");
162
- return;
163
- }
164
- this.bufferOrchestrator.deleteBulk(keys, this.bufferManagerMap);
165
- for (const key of keys) {
166
- this._dataMap.delete(key);
167
- }
168
- this.globe?.DrawRender();
169
- }
170
- setPluginOpacity(opacity, drawRender = false) {
171
- if (this._freed) {
172
- console.warn("Plugin is freed, cannot set opacity");
173
- return;
174
- }
175
- if (this.globe === null) {
176
- console.warn("Globe is not initialized, cannot set opacity");
177
- return;
178
- }
179
- opacityCheck(opacity);
180
- this._userOpacity = opacity;
181
- if (drawRender) {
182
- this.globe.DrawRender();
183
- }
184
- }
185
- setDefaultColor(color) {
186
- if (this._freed) {
187
- console.warn("Plugin is freed, cannot set default color");
188
- return;
189
- }
190
- if (this.globe === null) {
191
- console.warn("Globe is not initialized, cannot set default color");
192
- return;
193
- }
194
- colorCheck(color);
195
- this._options.defaultColor = color;
196
- this._uboHandler?.updateSingle("u_color", new Float32Array(color));
197
- this.globe.DrawRender();
198
- }
199
- setElevationMode(mode) {
200
- switch (mode) {
201
- case "msl":
202
- this._options.isMSL = true;
203
- break;
204
- case "agl":
205
- this._options.isMSL = false;
206
- break;
207
- default:
208
- throw new Error(`Unknown elevation mode: ${mode}`);
209
- }
210
- this._buildPaddings("elevation");
211
- this.globe?.DrawRender();
212
- }
213
- init(globe, gl) {
214
- this.globe = globe;
215
- this.lineProgram = LineStripProgramCache.get(globe);
216
- this._frameCounterTrigger = new FrameCounterTrigger(globe, 10, 1000, (globeChanges) => {
217
- if (this._freed)
218
- return;
219
- this.__build(globeChanges);
220
- globe.DrawRender();
221
- });
222
- this.__updateLODRelatedParameters();
223
- this.__updateAdaptiveOpacityMultiplier();
224
- const bufferManagerMap = new Map([
225
- ["position2d", {
226
- bufferManager: new BufferManager(globe.gl, 360 * 2 * 3, // plus 1 to cut
227
- { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
228
- adaptor: (paddingInput) => {
229
- if (this._float32Array === null) {
230
- throw new Error("Float32Array is not initialized");
231
- }
232
- else {
233
- this._float32Array.fill(NaN); // reset the float32Array
234
- }
235
- for (let i = 0; i < 360; i++) {
236
- const outerCoords = paddingInput.outerCoords[i];
237
- const innerCoords = paddingInput.innerCoords[i];
238
- if (outerCoords === null || innerCoords === null) {
239
- continue;
240
- }
241
- let coordsOuter = globe.api_GetMercator2DPoint(outerCoords[0], outerCoords[1]);
242
- // fill the second coordinate with 0
243
- this._float32Array[i * 6] = coordsOuter[0];
244
- this._float32Array[i * 6 + 1] = coordsOuter[1];
245
- let coordsInner = globe.api_GetMercator2DPoint(innerCoords[0], innerCoords[1]);
246
- // fill the second coordinate with 0
247
- this._float32Array[i * 6 + 2] = coordsInner[0];
248
- this._float32Array[i * 6 + 3] = coordsInner[1];
249
- }
250
- return this._float32Array.subarray(0, 360 * 2 * 3);
251
- }
252
- }
253
- ],
254
- [
255
- "position3d", {
256
- bufferManager: new BufferManager(globe.gl, 360 * 3 * 3, // plus 1 to cut
257
- { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
258
- adaptor: (paddingInput) => {
259
- if (this._float32Array === null) {
260
- throw new Error("Float32Array is not initialized");
261
- }
262
- else {
263
- this._float32Array.fill(NaN); // reset the float32Array
264
- }
265
- const _float32Array = this._float32Array;
266
- for (let i = 0; i < 360; i++) {
267
- const outerCoords = paddingInput.outerCoords[i];
268
- const innerCoords = paddingInput.innerCoords[i];
269
- if (outerCoords === null || innerCoords === null) {
270
- continue;
271
- }
272
- const height = paddingInput.heightFromGroundIn3D ?? this._options.defaultHeightFromGroundIn3D;
273
- let coords = globe.api_GetCartesian3DPoint(outerCoords[0], outerCoords[1], height, this._options.isMSL);
274
- // fill the second coordinate with 0
275
- _float32Array[i * 9] = coords[0];
276
- _float32Array[i * 9 + 1] = coords[1];
277
- _float32Array[i * 9 + 2] = coords[2];
278
- let coordsInner = globe.api_GetCartesian3DPoint(innerCoords[0], innerCoords[1], height, this._options.isMSL);
279
- // fill the second coordinate with 0
280
- _float32Array[i * 9 + 3] = coordsInner[0];
281
- _float32Array[i * 9 + 4] = coordsInner[1];
282
- _float32Array[i * 9 + 5] = coordsInner[2];
283
- }
284
- return _float32Array.subarray(0, 360 * 3 * 3);
285
- }
286
- }
287
- ],
288
- ]);
289
- if (this._options.variativeColorsOn) {
290
- bufferManagerMap.set("color", {
291
- bufferManager: new BufferManager(globe.gl, 360 * 4 * 3, // 4 for RGBA
292
- { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
293
- adaptor: (paddingInput) => {
294
- if (this._float32Array === null) {
295
- throw new Error("Float32Array is not initialized");
296
- }
297
- else {
298
- this._float32Array.fill(NaN); // reset the float32Array
299
- }
300
- if (!paddingInput.colorsRatios) {
301
- const color = this._options.defaultColor;
302
- const colorArray = new Float32Array(360 * 4 * 3);
303
- this._float32Array = colorArray; // store for forwarding
304
- for (let i = 0; i < 360; i++) {
305
- this._float32Array[i * 12] = color[0];
306
- this._float32Array[i * 12 + 1] = color[1];
307
- this._float32Array[i * 12 + 2] = color[2];
308
- this._float32Array[i * 12 + 3] = color[3];
309
- this._float32Array[i * 12 + 4] = color[0];
310
- this._float32Array[i * 12 + 5] = color[1];
311
- this._float32Array[i * 12 + 6] = color[2];
312
- this._float32Array[i * 12 + 7] = 0; //color[3] ;
313
- }
314
- return this._float32Array.subarray(0, 360 * 4 * 3);
315
- }
316
- else {
317
- const colorsRatios = paddingInput.colorsRatios;
318
- let i = 0;
319
- for (const colorRatio of colorsRatios) {
320
- const color = colorRatio.color;
321
- const ratio = colorRatio.ratio;
322
- for (let j = 0; j < ratio; j++) {
323
- this._float32Array[i * 12] = color[0];
324
- this._float32Array[i * 12 + 1] = color[1];
325
- this._float32Array[i * 12 + 2] = color[2];
326
- this._float32Array[i * 12 + 3] = color[3];
327
- this._float32Array[i * 12 + 4] = color[0];
328
- this._float32Array[i * 12 + 5] = color[1];
329
- this._float32Array[i * 12 + 6] = color[2];
330
- this._float32Array[i * 12 + 7] = 0.1; // color[3];
331
- i++;
332
- }
333
- }
334
- return this._float32Array.subarray(0, 360 * 4 * 3);
335
- }
336
- }
337
- });
338
- }
339
- const vaoInput = ["position3d", "position2d", "color"].map((name) => {
340
- const bufferManager = bufferManagerMap.get(name);
341
- if (!bufferManager) {
342
- return null;
343
- }
344
- return {
345
- buffer: bufferManager.bufferManager.buffer,
346
- stride: 0,
347
- offset: 0
348
- };
349
- });
350
- this._vao = this.lineProgram.createVAO(vaoInput[0], vaoInput[1], vaoInput[2]);
351
- this.bufferManagerMap = bufferManagerMap;
352
- this.bufferOrchestrator.resetWithCapacity(bufferManagerMap, initialCapacity);
353
- this._uboHandler = this.lineProgram.createUBO("STATIC_DRAW");
354
- this._uboHandler.updateSingle("u_color", new Float32Array(this._options.defaultColor));
355
- }
356
- draw3D() {
357
- if (this._freed) {
358
- console.warn("Plugin is freed, cannot draw");
359
- return;
360
- }
361
- if (this.globe === null || this.lineProgram === null || this._vao === null) {
362
- console.warn("Globe or LineProgram or VAO is not initialized, cannot draw");
363
- return;
364
- }
365
- this._frameCounterTrigger?.trigger();
366
- // this.__build();
367
- const gl = this.globe.gl;
368
- const drawOptions = {
369
- drawRange: {
370
- first: 0,
371
- count: this.bufferOrchestrator.length * (360 * 3), // plus 1 is for cutting linestrips
372
- },
373
- };
374
- gl.disable(gl.DEPTH_TEST);
375
- this.lineProgram.draw(this._vao, drawOptions, this._userOpacity * this._adaptiveOpacityMultiplier, this._uboHandler);
376
- gl.enable(gl.DEPTH_TEST);
377
- }
378
- free() {
379
- if (this._freed) {
380
- console.warn("Plugin is already freed");
381
- return;
382
- }
383
- if (!this.globe || !this.lineProgram) {
384
- console.warn("Globe or LineProgram is not initialized, cannot free the plugin");
385
- return;
386
- }
387
- this._freed = true;
388
- this._frameCounterTrigger?.free();
389
- LineStripProgramCache.release(this.lineProgram);
390
- this.lineProgram = null;
391
- this._uboHandler?.free();
392
- this._uboHandler = null;
393
- this.globe.gl.deleteVertexArray(this._vao);
394
- this.globe = null;
395
- this._vao = null;
396
- this.bufferManagerMap.forEach((bufferManager) => {
397
- bufferManager.bufferManager.free();
398
- });
399
- this._float32Array = null;
400
- }
401
- _buildPaddings(level, subSetIDs = null) {
402
- if (level === "input") {
403
- this.__inner(subSetIDs);
404
- this.__elevation(subSetIDs);
405
- }
406
- else if (level === "innerCircle") {
407
- // Build inner circle paddings
408
- if (this._options.adativePaddingSize) {
409
- this.__innerCircle(subSetIDs);
410
- }
411
- this.__elevation(subSetIDs);
412
- }
413
- else if (level === "elevation") {
414
- // Build elevation paddings
415
- this.__elevation(subSetIDs);
416
- }
417
- }
418
- __inner(subSetIDs = null) {
419
- // Implement inner circle padding logic
420
- const datas = this._dataMap;
421
- let keys;
422
- if (subSetIDs) {
423
- keys = subSetIDs;
424
- }
425
- else {
426
- keys = Array.from(datas.keys());
427
- }
428
- for (const key of keys) {
429
- const value = datas.get(key);
430
- if (!value)
431
- continue;
432
- // Implement inner circle padding logic using key and value
433
- const { innerCoords, outerCoords } = preAdapter(this.globe, value, this._innerPaddingRatio, null);
434
- value.outerCoords = outerCoords;
435
- value.innerCoords = innerCoords;
436
- }
437
- }
438
- __innerCircle(subSetIDs = null) {
439
- // Implement inner circle padding logic
440
- const datas = this._dataMap;
441
- let keys;
442
- if (subSetIDs) {
443
- keys = subSetIDs;
444
- }
445
- else {
446
- keys = Array.from(datas.keys());
447
- }
448
- for (const key of keys) {
449
- const value = datas.get(key);
450
- if (!value)
451
- continue;
452
- // Implement inner circle padding logic using key and value
453
- const { innerCoords } = preAdapter(this.globe, value, this._innerPaddingRatio, value.outerCoords);
454
- value.innerCoords = innerCoords;
455
- }
456
- }
457
- __elevation(subSetIDs = null) {
458
- this.__updateAdaptiveOpacityMultiplier();
459
- const bufferToUpdate = [this.globe?.api_GetCurrentGeometry() === 1 ? "position2d" : "position3d"];
460
- const datas = this._dataMap;
461
- const wrapper = [null];
462
- this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
463
- let keys;
464
- if (subSetIDs) {
465
- keys = subSetIDs;
466
- }
467
- else {
468
- keys = Array.from(datas.keys());
469
- }
470
- for (const key of keys) {
471
- const value = datas.get(key);
472
- if (!value)
473
- continue;
474
- wrapper[0] = value;
475
- this.bufferOrchestrator.updateBulk(wrapper, this.bufferManagerMap, bufferToUpdate);
476
- }
477
- this._float32Array = null; // reset the float32Array
478
- }
479
- __build(globeChanges) {
480
- if (globeChanges.lod) {
481
- this.__updateLODRelatedParameters();
482
- this._buildPaddings("innerCircle");
483
- }
484
- else if (globeChanges.look || globeChanges.geometry) {
485
- this._buildPaddings("elevation");
486
- }
487
- }
488
- __updateLODRelatedParameters() {
489
- const lod = this.globe?.api_GetCurrentLODWithDecimal();
490
- this._innerPaddingRatio = 1 - Math.pow(0.7, lod);
491
- }
492
- __updateAdaptiveOpacityMultiplier() {
493
- if (this._options.adaptiveOpacity === true) {
494
- const currentLod = this.globe?.api_GetCurrentLODWithDecimal();
495
- this._adaptiveOpacityMultiplier = Math.max(1 - (2.9 / currentLod), 0.1);
496
- }
497
- else {
498
- this._adaptiveOpacityMultiplier = 1; // TODO: set this once on adaptiveOpacity is Set to false
499
- }
500
- }
501
- }
502
- function preAdapter(globe, paddingInput, paddingRatio, outerCoords) {
503
- const innerCoords = new Array(360);
504
- if (outerCoords === null) {
505
- outerCoords = new Array(360);
506
- for (let i = 0; i < 360; i++) {
507
- const { long, lat } = globe.Math.FindPointByPolar(paddingInput.center[0], // center long
508
- paddingInput.center[1], // center lat
509
- paddingInput.radius, // outer radius
510
- i);
511
- const { long: endLong, lat: endLat } = globe.Math.FindPointByPolar(paddingInput.center[0], // center long
512
- paddingInput.center[1], // center lat
513
- paddingInput.radius * paddingRatio, // inner radius
514
- i);
515
- const longDifference = Math.abs(long - endLong);
516
- // const latDifference = Math.abs(lat - endLat);
517
- if (longDifference > 45) {
518
- outerCoords[i] = null;
519
- innerCoords[i] = null;
520
- continue;
521
- }
522
- // Assign the calculated coordinates
523
- outerCoords[i] = [long, lat];
524
- innerCoords[i] = [endLong, endLat];
525
- }
526
- }
527
- else {
528
- // Handle case when outerCoords is provided
529
- for (let i = 0; i < 360; i++) {
530
- if (outerCoords[i] === null) {
531
- innerCoords[i] = null;
532
- continue;
533
- }
534
- const { long: endLong, lat: endLat } = globe.Math.FindPointByPolar(paddingInput.center[0], paddingInput.center[1], paddingInput.radius * paddingRatio, i);
535
- innerCoords[i] = [endLong, endLat];
536
- }
537
- }
538
- return { outerCoords, innerCoords };
539
- }
1
+ // One Degree Padding
2
+ /**
3
+ * 2d coordinates are loaded ones
4
+ * 3d coordinates are calculated on the fly.
5
+ *
6
+ * 2d paddings are fixed size
7
+ * 3d paddings gets shortened as lod increases
8
+ *
9
+ * color buffer is shared and does not change on unless insert or delete
10
+ * changing color can be done by re inserting
11
+ *
12
+ *
13
+ *
14
+ */
15
+
16
+ import {
17
+ Globe,
18
+ GlobeChanges,
19
+ Meter,
20
+ Color,
21
+ BUFFER_TYPE,
22
+ UBOHandler,
23
+ ColorRatio,
24
+ PluginInterface,
25
+ DrawRangeIndexParams,
26
+ LongLatDegree
27
+ } from '../../types';
28
+ import { SemiPluginInterface } from '../interface';
29
+ import { BufferManagersMap } from '../../util/account/single-attribute-buffer-management/types';
30
+
31
+ import { BufferManager } from '../../util/account/single-attribute-buffer-management/buffer-manager';
32
+
33
+ import { BufferOrchestrator } from '../../util/account/single-attribute-buffer-management/buffer-orchestrator';
34
+
35
+ import {
36
+ LineStripProgramCache,
37
+ LineProgram
38
+ } from '../../programs/line-on-globe/linestrip/linestrip';
39
+ import {
40
+ opacityCheck,
41
+ colorCheck
42
+ } from '../../util/check/typecheck';
43
+ import { FrameCounterTrigger } from '../../util/frame-counter-trigger';
44
+
45
+
46
+
47
+ export type Padding1DegreeInput = {
48
+ key: string;
49
+ center: LongLatDegree;
50
+ radius: Meter;
51
+ heightFromGroundIn3D?: Meter; // optional, if not provided, defaultHeightFromGroundIn3D will be used
52
+ colorsRatios: ColorRatio[];
53
+ };
54
+
55
+
56
+ export type Padding1DegreePluginOptions = {
57
+ bufferType: BUFFER_TYPE;
58
+ variativeColorsOn: boolean;
59
+ defaultColor: Color;
60
+ defaultHeightFromGroundIn3D: Meter;
61
+ adativePaddingSize: boolean; // TODO : implement this
62
+ adaptiveOpacity: boolean; // TODO : implement this
63
+ isMSL: boolean;
64
+ }
65
+
66
+ const initialCapacity = 2; // initial capacity for the buffer managers
67
+
68
+ // You'll need to define this type based on your requirements
69
+ type InnerPadding1DegreeInput = {
70
+ key: string;
71
+ center: [number, number];
72
+ radius: number;
73
+ outerCoords: (LongLatDegree | null)[];
74
+ innerCoords: (LongLatDegree | null)[];
75
+ colorsRatios: ColorRatio[]; // optional, if not provided, defaultColor will be used
76
+ heightFromGroundIn3D: Meter;
77
+ };
78
+
79
+
80
+ // const _float32Array = new Float32Array(360 * 3 * 2).fill(NaN);
81
+
82
+ export class Padding1DegreePlugin implements SemiPluginInterface, PluginInterface {
83
+ id: string;
84
+ globe: Globe | null = null;
85
+ private bufferOrchestrator: BufferOrchestrator;
86
+ private bufferManagerMap: BufferManagersMap;
87
+ private lineProgram: LineProgram | null = null;
88
+ private _innerPaddingRatio = 0.95; //
89
+ private _float32Array: Float32Array | null = null; // this is used to forward the data to the buffer manager
90
+ private _uboHandler: UBOHandler | null = null; // this is used to forward the data to the shader program
91
+ private _bufferNames: string[] = ["position2d", "position3d"];
92
+ private _vao: WebGLVertexArrayObject | null = null; // this is used to store the VAO for the plugin
93
+ private _freed: boolean = false; // this is used to check if the plugin is freed or not
94
+ private _userOpacity: number = 1;
95
+ private _adaptiveOpacityMultiplier: number = 1;
96
+ private _dataMap = new Map<string, InnerPadding1DegreeInput>();
97
+ private _options: Padding1DegreePluginOptions = {
98
+ bufferType: "STATIC_DRAW",
99
+ variativeColorsOn: false,
100
+ defaultColor: [1, 1, 1, 1], // white color
101
+ defaultHeightFromGroundIn3D: 0.1, // 10 cm from ground
102
+ adativePaddingSize: true, // if true, the padding size will be adaptive to the LOD
103
+ adaptiveOpacity: true, // if true, the opacity will be adaptive to the LOD
104
+ isMSL: false // if true, no elevation of terrain
105
+
106
+ };
107
+ private _frameCounterTrigger: FrameCounterTrigger | null = null;
108
+
109
+ constructor(id: string, options: Partial<Padding1DegreePluginOptions> | null = null) {
110
+ this.id = id;
111
+ this.bufferManagerMap = new Map();
112
+ this.lineProgram = null;
113
+ this._options = options ? { ...this._options, ...options } : this._options;
114
+ this.bufferOrchestrator = new BufferOrchestrator()
115
+
116
+ if (this._options.variativeColorsOn) {
117
+ this._bufferNames.push("color");
118
+ }
119
+ }
120
+
121
+
122
+
123
+ increaseSpace(amount: number): void {
124
+ if (this._freed) {
125
+ console.warn("Plugin is freed, cannot increase space");
126
+ return;
127
+ }
128
+ if (this.globe === null) {
129
+ console.warn("Globe is not initialized.");
130
+ return;
131
+ }
132
+ if (typeof amount !== "number" || amount <= 0) {
133
+ console.warn("Invalid amount, must be a positive number");
134
+ return;
135
+ }
136
+ this.bufferOrchestrator.ensureSpace(amount, this.bufferManagerMap!);
137
+ }
138
+
139
+
140
+ insertBulk(inputs: Padding1DegreeInput[]): void {
141
+ if (this.globe === null) {
142
+ console.warn("Globe is not initialized, cannot insert input");
143
+ return;
144
+ }
145
+ if (this._freed) {
146
+ console.warn("Plugin is freed, cannot insert input");
147
+ return;
148
+ }
149
+
150
+ const wrapper: [InnerPadding1DegreeInput | null] = [null]
151
+ this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
152
+ let newItemCount = 0;
153
+ for (let i = 0; i < inputs.length; i++) {
154
+ if (!this._dataMap.has(inputs[i].key)) {
155
+ newItemCount++;
156
+ }
157
+ }
158
+ this.bufferOrchestrator.ensureSpace(newItemCount, this.bufferManagerMap!);
159
+ for (let i = 0; i < inputs.length; i++) {
160
+ const coords = preAdapter(this.globe, inputs[i], this._innerPaddingRatio, null);
161
+ const paddingInput = { ...inputs[i], ...coords } as InnerPadding1DegreeInput;
162
+ this._dataMap.set(paddingInput.key, paddingInput);
163
+ wrapper[0] = paddingInput;
164
+ this.bufferOrchestrator.insertBulk(wrapper, this.bufferManagerMap, this._bufferNames);
165
+ }
166
+ this._float32Array = null;
167
+ this.globe?.DrawRender();
168
+ }
169
+
170
+
171
+ updateColorRatios(key: string, colorRatios: ColorRatio[], drawRender: boolean = true): void {
172
+ if (this._freed) {
173
+ console.warn("Plugin is freed, cannot update color");
174
+ return;
175
+ }
176
+ if (this.globe === null) {
177
+ console.warn("Globe is not initialized, cannot update color");
178
+ return;
179
+ }
180
+ if (!this._options.variativeColorsOn) {
181
+ console.warn("VariativeColors are not enabled");
182
+ return;
183
+ }
184
+ if (!this._dataMap.has(key)) {
185
+ console.warn(`Key ${key} does not exist in the data map`);
186
+ return;
187
+ }
188
+ const paddingInput = this._dataMap.get(key);
189
+ if (!paddingInput) {
190
+ console.warn(`Padding input for key ${key} is not found`);
191
+ return;
192
+ }
193
+ this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
194
+
195
+ paddingInput.colorsRatios = colorRatios;
196
+ this.bufferOrchestrator.updateBulk([paddingInput], this.bufferManagerMap, ["color"]);
197
+ this._float32Array = null;
198
+ if (drawRender) {
199
+ this.globe.DrawRender();
200
+ }
201
+ }
202
+
203
+ updateCoordinates(items: Pick<Padding1DegreeInput, "key" | "center" | "radius">[]): void {
204
+ if (this._freed) {
205
+ console.warn("Plugin is freed, cannot update coordinates");
206
+ return;
207
+ }
208
+ if (this.globe === null) {
209
+ console.warn("Globe is not initialized, cannot update coordinates");
210
+ return;
211
+ }
212
+ this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
213
+
214
+ const updateKeys: string[] = [];
215
+ for (const item of items) {
216
+ const paddingInput = this._dataMap.get(item.key);
217
+ if (!paddingInput) {
218
+ console.warn(`Padding input for key ${item.key} is not found`);
219
+ continue;
220
+ }
221
+ paddingInput.center = item.center;
222
+ paddingInput.radius = item.radius;
223
+ updateKeys.push(item.key);
224
+ }
225
+
226
+ this._buildPaddings("input", updateKeys);
227
+ this._float32Array = null;
228
+ this.globe.DrawRender();
229
+ }
230
+
231
+ deleteBulk(keys: string[]): void {
232
+ if (this.globe === null) {
233
+ console.warn("Globe is not initialized, cannot delete data");
234
+ return;
235
+ }
236
+ if (this._freed) {
237
+ console.warn("Plugin is freed, cannot delete data");
238
+ return;
239
+ }
240
+ this.bufferOrchestrator.deleteBulk(keys, this.bufferManagerMap);
241
+ for (const key of keys) {
242
+ this._dataMap.delete(key);
243
+ }
244
+ this.globe?.DrawRender();
245
+ }
246
+
247
+ setPluginOpacity(opacity: number, drawRender: boolean = false): void {
248
+ if (this._freed) {
249
+ console.warn("Plugin is freed, cannot set opacity");
250
+ return;
251
+ }
252
+ if (this.globe === null) {
253
+ console.warn("Globe is not initialized, cannot set opacity");
254
+ return;
255
+ }
256
+ opacityCheck(opacity);
257
+ this._userOpacity = opacity;
258
+ if (drawRender) {
259
+ this.globe.DrawRender();
260
+ }
261
+ }
262
+
263
+ setDefaultColor(color: Color): void {
264
+ if (this._freed) {
265
+ console.warn("Plugin is freed, cannot set default color");
266
+ return;
267
+ }
268
+ if (this.globe === null) {
269
+ console.warn("Globe is not initialized, cannot set default color");
270
+ return;
271
+ }
272
+ colorCheck(color);
273
+ this._options.defaultColor = color;
274
+ this._uboHandler?.updateSingle("u_color", new Float32Array(color));
275
+ this.globe.DrawRender();
276
+ }
277
+
278
+
279
+ setElevationMode(mode: "msl" | "agl"): void {
280
+ switch (mode) {
281
+ case "msl":
282
+ this._options.isMSL = true;
283
+ break;
284
+ case "agl":
285
+ this._options.isMSL = false;
286
+ break;
287
+ default:
288
+ throw new Error(`Unknown elevation mode: ${mode}`);
289
+ }
290
+ this._buildPaddings("elevation");
291
+ this.globe?.DrawRender();
292
+ }
293
+
294
+ init(globe: Globe, gl: WebGL2RenderingContext): void {
295
+ this.globe = globe;
296
+ this.lineProgram = LineStripProgramCache.get(globe);
297
+
298
+ this._frameCounterTrigger = new FrameCounterTrigger(globe, 10, 1000, (globeChanges: GlobeChanges) => {
299
+ if (this._freed) return;
300
+ this.__build(globeChanges);
301
+ globe.DrawRender();
302
+ });
303
+
304
+
305
+ this.__updateLODRelatedParameters()
306
+ this.__updateAdaptiveOpacityMultiplier();
307
+
308
+ const bufferManagerMap = new Map(
309
+ [
310
+ ["position2d", {
311
+ bufferManager: new BufferManager(globe.gl as WebGL2RenderingContext,
312
+ 360 * 2 * 3, // plus 1 to cut
313
+ { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
314
+ adaptor: (paddingInput: InnerPadding1DegreeInput) => {
315
+ if (this._float32Array === null) {
316
+ throw new Error("Float32Array is not initialized");
317
+ } else {
318
+ this._float32Array.fill(NaN); // reset the float32Array
319
+ }
320
+ for (let i = 0; i < 360; i++) {
321
+
322
+ const outerCoords = paddingInput.outerCoords[i] as LongLatDegree;
323
+ const innerCoords = paddingInput.innerCoords[i] as LongLatDegree;
324
+ if (outerCoords === null || innerCoords === null) {
325
+ continue;
326
+ }
327
+ let coordsOuter = globe.api_GetMercator2DPoint(outerCoords[0], outerCoords[1]);
328
+ // fill the second coordinate with 0
329
+ this._float32Array[i * 6] = coordsOuter[0];
330
+ this._float32Array[i * 6 + 1] = coordsOuter[1];
331
+
332
+ let coordsInner = globe.api_GetMercator2DPoint(innerCoords[0], innerCoords[1]);
333
+ // fill the second coordinate with 0
334
+ this._float32Array[i * 6 + 2] = coordsInner[0];
335
+ this._float32Array[i * 6 + 3] = coordsInner[1];
336
+ }
337
+ return this._float32Array.subarray(0, 360 * 2 * 3);
338
+ }
339
+ }
340
+ ],
341
+ [
342
+ "position3d", {
343
+ bufferManager: new BufferManager(globe.gl as WebGL2RenderingContext,
344
+ 360 * 3 * 3, // plus 1 to cut
345
+ { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
346
+ adaptor: (paddingInput: InnerPadding1DegreeInput) => {
347
+ if (this._float32Array === null) {
348
+ throw new Error("Float32Array is not initialized");
349
+ } else {
350
+ this._float32Array.fill(NaN); // reset the float32Array
351
+ }
352
+ const _float32Array = this._float32Array;
353
+ for (let i = 0; i < 360; i++) {
354
+
355
+
356
+ const outerCoords = paddingInput.outerCoords[i] as LongLatDegree;
357
+ const innerCoords = paddingInput.innerCoords[i] as LongLatDegree;
358
+ if (outerCoords === null || innerCoords === null) {
359
+ continue;
360
+ }
361
+ const height = paddingInput.heightFromGroundIn3D ?? this._options.defaultHeightFromGroundIn3D;
362
+
363
+ let coords = globe.api_GetCartesian3DPoint(outerCoords[0], outerCoords[1], height, this._options.isMSL);
364
+ // fill the second coordinate with 0
365
+ _float32Array[i * 9] = coords[0];
366
+ _float32Array[i * 9 + 1] = coords[1];
367
+ _float32Array[i * 9 + 2] = coords[2];
368
+
369
+
370
+ let coordsInner = globe.api_GetCartesian3DPoint(innerCoords[0], innerCoords[1], height, this._options.isMSL);
371
+ // fill the second coordinate with 0
372
+
373
+ _float32Array[i * 9 + 3] = coordsInner[0];
374
+ _float32Array[i * 9 + 4] = coordsInner[1];
375
+ _float32Array[i * 9 + 5] = coordsInner[2];
376
+
377
+ }
378
+ return _float32Array.subarray(0, 360 * 3 * 3);
379
+ }
380
+ }
381
+ ],
382
+ ]
383
+ );
384
+
385
+
386
+ if (this._options.variativeColorsOn) {
387
+ bufferManagerMap.set(
388
+ "color", {
389
+ bufferManager: new BufferManager(globe.gl as WebGL2RenderingContext,
390
+ 360 * 4 * 3, // 4 for RGBA
391
+ { bufferType: this._options.bufferType, initialCapacity: initialCapacity }),
392
+ adaptor: (paddingInput: Padding1DegreeInput) => {
393
+ if (this._float32Array === null) {
394
+ throw new Error("Float32Array is not initialized");
395
+ } else {
396
+ this._float32Array.fill(NaN); // reset the float32Array
397
+ }
398
+ if (!paddingInput.colorsRatios) {
399
+ const color = this._options.defaultColor;
400
+ const colorArray = new Float32Array(360 * 4 * 3);
401
+ this._float32Array = colorArray; // store for forwarding
402
+ for (let i = 0; i < 360; i++) {
403
+ this._float32Array[i * 12] = color[0];
404
+ this._float32Array[i * 12 + 1] = color[1];
405
+ this._float32Array[i * 12 + 2] = color[2];
406
+ this._float32Array[i * 12 + 3] = color[3];
407
+ this._float32Array[i * 12 + 4] = color[0];
408
+ this._float32Array[i * 12 + 5] = color[1];
409
+ this._float32Array[i * 12 + 6] = color[2];
410
+ this._float32Array[i * 12 + 7] = 0; //color[3] ;
411
+ }
412
+ return this._float32Array.subarray(0, 360 * 4 * 3);
413
+ } else {
414
+ const colorsRatios = paddingInput.colorsRatios;
415
+ let i = 0;
416
+ for (const colorRatio of colorsRatios) {
417
+ const color = colorRatio.color;
418
+ const ratio = colorRatio.ratio;
419
+ for (let j = 0; j < ratio; j++) {
420
+ this._float32Array[i * 12] = color[0];
421
+ this._float32Array[i * 12 + 1] = color[1];
422
+ this._float32Array[i * 12 + 2] = color[2];
423
+ this._float32Array[i * 12 + 3] = color[3];
424
+ this._float32Array[i * 12 + 4] = color[0];
425
+ this._float32Array[i * 12 + 5] = color[1];
426
+ this._float32Array[i * 12 + 6] = color[2];
427
+ this._float32Array[i * 12 + 7] = 0.1;// color[3];
428
+ i++;
429
+ }
430
+ }
431
+ return this._float32Array.subarray(0, 360 * 4 * 3);
432
+ }
433
+ }
434
+ }
435
+ );
436
+ }
437
+
438
+
439
+ const vaoInput = ["position3d", "position2d", "color"].map((name) => {
440
+ const bufferManager = bufferManagerMap.get(name);
441
+ if (!bufferManager) {
442
+ return null;
443
+ }
444
+ return {
445
+ buffer: bufferManager.bufferManager.buffer,
446
+ stride: 0,
447
+ offset: 0
448
+ }
449
+ })
450
+
451
+ this._vao = this.lineProgram.createVAO(
452
+ vaoInput[0],
453
+ vaoInput[1],
454
+ vaoInput[2],
455
+ );
456
+ this.bufferManagerMap = bufferManagerMap;
457
+ this.bufferOrchestrator.resetWithCapacity(bufferManagerMap, initialCapacity);
458
+ this._uboHandler = this.lineProgram.createUBO("STATIC_DRAW");
459
+ this._uboHandler.updateSingle("u_color", new Float32Array(this._options.defaultColor));
460
+ }
461
+
462
+
463
+ draw3D(): void {
464
+
465
+ if (this._freed) {
466
+ console.warn("Plugin is freed, cannot draw");
467
+ return;
468
+ }
469
+ if (this.globe === null || this.lineProgram === null || this._vao === null) {
470
+ console.warn("Globe or LineProgram or VAO is not initialized, cannot draw");
471
+ return;
472
+ }
473
+
474
+ this._frameCounterTrigger?.trigger();
475
+ // this.__build();
476
+
477
+ const gl = this.globe.gl as WebGL2RenderingContext;
478
+ const drawOptions: DrawRangeIndexParams = {
479
+ drawRange: {
480
+ first: 0,
481
+ count: this.bufferOrchestrator.length * (360 * 3), // plus 1 is for cutting linestrips
482
+ },
483
+ }
484
+ gl.disable(gl.DEPTH_TEST);
485
+
486
+ this.lineProgram.draw(
487
+ this._vao,
488
+ drawOptions,
489
+ this._userOpacity * this._adaptiveOpacityMultiplier,
490
+ this._uboHandler
491
+ );
492
+ gl.enable(gl.DEPTH_TEST);
493
+
494
+ }
495
+
496
+
497
+ free(): void {
498
+ if (this._freed) {
499
+ console.warn("Plugin is already freed");
500
+ return;
501
+ }
502
+ if (!this.globe || !this.lineProgram) {
503
+ console.warn("Globe or LineProgram is not initialized, cannot free the plugin");
504
+ return;
505
+ }
506
+ this._freed = true;
507
+ this._frameCounterTrigger?.free();
508
+ LineStripProgramCache.release(this.lineProgram);
509
+ this.lineProgram = null;
510
+ this._uboHandler?.free();
511
+ this._uboHandler = null;
512
+ this.globe.gl.deleteVertexArray(this._vao);
513
+ this.globe = null;
514
+ this._vao = null;
515
+ this.bufferManagerMap.forEach((bufferManager) => {
516
+ bufferManager.bufferManager.free();
517
+ });
518
+ this._float32Array = null;
519
+ }
520
+
521
+
522
+
523
+
524
+
525
+
526
+ _buildPaddings(level: "input" | "innerCircle" | "elevation" | "geometry", subSetIDs: string[] | null = null) {
527
+
528
+ if (level === "input") {
529
+ this.__inner(subSetIDs);
530
+ this.__elevation(subSetIDs);
531
+ } else if (level === "innerCircle") {
532
+ // Build inner circle paddings
533
+ if (this._options.adativePaddingSize) {
534
+ this.__innerCircle(subSetIDs);
535
+ }
536
+ this.__elevation(subSetIDs);
537
+ } else if (level === "elevation") {
538
+ // Build elevation paddings
539
+ this.__elevation(subSetIDs);
540
+ }
541
+ }
542
+
543
+ __inner(subSetIDs: string[] | null = null) {
544
+ // Implement inner circle padding logic
545
+
546
+ const datas = this._dataMap;
547
+
548
+ let keys;
549
+ if (subSetIDs) {
550
+ keys = subSetIDs;
551
+ } else {
552
+ keys = Array.from(datas.keys());
553
+ }
554
+ for (const key of keys) {
555
+ const value = datas.get(key);
556
+ if (!value) continue;
557
+
558
+ // Implement inner circle padding logic using key and value
559
+ const { innerCoords, outerCoords } = preAdapter(
560
+ this.globe!,
561
+ value,
562
+ this._innerPaddingRatio,
563
+ null
564
+ )
565
+ value.outerCoords = outerCoords;
566
+ value.innerCoords = innerCoords;
567
+ }
568
+ }
569
+
570
+ __innerCircle(subSetIDs: string[] | null = null) {
571
+ // Implement inner circle padding logic
572
+
573
+ const datas = this._dataMap;
574
+
575
+ let keys;
576
+ if (subSetIDs) {
577
+ keys = subSetIDs;
578
+ } else {
579
+ keys = Array.from(datas.keys());
580
+ }
581
+ for (const key of keys) {
582
+ const value = datas.get(key);
583
+ if (!value) continue;
584
+
585
+ // Implement inner circle padding logic using key and value
586
+ const { innerCoords } = preAdapter(
587
+ this.globe!,
588
+ value,
589
+ this._innerPaddingRatio,
590
+ value.outerCoords
591
+ )
592
+ value.innerCoords = innerCoords;
593
+ }
594
+ }
595
+
596
+
597
+ __elevation(subSetIDs: string[] | null = null) {
598
+ this.__updateAdaptiveOpacityMultiplier();
599
+ const bufferToUpdate = [this.globe?.api_GetCurrentGeometry() === 1 ? "position2d" : "position3d"];
600
+ const datas = this._dataMap;
601
+ const wrapper: [InnerPadding1DegreeInput] = [null!];
602
+ this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
603
+
604
+ let keys;
605
+ if (subSetIDs) {
606
+ keys = subSetIDs;
607
+ } else {
608
+ keys = Array.from(datas.keys());
609
+ }
610
+
611
+ for (const key of keys) {
612
+ const value = datas.get(key);
613
+ if (!value) continue;
614
+ wrapper[0] = value
615
+ this.bufferOrchestrator.updateBulk(
616
+ wrapper,
617
+ this.bufferManagerMap,
618
+ bufferToUpdate
619
+ );
620
+ }
621
+ this._float32Array = null; // reset the float32Array
622
+ }
623
+
624
+
625
+
626
+ __build(globeChanges: GlobeChanges) {
627
+ if (globeChanges.lod) {
628
+ this.__updateLODRelatedParameters();
629
+ this._buildPaddings("innerCircle");
630
+ } else if (globeChanges.look || globeChanges.geometry) {
631
+ this._buildPaddings("elevation");
632
+ }
633
+
634
+ }
635
+ __updateLODRelatedParameters(): void {
636
+ const lod = this.globe?.api_GetCurrentLODWithDecimal() as number;
637
+ this._innerPaddingRatio = 1 - Math.pow(0.7, lod);
638
+ }
639
+
640
+ __updateAdaptiveOpacityMultiplier() {
641
+ if (this._options.adaptiveOpacity === true) {
642
+ const currentLod = this.globe?.api_GetCurrentLODWithDecimal() as number;
643
+ this._adaptiveOpacityMultiplier = Math.max(1 - (2.9 / currentLod), 0.1)
644
+ } else {
645
+ this._adaptiveOpacityMultiplier = 1; // TODO: set this once on adaptiveOpacity is Set to false
646
+ }
647
+ }
648
+
649
+ }
650
+
651
+
652
+
653
+ function preAdapter<T extends LongLatDegree | null>(
654
+ globe: Globe,
655
+ paddingInput: Padding1DegreeInput,
656
+ paddingRatio: number,
657
+ outerCoords: T[] | null,
658
+ ): { outerCoords: T[], innerCoords: T[] } {
659
+
660
+ const innerCoords: T[] = new Array<T>(360);
661
+
662
+ if (outerCoords === null) {
663
+ outerCoords = new Array<T>(360);
664
+
665
+ for (let i = 0; i < 360; i++) {
666
+ const { long, lat } = globe.Math.FindPointByPolar(
667
+ paddingInput.center[0], // center long
668
+ paddingInput.center[1], // center lat
669
+ paddingInput.radius, // outer radius
670
+ i, // angle
671
+ );
672
+
673
+ const { long: endLong, lat: endLat } = globe.Math.FindPointByPolar(
674
+ paddingInput.center[0], // center long
675
+ paddingInput.center[1], // center lat
676
+ paddingInput.radius * paddingRatio, // inner radius
677
+ i, // angle
678
+ );
679
+
680
+ const longDifference = Math.abs(long - endLong);
681
+ // const latDifference = Math.abs(lat - endLat);
682
+
683
+ if (longDifference > 45) {
684
+ outerCoords[i] = null as T;
685
+ innerCoords[i] = null as T;
686
+ continue;
687
+ }
688
+
689
+ // Assign the calculated coordinates
690
+ outerCoords[i] = [long, lat] as T;
691
+ innerCoords[i] = [endLong, endLat] as T;
692
+ }
693
+ } else {
694
+ // Handle case when outerCoords is provided
695
+ for (let i = 0; i < 360; i++) {
696
+ if (outerCoords[i] === null) {
697
+ innerCoords[i] = null as T;
698
+ continue;
699
+ }
700
+
701
+ const { long: endLong, lat: endLat } = globe.Math.FindPointByPolar(
702
+ paddingInput.center[0],
703
+ paddingInput.center[1],
704
+ paddingInput.radius * paddingRatio,
705
+ i
706
+ );
707
+
708
+ innerCoords[i] = [endLong, endLat] as T;
709
+ }
710
+ }
711
+
712
+ return { outerCoords, innerCoords };
713
+ }