@pirireis/webglobeplugins 1.0.2 → 1.0.3

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 (259) hide show
  1. package/Math/{angle-calculation.ts → angle-calculation.js} +14 -18
  2. package/Math/{arc-cdf-points.ts → arc-cdf-points.js} +272 -329
  3. package/Math/{arc-generate-points-exponantial.ts → arc-generate-points-exponantial.js} +254 -299
  4. package/Math/{arc.ts → arc.js} +292 -421
  5. package/Math/bounds/line-bbox.js +186 -225
  6. package/Math/{circle-cdf-points.ts → circle-cdf-points.js} +78 -143
  7. package/Math/{circle.ts → circle.js} +33 -49
  8. package/Math/{constants.ts → constants.js} +4 -12
  9. package/Math/contour/{quadtreecontours.ts → quadtreecontours.js} +300 -371
  10. package/Math/contour/quadtreecontours1.js +298 -336
  11. package/Math/{finite-line-2d.ts → finite-line-2d.js} +58 -68
  12. package/Math/{haversine.ts → haversine.js} +22 -33
  13. package/Math/index.js +1 -0
  14. package/Math/juction/{arc-plane.ts → arc-plane.js} +143 -203
  15. package/Math/juction/{line-sphere.ts → line-sphere.js} +22 -32
  16. package/Math/juction/{plane-plane.ts → plane-plane.js} +53 -62
  17. package/Math/{line.ts → line.js} +52 -84
  18. package/Math/matrix4.js +1 -0
  19. package/Math/{methods.ts → methods.js} +126 -182
  20. package/Math/{plane.ts → plane.js} +56 -92
  21. package/Math/{quaternion.ts → quaternion.js} +106 -128
  22. package/Math/templete-shapes/{grid-visually-equal.ts → grid-visually-equal.js} +65 -118
  23. package/Math/tessellation/constants.js +1 -0
  24. package/Math/tessellation/{methods.ts → methods.js} +49 -79
  25. package/Math/tessellation/{nearest-value-padding.ts → nearest-value-padding.js} +112 -147
  26. package/Math/tessellation/{spherical-triangle-area.ts → spherical-triangle-area.js} +99 -127
  27. package/Math/tessellation/{tile-merger.ts → tile-merger.js} +429 -578
  28. package/Math/tessellation/{triangle-tessellation.ts → triangle-tessellation.js} +386 -533
  29. package/Math/tessellation/types.js +1 -0
  30. package/Math/types.js +1 -0
  31. package/Math/utils.js +2 -3
  32. package/Math/{vec3.ts → vec3.js} +155 -227
  33. package/Math/{xyz-tile.ts → xyz-tile.js} +18 -26
  34. package/algorithms/search-binary.js +16 -14
  35. package/altitude-locator/adaptors.js +1 -0
  36. package/altitude-locator/keymethod.js +1 -0
  37. package/altitude-locator/plugin.js +344 -445
  38. package/altitude-locator/types.js +21 -26
  39. package/compass-rose/compass-rose-padding-flat.js +230 -274
  40. package/compass-rose/{compass-text-writer.ts → compass-text-writer.js} +155 -210
  41. package/compass-rose/index.js +3 -3
  42. package/{constants.ts → constants.js} +6 -8
  43. package/heatwave/datamanager.js +149 -168
  44. package/heatwave/heatwave.js +206 -261
  45. package/heatwave/index.js +5 -5
  46. package/heatwave/isobar.js +303 -340
  47. package/heatwave/{texture-point-sampler.ts → texture-point-sampler.js} +187 -220
  48. package/investigation-tools/draw/tiles/adapters.js +67 -0
  49. package/investigation-tools/draw/tiles/{tiles.ts → tiles.js} +128 -162
  50. package/jest.config.js +7 -6
  51. package/package.json +1 -1
  52. package/pin/pin-object-array1.js +300 -381
  53. package/pin/pin-point-totem1.js +60 -77
  54. package/programs/arrowfield/arrow-field.js +60 -89
  55. package/programs/arrowfield/logic.js +141 -173
  56. package/programs/data2legend/density-to-legend.js +68 -86
  57. package/programs/data2legend/point-to-density-texture.js +67 -84
  58. package/programs/float2legendwithratio/index.js +2 -3
  59. package/programs/float2legendwithratio/logic.js +118 -144
  60. package/programs/float2legendwithratio/object.js +104 -141
  61. package/programs/helpers/blender.js +58 -73
  62. package/programs/helpers/{fadeaway.ts → fadeaway.js} +60 -73
  63. package/programs/index.js +20 -19
  64. package/programs/line-on-globe/circle-accurate-3d.js +85 -112
  65. package/programs/line-on-globe/circle-accurate-flat.js +148 -200
  66. package/programs/line-on-globe/degree-padding-around-circle-3d.js +102 -134
  67. package/programs/line-on-globe/index.js +1 -0
  68. package/programs/line-on-globe/lines-color-instanced-flat.js +80 -99
  69. package/programs/line-on-globe/linestrip/data.js +4 -0
  70. package/programs/line-on-globe/linestrip/{linestrip.ts → linestrip.js} +93 -152
  71. package/programs/line-on-globe/{naive-accurate-flexible.ts → naive-accurate-flexible.js} +126 -175
  72. package/programs/line-on-globe/util.js +5 -8
  73. package/programs/picking/pickable-polygon-renderer.js +98 -129
  74. package/programs/picking/pickable-renderer.js +98 -130
  75. package/programs/point-on-globe/element-globe-surface-glow.js +93 -122
  76. package/programs/point-on-globe/element-point-glow.js +80 -114
  77. package/programs/point-on-globe/square-pixel-point.js +121 -139
  78. package/programs/polygon-on-globe/{texture-dem-triangles.ts → texture-dem-triangles.js} +163 -207
  79. package/programs/{programcache.ts → programcache.js} +126 -134
  80. package/programs/rings/index.js +1 -1
  81. package/programs/rings/partial-ring/{piece-of-pie.ts → piece-of-pie.js} +152 -222
  82. package/programs/totems/camera-totem-attactment-interface.js +1 -0
  83. package/programs/totems/{camerauniformblock.ts → camerauniformblock.js} +225 -310
  84. package/programs/totems/{canvas-webglobe-info.ts → canvas-webglobe-info.js} +132 -147
  85. package/programs/totems/{dem-textures-manager.ts → dem-textures-manager.js} +257 -360
  86. package/programs/totems/{globe-changes.ts → globe-changes.js} +59 -79
  87. package/programs/totems/gpu-selection-uniform-block.js +99 -127
  88. package/programs/totems/{index.ts → index.js} +2 -2
  89. package/programs/two-d/pixel-padding-for-compass.js +87 -101
  90. package/programs/util.js +14 -19
  91. package/programs/vectorfields/logics/{constants.ts → constants.js} +4 -5
  92. package/programs/vectorfields/logics/{drawrectangleparticles.ts → drawrectangleparticles.js} +80 -115
  93. package/programs/vectorfields/logics/index.js +2 -4
  94. package/programs/vectorfields/logics/particle-ubo.js +16 -0
  95. package/programs/vectorfields/logics/{pixelbased.ts → pixelbased.js} +86 -115
  96. package/programs/vectorfields/logics/ubo.js +51 -57
  97. package/programs/vectorfields/{pingpongbuffermanager.ts → pingpongbuffermanager.js} +99 -113
  98. package/range-tools-on-terrain/bearing-line/{adapters.ts → adapters.js} +114 -154
  99. package/range-tools-on-terrain/bearing-line/{plugin.ts → plugin.js} +457 -569
  100. package/range-tools-on-terrain/bearing-line/types.js +1 -0
  101. package/range-tools-on-terrain/circle-line-chain/{adapters.ts → adapters.js} +85 -104
  102. package/range-tools-on-terrain/circle-line-chain/{chain-list-map.ts → chain-list-map.js} +382 -446
  103. package/range-tools-on-terrain/circle-line-chain/{plugin.ts → plugin.js} +464 -607
  104. package/range-tools-on-terrain/circle-line-chain/types.js +1 -0
  105. package/range-tools-on-terrain/range-ring/{adapters.ts → adapters.js} +93 -114
  106. package/range-tools-on-terrain/range-ring/{enum.ts → enum.js} +2 -2
  107. package/range-tools-on-terrain/range-ring/{plugin.ts → plugin.js} +377 -444
  108. package/range-tools-on-terrain/range-ring/rangeringangletext.js +331 -0
  109. package/range-tools-on-terrain/range-ring/types.js +9 -0
  110. package/semiplugins/interface.js +1 -0
  111. package/semiplugins/lightweight/{line-plugin.ts → line-plugin.js} +221 -342
  112. package/semiplugins/lightweight/{piece-of-pie-plugin.ts → piece-of-pie-plugin.js} +200 -275
  113. package/semiplugins/shape-on-terrain/{arc-plugin.ts → arc-plugin.js} +481 -616
  114. package/semiplugins/shape-on-terrain/{circle-plugin.ts → circle-plugin.js} +444 -588
  115. package/semiplugins/shape-on-terrain/{padding-1-degree.ts → padding-1-degree.js} +539 -713
  116. package/semiplugins/shape-on-terrain/terrain-polygon/{adapters.ts → adapters.js} +55 -69
  117. package/semiplugins/shape-on-terrain/terrain-polygon/data/{cache.ts → cache.js} +102 -149
  118. package/semiplugins/shape-on-terrain/terrain-polygon/data/{index-polygon-map.ts → index-polygon-map.js} +45 -58
  119. package/semiplugins/shape-on-terrain/terrain-polygon/data/{manager.ts → manager.js} +4 -4
  120. package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.js +177 -196
  121. package/semiplugins/shape-on-terrain/terrain-polygon/data/{polygon-to-triangles.ts → polygon-to-triangles.js} +100 -144
  122. package/semiplugins/shape-on-terrain/terrain-polygon/data/{random.ts → random.js} +121 -165
  123. package/semiplugins/shape-on-terrain/terrain-polygon/data/types.js +1 -0
  124. package/semiplugins/shape-on-terrain/terrain-polygon/data/{worker-contact.ts → worker-contact.js} +63 -81
  125. package/semiplugins/shape-on-terrain/terrain-polygon/data/worker.js +125 -146
  126. package/semiplugins/shape-on-terrain/terrain-polygon/{terrain-polygon.ts → terrain-polygon.js} +219 -265
  127. package/semiplugins/shape-on-terrain/terrain-polygon/types.js +8 -0
  128. package/semiplugins/shell/bbox-renderer/index.js +2 -0
  129. package/semiplugins/shell/bbox-renderer/{logic.ts → logic.js} +209 -273
  130. package/semiplugins/shell/bbox-renderer/object.js +75 -0
  131. package/semiplugins/type.js +1 -0
  132. package/semiplugins/utility/{container-plugin.ts → container-plugin.js} +94 -126
  133. package/semiplugins/utility/{object-pass-container-plugin.ts → object-pass-container-plugin.js} +80 -101
  134. package/shaders/fragment-toy/firework.js +1 -1
  135. package/shaders/fragment-toy/singularity.js +2 -5
  136. package/tracks/point-heat-map/adaptors/timetracksplugin-format-to-this.js +63 -78
  137. package/tracks/point-heat-map/index.js +1 -0
  138. package/tracks/point-heat-map/plugin-webworker.js +121 -148
  139. package/tracks/point-heat-map/point-to-heat-map-flow.js +121 -150
  140. package/tracks/point-tracks/key-methods.js +2 -3
  141. package/tracks/point-tracks/plugin.js +401 -487
  142. package/tracks/timetracks/adaptors-line-strip.js +65 -79
  143. package/tracks/timetracks/plugin-line-strip.js +240 -295
  144. package/tracks/timetracks/program-line-strip.js +411 -495
  145. package/tracks/timetracks/programpoint-line-strip.js +109 -137
  146. package/types.js +19 -0
  147. package/util/account/bufferoffsetmanager.js +176 -209
  148. package/util/account/create-buffermap-orchastration.js +39 -0
  149. package/util/account/index.js +3 -6
  150. package/util/account/single-attribute-buffer-management/{buffer-manager.ts → buffer-manager.js} +119 -151
  151. package/util/account/single-attribute-buffer-management/{buffer-orchestrator.ts → buffer-orchestrator.js} +212 -238
  152. package/util/account/single-attribute-buffer-management/{buffer-orchestrator1.ts → buffer-orchestrator1.js} +159 -184
  153. package/util/account/single-attribute-buffer-management/{index.ts → index.js} +4 -11
  154. package/util/account/single-attribute-buffer-management/{object-store.ts → object-store.js} +55 -76
  155. package/util/account/single-attribute-buffer-management/types.js +1 -0
  156. package/util/account/util.js +18 -22
  157. package/util/algorithms/index.js +1 -0
  158. package/util/algorithms/search-binary.js +25 -26
  159. package/util/build-strategy/{static-dynamic.ts → static-dynamic.js} +41 -50
  160. package/util/check/index.js +1 -0
  161. package/util/check/typecheck.js +66 -0
  162. package/util/{frame-counter-trigger.ts → frame-counter-trigger.js} +84 -99
  163. package/util/geometry/{index.ts → index.js} +121 -155
  164. package/util/gl-util/buffer/{attribute-loader.ts → attribute-loader.js} +62 -84
  165. package/util/gl-util/buffer/{index.ts → index.js} +3 -6
  166. package/util/gl-util/draw-options/{methods.ts → methods.js} +32 -47
  167. package/util/gl-util/uniform-block/{manager.ts → manager.js} +200 -232
  168. package/util/{globe-default-gl-states.ts → globe-default-gl-states.js} +4 -5
  169. package/util/{helper-methods.ts → helper-methods.js} +8 -9
  170. package/util/index.js +10 -9
  171. package/util/interpolation/index.js +1 -0
  172. package/util/interpolation/timetrack/index.js +2 -9
  173. package/util/interpolation/timetrack/timetrack-interpolator.js +79 -94
  174. package/util/interpolation/timetrack/web-worker.js +46 -51
  175. package/util/picking/{fence.ts → fence.js} +43 -47
  176. package/util/picking/{picker-displayer.ts → picker-displayer.js} +176 -226
  177. package/util/programs/draw-from-pixel-coords.js +164 -201
  178. package/util/programs/{draw-texture-on-canvas.ts → draw-texture-on-canvas.js} +69 -91
  179. package/util/programs/supersampletotextures.js +97 -130
  180. package/util/programs/texturetoglobe.js +128 -153
  181. package/util/shaderfunctions/{geometrytransformations.ts → geometrytransformations.js} +44 -106
  182. package/util/shaderfunctions/index.js +2 -2
  183. package/util/shaderfunctions/nodata.js +2 -4
  184. package/util/shaderfunctions/noisefunctions.js +7 -10
  185. package/util/{webglobjectbuilders.ts → webglobjectbuilders.js} +358 -446
  186. package/vectorfield/arrowfield/adaptor.js +11 -11
  187. package/vectorfield/arrowfield/index.js +3 -3
  188. package/vectorfield/arrowfield/plugin.js +83 -128
  189. package/vectorfield/waveparticles/adaptor.js +15 -16
  190. package/vectorfield/waveparticles/index.js +3 -3
  191. package/vectorfield/waveparticles/{plugin.ts → plugin.js} +415 -506
  192. package/vectorfield/wind/adapters/{image-to-fields.ts → image-to-fields.js} +61 -74
  193. package/vectorfield/wind/adapters/types.js +1 -0
  194. package/vectorfield/wind/{imagetovectorfieldandmagnitude.ts → imagetovectorfieldandmagnitude.js} +53 -78
  195. package/vectorfield/wind/index.js +5 -5
  196. package/vectorfield/wind/{plugin-persistant copy.ts → plugin-persistant copy.js } +364 -461
  197. package/vectorfield/wind/{plugin-persistant.ts → plugin-persistant.js} +375 -483
  198. package/vectorfield/wind/plugin.js +685 -883
  199. package/vectorfield/wind/vectorfieldimage.js +23 -27
  200. package/write-text/{context-text-bulk.ts → context-text-bulk.js} +200 -285
  201. package/write-text/context-text3.js +167 -0
  202. package/write-text/{context-text4.ts → context-text4.js} +146 -231
  203. package/write-text/context-textDELETE.js +94 -125
  204. package/write-text/objectarraylabels/{index.ts → index.js} +2 -2
  205. package/write-text/objectarraylabels/objectarraylabels.js +200 -247
  206. package/Math/matrix4.ts +0 -0
  207. package/Math/mesh/mapbox-delaunay.d.ts +0 -74
  208. package/Math/roadmap.md +0 -10
  209. package/Math/tessellation/constants.ts +0 -1
  210. package/Math/tessellation/roadmap.md +0 -48
  211. package/Math/tessellation/types.ts +0 -1
  212. package/Math/types.ts +0 -68
  213. package/investigation-tools/draw/tiles/adapters.ts +0 -133
  214. package/programs/line-on-globe/linestrip/data.ts +0 -29
  215. package/programs/polygon-on-globe/roadmap.md +0 -8
  216. package/programs/totems/camera-totem-attactment-interface.ts +0 -4
  217. package/programs/vectorfields/logics/particle-ubo.ts +0 -23
  218. package/publish.bat +0 -62
  219. package/range-tools-on-terrain/bearing-line/types.ts +0 -65
  220. package/range-tools-on-terrain/circle-line-chain/types.ts +0 -43
  221. package/range-tools-on-terrain/range-ring/rangeringangletext.ts +0 -396
  222. package/range-tools-on-terrain/range-ring/types.ts +0 -30
  223. package/semiplugins/interface.ts +0 -14
  224. package/semiplugins/shape-on-terrain/goal.md +0 -12
  225. package/semiplugins/shape-on-terrain/terrain-polygon/data/cache-shortcuts.md +0 -20
  226. package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.ts +0 -209
  227. package/semiplugins/shape-on-terrain/terrain-polygon/data/readme.md +0 -5
  228. package/semiplugins/shape-on-terrain/terrain-polygon/data/types.ts +0 -37
  229. package/semiplugins/shape-on-terrain/terrain-polygon/notes.md +0 -90
  230. package/semiplugins/shape-on-terrain/terrain-polygon/types.ts +0 -69
  231. package/semiplugins/shell/bbox-renderer/index.ts +0 -2
  232. package/semiplugins/shell/bbox-renderer/object.ts +0 -129
  233. package/semiplugins/type.ts +0 -8
  234. package/terrain-plugin.mmd +0 -83
  235. package/tests/Math/arc-sampling-test.js +0 -367
  236. package/tests/Math/arc-sampling-test.ts +0 -429
  237. package/tests/Math/arc.test.ts +0 -77
  238. package/tests/Math/junction/arc-limit.test.ts +0 -7
  239. package/tests/Math/junction/arc-plane-points.test.ts +0 -196
  240. package/tests/Math/junction/arc-plane.test.ts +0 -172
  241. package/tests/Math/junction/line-sphere.test.ts +0 -127
  242. package/tests/Math/junction/plane-plane.test.ts +0 -91
  243. package/tests/Math/plane-test.ts +0 -17
  244. package/tests/Math/plane.test.ts +0 -43
  245. package/tests/Math/vec3.test.ts +0 -33
  246. package/tracks/point-heat-map/readme.md +0 -15
  247. package/tracks/timetracks/readme.md +0 -1
  248. package/tsconfig.json +0 -22
  249. package/types/@pirireis/webglobe.d.ts +0 -102
  250. package/types/delaunator.d.ts +0 -40
  251. package/types/earcut.d.ts +0 -11
  252. package/types/rbush.d.ts +0 -57
  253. package/types.ts +0 -319
  254. package/util/account/create-buffermap-orchastration.ts +0 -85
  255. package/util/account/single-attribute-buffer-management/types.ts +0 -43
  256. package/util/check/typecheck.ts +0 -74
  257. package/vectorfield/wind/adapters/types.ts +0 -12
  258. package/write-text/context-text3.ts +0 -252
  259. package/write-text/objectarraylabels/objectarraylabels.d.ts +0 -72
@@ -1,713 +1,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
- }
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
+ }