@pirireis/webglobeplugins 0.9.7 → 0.9.8

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 (212) hide show
  1. package/dist/Math/angle-calculation.js +15 -0
  2. package/dist/Math/arc.js +65 -0
  3. package/dist/Math/bounds/line-bbox.js +188 -0
  4. package/dist/Math/constants.js +9 -0
  5. package/dist/Math/frustum/camera.js +24 -0
  6. package/dist/Math/frustum/from-globeinfo.js +48 -0
  7. package/dist/Math/frustum/types.js +2 -0
  8. package/dist/Math/globe-util/horizon-plane.js +112 -0
  9. package/dist/Math/index.js +1 -0
  10. package/dist/Math/juction/arc-plane.js +83 -0
  11. package/dist/Math/juction/line-sphere.js +25 -0
  12. package/dist/Math/juction/plane-plane.js +58 -0
  13. package/dist/Math/line.js +56 -0
  14. package/dist/Math/matrix4.js +1 -0
  15. package/dist/Math/methods.js +201 -0
  16. package/dist/Math/plane.js +60 -0
  17. package/dist/Math/quaternion.js +104 -0
  18. package/dist/Math/types.js +2 -0
  19. package/dist/Math/utils.js +4 -0
  20. package/dist/Math/vec3.js +126 -0
  21. package/dist/algorithms/search-binary.js +19 -0
  22. package/dist/altitude-locator/adaptors.js +1 -0
  23. package/dist/altitude-locator/draw-subset-obj.js +18 -0
  24. package/dist/altitude-locator/keymethod.js +1 -0
  25. package/dist/altitude-locator/plugin.js +341 -0
  26. package/dist/altitude-locator/types.js +23 -0
  27. package/dist/arrowfield/adaptor.js +14 -0
  28. package/dist/arrowfield/index.js +10 -0
  29. package/dist/arrowfield/plugin.js +86 -0
  30. package/dist/bearing-line/index.js +8 -0
  31. package/dist/bearing-line/plugin.js +449 -0
  32. package/dist/circle-line-chain/chain-list-map.js +205 -0
  33. package/dist/circle-line-chain/init.js +1 -0
  34. package/dist/circle-line-chain/plugin.js +424 -0
  35. package/dist/circle-line-chain/util.js +5 -0
  36. package/dist/compass-rose/compass-rose-padding-flat.js +225 -0
  37. package/dist/compass-rose/compass-text-writer.js +153 -0
  38. package/dist/compass-rose/index.js +7 -0
  39. package/dist/compassrose/compassrose.js +296 -0
  40. package/dist/compassrose/index.js +8 -0
  41. package/dist/globe-types.js +1 -0
  42. package/dist/heatwave/index.js +10 -0
  43. package/dist/heatwave/isobar/objectarraylabels.js +202 -0
  44. package/dist/heatwave/isobar/plugin.js +343 -0
  45. package/dist/heatwave/isobar/quadtreecontours.js +300 -0
  46. package/dist/heatwave/plugins/heatwaveglobeshell.js +206 -0
  47. package/dist/index.js +58 -0
  48. package/dist/jest.config.js +7 -0
  49. package/dist/partialrings/buffer-manager.js +81 -0
  50. package/dist/partialrings/index.js +41 -0
  51. package/dist/partialrings/plugin.js +135 -0
  52. package/dist/partialrings/program.js +286 -0
  53. package/dist/pin/pin-object-array.js +305 -0
  54. package/dist/pin/pin-point-totem.js +60 -0
  55. package/dist/point-heat-map/adaptors/timetracksplugin-format-to-this.js +66 -0
  56. package/dist/point-heat-map/index.js +1 -0
  57. package/dist/point-heat-map/plugin-webworker.js +126 -0
  58. package/dist/point-heat-map/point-to-heat-map-flow.js +127 -0
  59. package/dist/point-tracks/key-methods.js +5 -0
  60. package/dist/point-tracks/plugin.js +338 -0
  61. package/dist/programs/arrowfield/index.js +7 -0
  62. package/dist/programs/arrowfield/logic.js +257 -0
  63. package/dist/programs/arrowfield/object.js +66 -0
  64. package/dist/programs/data2legend/density-to-legend.js +101 -0
  65. package/dist/programs/data2legend/point-to-density-texture.js +100 -0
  66. package/dist/programs/float2legendwithratio/index.js +8 -0
  67. package/dist/programs/float2legendwithratio/logic.js +171 -0
  68. package/dist/programs/float2legendwithratio/object.js +110 -0
  69. package/dist/programs/globe-util/is-globe-moved.js +21 -0
  70. package/dist/programs/globeshell/index.js +8 -0
  71. package/dist/programs/globeshell/noise/noises.js +1 -0
  72. package/dist/programs/globeshell/wiggle/index.js +8 -0
  73. package/dist/programs/globeshell/wiggle/logic.js +345 -0
  74. package/dist/programs/globeshell/wiggle/object.js +72 -0
  75. package/dist/programs/helpers/blender/index.js +1 -0
  76. package/dist/programs/helpers/blender/program.js +79 -0
  77. package/dist/programs/helpers/fadeaway/index.js +7 -0
  78. package/dist/programs/helpers/fadeaway/logic.js +72 -0
  79. package/dist/programs/helpers/fadeaway/object.js +20 -0
  80. package/dist/programs/helpers/index.js +8 -0
  81. package/dist/programs/index.js +58 -0
  82. package/dist/programs/interface.js +1 -0
  83. package/dist/programs/line-on-globe/angled-line.js +176 -0
  84. package/dist/programs/line-on-globe/circle-accurate-3d.js +141 -0
  85. package/dist/programs/line-on-globe/circle-accurate-flat.js +216 -0
  86. package/dist/programs/line-on-globe/circle-accurate.js +178 -0
  87. package/dist/programs/line-on-globe/circle.js +167 -0
  88. package/dist/programs/line-on-globe/degree-padding-around-circle-3d.js +159 -0
  89. package/dist/programs/line-on-globe/index.js +1 -0
  90. package/dist/programs/line-on-globe/lines-color-instanced-flat.js +136 -0
  91. package/dist/programs/line-on-globe/linestrip.js +171 -0
  92. package/dist/programs/line-on-globe/naive-accurate-flexible.js +195 -0
  93. package/dist/programs/line-on-globe/to-the-surface.js +111 -0
  94. package/dist/programs/line-on-globe/util.js +8 -0
  95. package/dist/programs/picking/pickable-renderer.js +188 -0
  96. package/dist/programs/point-on-globe/element-globe-surface-glow.js +142 -0
  97. package/dist/programs/point-on-globe/element-point-glow.js +153 -0
  98. package/dist/programs/point-on-globe/square-pixel-point.js +174 -0
  99. package/dist/programs/programcache.js +131 -0
  100. package/dist/programs/rings/distancering/circleflatprogram.js +156 -0
  101. package/dist/programs/rings/distancering/circlepaddingfreeangleprogram.js +369 -0
  102. package/dist/programs/rings/distancering/circlepaddysharedbuffer.js +357 -0
  103. package/dist/programs/rings/distancering/index.js +14 -0
  104. package/dist/programs/rings/distancering/paddyflatprogram.js +172 -0
  105. package/dist/programs/rings/distancering/paddyflatprogram2d.js +174 -0
  106. package/dist/programs/rings/distancering/paddyflatprogram3d.js +172 -0
  107. package/dist/programs/rings/distancering/shader.js +1 -0
  108. package/dist/programs/rings/index.js +17 -0
  109. package/dist/programs/rings/partial-ring/piece-of-pie.js +275 -0
  110. package/dist/programs/totems/camerauniformblock.js +160 -0
  111. package/dist/programs/totems/canvas-webglobe-info.js +110 -0
  112. package/dist/programs/totems/gpu-selection-uniform-block.js +108 -0
  113. package/dist/programs/totems/index.js +40 -0
  114. package/dist/programs/two-d/pixel-circle.js +1 -0
  115. package/dist/programs/two-d/pixel-padding-for-compass.js +162 -0
  116. package/dist/programs/util.js +17 -0
  117. package/dist/programs/vectorfields/index.js +23 -0
  118. package/dist/programs/vectorfields/logics/drawrectangleparticles.js +107 -0
  119. package/dist/programs/vectorfields/logics/index.js +12 -0
  120. package/dist/programs/vectorfields/logics/pixelbased.js +142 -0
  121. package/dist/programs/vectorfields/logics/ubo.js +63 -0
  122. package/dist/programs/vectorfields/pingpongbuffermanager.js +76 -0
  123. package/dist/rangerings/enum.js +5 -0
  124. package/dist/rangerings/index.js +15 -0
  125. package/dist/rangerings/plugin.js +560 -0
  126. package/dist/rangerings/rangeringangletext.js +329 -0
  127. package/dist/rangerings/ring-account.js +117 -0
  128. package/dist/shaders/fragment-toy/firework.js +58 -0
  129. package/dist/shaders/fragment-toy/singularity.js +59 -0
  130. package/dist/shape-on-terrain/arc/naive/plugin.js +252 -0
  131. package/dist/timetracks/adaptors-line-strip.js +71 -0
  132. package/dist/timetracks/adaptors.js +122 -0
  133. package/dist/timetracks/index.js +19 -0
  134. package/dist/timetracks/plugin-line-strip.js +250 -0
  135. package/dist/timetracks/plugin.js +258 -0
  136. package/dist/timetracks/program-line-strip.js +611 -0
  137. package/dist/timetracks/program.js +772 -0
  138. package/dist/timetracks/programpoint-line-strip.js +154 -0
  139. package/dist/timetracks/programpoint.js +147 -0
  140. package/dist/types.js +15 -0
  141. package/dist/util/account/bufferoffsetmanager.js +179 -0
  142. package/dist/util/account/index.js +23 -0
  143. package/dist/util/account/single-attribute-buffer-management/buffer-manager.js +108 -0
  144. package/dist/util/account/single-attribute-buffer-management/buffer-orchestrator.js +150 -0
  145. package/dist/util/account/single-attribute-buffer-management/index.js +9 -0
  146. package/dist/util/account/single-attribute-buffer-management/object-store.js +51 -0
  147. package/dist/util/account/single-attribute-buffer-management/types.js +2 -0
  148. package/dist/util/account/util.js +22 -0
  149. package/dist/util/algorithms/index.js +1 -0
  150. package/dist/util/algorithms/search-binary.js +28 -0
  151. package/dist/util/check/get.js +18 -0
  152. package/dist/util/check/index.js +1 -0
  153. package/dist/util/check/typecheck.js +49 -0
  154. package/dist/util/geometry/index.js +51 -0
  155. package/dist/util/gl-util/buffer/attribute-loader.js +69 -0
  156. package/dist/util/gl-util/buffer/index.js +6 -0
  157. package/dist/util/gl-util/buffer/types.js +1 -0
  158. package/dist/util/gl-util/draw-options/methods.js +38 -0
  159. package/dist/util/gl-util/draw-options/types.js +15 -0
  160. package/dist/util/gl-util/uniform-block/manager.js +156 -0
  161. package/dist/util/gl-util/uniform-block/shader.js +1 -0
  162. package/dist/util/gl-util/uniform-block/types.js +8 -0
  163. package/dist/util/heatwavedatamanager/datamanager.js +152 -0
  164. package/dist/util/heatwavedatamanager/index.js +10 -0
  165. package/dist/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +122 -0
  166. package/dist/util/heatwavedatamanager/pointcoordsmeta.js +20 -0
  167. package/dist/util/index.js +57 -0
  168. package/dist/util/interpolation/index.js +1 -0
  169. package/dist/util/interpolation/timetrack/index.js +5 -0
  170. package/dist/util/interpolation/timetrack/timetrack-interpolator.js +79 -0
  171. package/dist/util/interpolation/timetrack/web-worker-str.js +183 -0
  172. package/dist/util/interpolation/timetrack/web-worker.js +48 -0
  173. package/dist/util/jshelpers/data-filler.js +20 -0
  174. package/dist/util/jshelpers/equality.js +20 -0
  175. package/dist/util/jshelpers/index.js +37 -0
  176. package/dist/util/jshelpers/timefilters.js +32 -0
  177. package/dist/util/picking/fence.js +46 -0
  178. package/dist/util/picking/picker-displayer.js +139 -0
  179. package/dist/util/programs/draw-texture-on-canvas.js +89 -0
  180. package/dist/util/programs/index.js +17 -0
  181. package/dist/util/programs/shapesonglobe.js +214 -0
  182. package/dist/util/programs/supersampletotextures.js +113 -0
  183. package/dist/util/programs/texturetoglobe.js +182 -0
  184. package/dist/util/shaderfunctions/geometrytransformations.js +340 -0
  185. package/dist/util/shaderfunctions/index.js +18 -0
  186. package/dist/util/shaderfunctions/nodata.js +11 -0
  187. package/dist/util/shaderfunctions/noisefunctions.js +43 -0
  188. package/dist/util/surface-line-data/arc-bboxes.js +25 -0
  189. package/dist/util/surface-line-data/arcs-to-cuts.js +50 -0
  190. package/dist/util/surface-line-data/cut-arc.js +1 -0
  191. package/dist/util/surface-line-data/flow.js +28 -0
  192. package/dist/util/surface-line-data/rbush-manager.js +1 -0
  193. package/dist/util/surface-line-data/types.js +1 -0
  194. package/dist/util/surface-line-data/web-worker.js +1 -0
  195. package/dist/util/webglobe/gldefaultstates.js +7 -0
  196. package/dist/util/webglobe/index.js +18 -0
  197. package/dist/util/webglobe/rasteroverlay.js +78 -0
  198. package/dist/util/webglobjectbuilders.js +388 -0
  199. package/dist/util/webglobjectbuilders1.js +237 -0
  200. package/dist/waveparticles/adaptor.js +17 -0
  201. package/dist/waveparticles/index.js +10 -0
  202. package/dist/waveparticles/plugin.js +266 -0
  203. package/dist/wind/imagetovectorfieldandmagnitude.js +35 -0
  204. package/dist/wind/index.js +14 -0
  205. package/dist/wind/plugin.js +926 -0
  206. package/dist/wind/vectorfieldimage.js +25 -0
  207. package/dist/write-text/attached-text-writer.js +91 -0
  208. package/dist/write-text/context-text.js +98 -0
  209. package/dist/write-text/context-text3.js +155 -0
  210. package/dist/write-text/index.js +5 -0
  211. package/dist/write-text/writer-plugin.js +8 -0
  212. package/package.json +1 -1
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function getVectorField(u, v, width, height, vMin, vMax, uMin, uMax, flip) {
4
+ const data = new Uint8ClampedArray(width * height * 4);
5
+ for (let row = 0; row < height; row++) {
6
+ for (let col = 0; col < width; col++) {
7
+ let k = flip ? ((height - row - 1) * width + col) : row * width + col;
8
+ let idx = (width * row + col) << 2; // Multiply by 4 for RGBA
9
+ if (u[k] === null || v[k] === null || isNaN(u[k]) || !isFinite(u[k]) || isNaN(v[k]) || !isFinite(v[k])) {
10
+ data[idx] = 0; // R
11
+ data[idx + 1] = 0; // G
12
+ data[idx + 2] = 0; // B
13
+ data[idx + 3] = 0; // A
14
+ }
15
+ else {
16
+ data[idx] = Math.floor(255 * (u[k] - uMin) / (uMax - uMin)); // R
17
+ data[idx + 1] = Math.floor(255 * (v[k] - vMin) / (vMax - vMin)); // G
18
+ data[idx + 2] = 0; // B
19
+ data[idx + 3] = 255; // A
20
+ }
21
+ }
22
+ }
23
+ return data;
24
+ }
25
+ exports.default = getVectorField;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttachedTextWriter = void 0;
4
+ const webglobe_1 = require("@pirireis/webglobe");
5
+ const typecheck_1 = require("../util/check/typecheck");
6
+ /**
7
+ * Light wight version of context text writer.
8
+ * The parameters by text are calculated on user side and inserted as items. (ContextTextWriter3 constructs text data from items)
9
+ *
10
+ * Good side of ContextTextWriters pattern is that there is only one way to create text.
11
+ * The glue is inside the plugin.
12
+ * This makes the code more readable and maintainable.
13
+ *
14
+ * With AttachedTextWriter the glue is created by user.
15
+ * I observed that the users generally uses a wrapper around the plugin logic anyway. This wrapper can be used as the glue for plugin and attacked writer.
16
+ */
17
+ class AttachedTextWriter {
18
+ constructor(globe, { style = {
19
+ textFont: {
20
+ name: 'Arial',
21
+ textColor: '#FFFFFF', // beyaz
22
+ hollowColor: '#000000', // siyah
23
+ size: 12, // piksel
24
+ hollow: true,
25
+ bold: true,
26
+ italic: false,
27
+ },
28
+ opacity: 1.0,
29
+ zMode: webglobe_1.CSZMode.Z_GROUND_PERVERTEX,
30
+ }, doDraw = true, angleOnSphere = false, zoomLevelAdaptor = (zoomLevel) => (item) => {
31
+ return {
32
+ opacityMultiplier: 1,
33
+ sizeMultiplier: 1
34
+ };
35
+ }, } = {}) {
36
+ this.globe = globe;
37
+ this._itemMap = new Map();
38
+ this.doDraw = doDraw;
39
+ this.angleOnSphere = angleOnSphere;
40
+ this.zoomLevelAdaptor = zoomLevelAdaptor;
41
+ this.setStyle(style);
42
+ }
43
+ setOpacity(opacity) {
44
+ (0, typecheck_1.opacityCheck)(opacity);
45
+ this._style.opacity = opacity;
46
+ this.globe.DrawRender();
47
+ }
48
+ setStyle(style) {
49
+ (0, typecheck_1.isTextFont)(style.textFont);
50
+ this._style = style;
51
+ this.globe.DrawRender();
52
+ }
53
+ /**
54
+ *
55
+ * @param {{text, long, lat, z = 0, xOffset = 0, yOffset = 0, isAngleOn = false, Angle = 0 }} item
56
+ * @returns
57
+ */
58
+ insertItem(item) {
59
+ const key = this.keyAdaptor ? this.keyAdaptor(item) : item;
60
+ this._itemMap.set(key, item);
61
+ this.globe.DrawRender();
62
+ }
63
+ // TODO: use item style
64
+ draw() {
65
+ if (!this.doDraw) {
66
+ return;
67
+ }
68
+ const { globe, _itemMap, _style } = this;
69
+ const { zMode, textFont, opacity } = _style;
70
+ const is3D = globe.api_GetCurrentGeometry() === 0;
71
+ const angleIsOn = is3D ? true : this.angleOnSphere;
72
+ const zoomLevel = globe.api_GetCurrentLODWithDecimal();
73
+ const zoomAdaptor = this.zoomLevelAdaptor(zoomLevel);
74
+ const theSize = textFont.size;
75
+ _itemMap.forEach((item, key) => {
76
+ const { text, long, lat, z = 0, xOffset = 0, yOffset = 0, isAngleOn = false, angle = 0 } = item;
77
+ const { x, y } = globe.api_GetScreenPointFromGeo({
78
+ long,
79
+ lat,
80
+ z
81
+ }, zMode);
82
+ const { opacityMultiplier, sizeMultiplier } = zoomAdaptor(item);
83
+ textFont.size = sizeMultiplier * theSize;
84
+ if (x !== null && y !== null) {
85
+ globe.api_DrawContextText(text, textFont, opacityMultiplier * opacity, { x: x + xOffset, y: y - yOffset }, (isAngleOn && angleIsOn), angle);
86
+ }
87
+ });
88
+ textFont.size = theSize;
89
+ }
90
+ }
91
+ exports.AttachedTextWriter = AttachedTextWriter;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContextTextWriter = void 0;
4
+ const webglobe_1 = require("@pirireis/webglobe");
5
+ const defaultStyle = {
6
+ textFont: {
7
+ name: 'Arial',
8
+ textColor: '#FFFFFF', // beyaz
9
+ hollowColor: '#000000', // siyah
10
+ size: 12, // piksel
11
+ hollow: true,
12
+ bold: true,
13
+ italic: false,
14
+ },
15
+ opacity: 1.0,
16
+ zMode: webglobe_1.CSZMode.Z_GROUND_PERVERTEX,
17
+ };
18
+ class ContextTextWriter {
19
+ constructor(globe, { style = null, doDraw = true } = {}) {
20
+ this.globe = globe;
21
+ this.itemMap = new Map();
22
+ this.style = style || defaultStyle;
23
+ this.doDraw = doDraw;
24
+ }
25
+ setDoDraw(bool) {
26
+ this.doDraw = bool;
27
+ }
28
+ setStyle(style) {
29
+ this.style = style;
30
+ }
31
+ setOpacity(opacity) {
32
+ this.style.opacity = opacity;
33
+ }
34
+ // Clean this ask Front dev
35
+ doDraw(boolean) {
36
+ this.doDraw = boolean;
37
+ }
38
+ draw() {
39
+ if (!this.doDraw)
40
+ return;
41
+ const { globe, style, itemMap } = this;
42
+ const { textFont, opacity: opacity_ } = style;
43
+ for (const [key, { lat, long, text, opacity = null }] of itemMap) {
44
+ const { x, y } = globe.api_GetScreenPointFromGeo({
45
+ long: long,
46
+ lat: lat,
47
+ z: 0,
48
+ }, style.zMode === webglobe_1.CSZMode.Z_MSL);
49
+ const o = opacity === null ? opacity_ : opacity * opacity_;
50
+ if (x !== null && y !== null)
51
+ globe.api_DrawContextTextMultiLine(text, textFont, o, { x, y });
52
+ }
53
+ }
54
+ insertText(key, lat, long, text) {
55
+ this.itemMap.set(key, { lat, long, text });
56
+ }
57
+ updateOpacityOfItem(key, opacity) {
58
+ this.itemMap.get(key).opacity = opacity;
59
+ }
60
+ updateOpacityBulk(items, keyAdaptor, valueAdaptor) {
61
+ for (const item of items) {
62
+ const key = keyAdaptor(item);
63
+ const opacity = valueAdaptor(item);
64
+ const data = this.itemMap.get(key);
65
+ data.opacity = opacity;
66
+ }
67
+ }
68
+ updateText(key, text) {
69
+ const item = this.itemMap.get(key);
70
+ item.text = text;
71
+ }
72
+ updateCoords(key, lat, long) {
73
+ const item = this.itemMap.get(key);
74
+ item.lat = lat;
75
+ item.long = long;
76
+ }
77
+ insertTextBulk(items) {
78
+ for (const item of items) {
79
+ this.itemMap.set(item.key, item);
80
+ }
81
+ }
82
+ updateTextCoordsBulk(items) {
83
+ for (const { key, lat, long } of items) {
84
+ const item = this.itemMap.get(key);
85
+ item.lat = lat;
86
+ item.long = long;
87
+ }
88
+ }
89
+ deleteTextBulk(keys) {
90
+ for (const key of keys) {
91
+ this.itemMap.delete(key);
92
+ }
93
+ }
94
+ clear() {
95
+ this.itemMap.clear();
96
+ }
97
+ }
98
+ exports.ContextTextWriter = ContextTextWriter;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContextTextWriter3 = void 0;
4
+ const webglobe_1 = require("@pirireis/webglobe");
5
+ const typecheck_1 = require("../util/check/typecheck");
6
+ /**
7
+ * TODOs:
8
+ * 1) update all if initials change (propably need a context and a callback to iterate over zPayload)
9
+ * 2) expose a mechanic to update text on zoom change
10
+ * 3) extend the mechanic on 2 to other events
11
+ *
12
+ * TODO: key check and raise error if doesnt exist
13
+ */
14
+ class ContextTextWriter3 {
15
+ constructor(globe, { style = {
16
+ textFont: {
17
+ name: 'Arial',
18
+ textColor: '#FFFFFF', // beyaz
19
+ hollowColor: '#000000', // siyah
20
+ size: 12, // piksel
21
+ hollow: true,
22
+ bold: true,
23
+ italic: false,
24
+ },
25
+ opacity: 1.0,
26
+ zMode: webglobe_1.CSZMode.Z_GROUND_PERVERTEX,
27
+ }, xOffset = 0, yOffset = 0, doDraw = true, textAdaptor = null, coordinatesAdaptor = null, keyAdaptor = null, opacityAdaptor = null, angleAdaptor = null, angleOnSphere = false, positionAdaptor = (item, i, container, properties) => "left", zoomLevelAdaptor = (zoomLevel) => (item) => {
28
+ return {
29
+ opacityMultiplier: 1,
30
+ sizeMultiplier: 1
31
+ };
32
+ } } = {}) {
33
+ this.globe = globe;
34
+ this.itemMap = new Map();
35
+ this.setStyle(style);
36
+ this.doDraw = doDraw;
37
+ this._checkParameterTypes(textAdaptor, coordinatesAdaptor, keyAdaptor, opacityAdaptor, angleAdaptor, xOffset, yOffset);
38
+ this.textAdaptor = textAdaptor;
39
+ this.coordinatesAdaptor = coordinatesAdaptor;
40
+ this.keyAdaptor = keyAdaptor;
41
+ this.zoomLevelAdaptor = zoomLevelAdaptor;
42
+ this.positionAdaptor = positionAdaptor;
43
+ this.opacityAdaptor = opacityAdaptor ? opacityAdaptor : () => 1;
44
+ this.angleOnSphere = angleOnSphere;
45
+ if (angleAdaptor) {
46
+ this.angleAdaptor = angleAdaptor;
47
+ this.angleAdaptorIsOn = true;
48
+ }
49
+ else {
50
+ this.angleAdaptor = () => null;
51
+ this.angleAdaptorIsOn = false;
52
+ }
53
+ this.xOffset = xOffset;
54
+ this.yOffset = yOffset;
55
+ }
56
+ _checkParameterTypes(textAdaptor, coordinatesAdaptor, keyAdaptor, opacityAdaptor, angleAdaptor, xOffset, yOffset) {
57
+ if (textAdaptor !== null)
58
+ if (!(textAdaptor instanceof Function))
59
+ throw new Error("textAdaptor is not an instance of a Function");
60
+ if (coordinatesAdaptor !== null)
61
+ if (!(coordinatesAdaptor instanceof Function))
62
+ throw new Error("coordinatesAdaptor is not an instance of a Function");
63
+ if (keyAdaptor !== null)
64
+ if (!(keyAdaptor instanceof Function))
65
+ throw new Error("keyAdaptor is not an instance of a Function");
66
+ if (opacityAdaptor !== null)
67
+ if (!(opacityAdaptor instanceof Function))
68
+ throw new Error("opacityAdaptor is not an instance of a Function");
69
+ if (angleAdaptor !== null)
70
+ if (!(angleAdaptor instanceof Function))
71
+ throw new Error("angleAdaptor is not an instance of a Function");
72
+ if (typeof xOffset !== "number")
73
+ throw new Error("xOffset type is not a number");
74
+ if (typeof yOffset !== "number")
75
+ throw new Error("yOffset type is not a number");
76
+ }
77
+ setKeyAdaptor(adaptor) {
78
+ this.keyAdaptor = adaptor;
79
+ }
80
+ setDoDraw(bool) {
81
+ this.doDraw = bool;
82
+ this.globe.DrawRender();
83
+ }
84
+ setStyle(style) {
85
+ (0, typecheck_1.isTextFont)(style.textFont);
86
+ (0, typecheck_1.opacityCheck)(style.opacity); //TODO: use shallow copy
87
+ this.style = style;
88
+ this.globe.DrawRender();
89
+ }
90
+ setOpacity(opacity) {
91
+ this.style.opacity = opacity;
92
+ this.globe.DrawRender();
93
+ }
94
+ draw() {
95
+ if (!this.doDraw)
96
+ return;
97
+ const { globe, style, itemMap, xOffset, yOffset } = this;
98
+ const { textFont, opacity: opacity_ } = style;
99
+ const textSize = textFont.size;
100
+ const is3D = globe.api_GetCurrentGeometry() === 0;
101
+ const angleIsOn = is3D ? (this.angleAdaptorIsOn && this.angleOnSphere) : (this.angleAdaptorIsOn);
102
+ const zoomLevel = globe.api_GetCurrentLODWithDecimal();
103
+ const zoomAdaptor = this.zoomLevelAdaptor(zoomLevel);
104
+ for (const item of itemMap.values()) {
105
+ const { lat, long, text, opacity = null, angle = null, zPayload, position } = item;
106
+ const { x, y } = globe.api_GetScreenPointFromGeo({
107
+ long: long,
108
+ lat: lat,
109
+ z: 0,
110
+ }, style.zMode === webglobe_1.CSZMode.Z_MSL);
111
+ const { opacityMultiplier, sizeMultiplier } = zoomAdaptor(zPayload);
112
+ const o = (opacity === null ? opacity_ : opacity * opacity_) * opacityMultiplier;
113
+ textFont.size = sizeMultiplier * textSize;
114
+ textFont.position = position;
115
+ if (x !== null && y !== null)
116
+ globe.api_DrawContextTextMultiLine(text, textFont, o, { x: x + xOffset, y: y - yOffset }, angleIsOn, angle);
117
+ }
118
+ textFont.size = textSize;
119
+ }
120
+ insertTextBulk(container, properties) {
121
+ container.forEach((v, i, c) => {
122
+ this.insertText(v, i, c, properties);
123
+ });
124
+ }
125
+ deleteTextBulk(keys) {
126
+ for (const key of keys) {
127
+ this.itemMap.delete(key);
128
+ }
129
+ }
130
+ insertText(item, id, container, properties) {
131
+ const key = this.keyAdaptor(item, id, container, properties);
132
+ const coords = this.coordinatesAdaptor(item, id, container, properties);
133
+ if (coords == null) {
134
+ this.itemMap.delete(key);
135
+ return;
136
+ }
137
+ const text = this.textAdaptor(item, id, container, properties);
138
+ if (text == null) {
139
+ this.itemMap.delete(key);
140
+ return;
141
+ }
142
+ ;
143
+ const opacity = this.opacityAdaptor(item, id, container, properties);
144
+ const angle = this.angleAdaptor(item, id, container, properties);
145
+ const position = this.positionAdaptor(item, id, container, properties);
146
+ this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity, angle, zPayload: item, position });
147
+ }
148
+ clear() {
149
+ this.itemMap.clear();
150
+ }
151
+ free() {
152
+ this.itemMap = null;
153
+ }
154
+ }
155
+ exports.ContextTextWriter3 = ContextTextWriter3;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContextTextWriter = void 0;
4
+ var context_text_1 = require("./context-text");
5
+ Object.defineProperty(exports, "ContextTextWriter", { enumerable: true, get: function () { return context_text_1.ContextTextWriter; } });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * registerMap(id, aMap, textFont)
4
+ * aMap key, object map.
5
+ * aMap is a specifical tem for a use case.
6
+ * The object has { text, long, lat, opacity, angle, zPayload, achor, xOffset, yOffset, ...extraPropertiesForZoomLevelAdaptor } properties.
7
+ * the plugin runs over items in aMap and draw text on the globe.
8
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.9.7",
3
+ "version": "0.9.8",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",