@pirireis/webglobeplugins 0.9.9 → 0.9.10

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 (211) hide show
  1. package/Math/angle-calculation.js +15 -0
  2. package/Math/arc.js +65 -0
  3. package/Math/bounds/line-bbox.js +188 -0
  4. package/Math/constants.js +9 -0
  5. package/Math/frustum/camera.js +24 -0
  6. package/Math/frustum/from-globeinfo.js +48 -0
  7. package/Math/frustum/types.js +2 -0
  8. package/Math/globe-util/horizon-plane.js +112 -0
  9. package/Math/index.js +1 -0
  10. package/Math/juction/arc-plane.js +83 -0
  11. package/Math/juction/line-sphere.js +25 -0
  12. package/Math/juction/plane-plane.js +58 -0
  13. package/Math/line.js +56 -0
  14. package/Math/matrix4.js +1 -0
  15. package/Math/methods.js +201 -0
  16. package/Math/plane.js +60 -0
  17. package/Math/quaternion.js +104 -0
  18. package/Math/types.js +2 -0
  19. package/Math/utils.js +4 -0
  20. package/Math/vec3.js +126 -0
  21. package/algorithms/search-binary.js +19 -0
  22. package/altitude-locator/adaptors.js +1 -0
  23. package/altitude-locator/draw-subset-obj.js +18 -0
  24. package/altitude-locator/keymethod.js +1 -0
  25. package/altitude-locator/plugin.js +341 -0
  26. package/altitude-locator/types.js +23 -0
  27. package/arrowfield/adaptor.js +14 -0
  28. package/arrowfield/index.js +10 -0
  29. package/arrowfield/plugin.js +86 -0
  30. package/bearing-line/index.js +8 -0
  31. package/bearing-line/plugin.js +449 -0
  32. package/circle-line-chain/chain-list-map.js +205 -0
  33. package/circle-line-chain/init.js +1 -0
  34. package/circle-line-chain/plugin.js +424 -0
  35. package/circle-line-chain/util.js +5 -0
  36. package/compass-rose/compass-rose-padding-flat.js +225 -0
  37. package/compass-rose/compass-text-writer.js +153 -0
  38. package/compass-rose/index.js +7 -0
  39. package/compassrose/compassrose.js +296 -0
  40. package/compassrose/index.js +8 -0
  41. package/globe-types.js +1 -0
  42. package/heatwave/index.js +10 -0
  43. package/heatwave/isobar/objectarraylabels.js +202 -0
  44. package/heatwave/isobar/plugin.js +343 -0
  45. package/heatwave/isobar/quadtreecontours.js +300 -0
  46. package/heatwave/plugins/heatwaveglobeshell.js +206 -0
  47. package/jest.config.js +7 -0
  48. package/package.json +4 -4
  49. package/partialrings/buffer-manager.js +81 -0
  50. package/partialrings/index.js +41 -0
  51. package/partialrings/plugin.js +135 -0
  52. package/partialrings/program.js +286 -0
  53. package/pin/pin-object-array.js +305 -0
  54. package/pin/pin-point-totem.js +60 -0
  55. package/point-heat-map/adaptors/timetracksplugin-format-to-this.js +66 -0
  56. package/point-heat-map/index.js +1 -0
  57. package/point-heat-map/plugin-webworker.js +126 -0
  58. package/point-heat-map/point-to-heat-map-flow.js +127 -0
  59. package/point-tracks/key-methods.js +5 -0
  60. package/point-tracks/plugin.js +338 -0
  61. package/programs/arrowfield/index.js +7 -0
  62. package/programs/arrowfield/logic.js +257 -0
  63. package/programs/arrowfield/object.js +66 -0
  64. package/programs/data2legend/density-to-legend.js +101 -0
  65. package/programs/data2legend/point-to-density-texture.js +100 -0
  66. package/programs/float2legendwithratio/index.js +8 -0
  67. package/programs/float2legendwithratio/logic.js +171 -0
  68. package/programs/float2legendwithratio/object.js +110 -0
  69. package/programs/globe-util/is-globe-moved.js +21 -0
  70. package/programs/globeshell/index.js +8 -0
  71. package/programs/globeshell/noise/noises.js +1 -0
  72. package/programs/globeshell/wiggle/index.js +8 -0
  73. package/programs/globeshell/wiggle/logic.js +345 -0
  74. package/programs/globeshell/wiggle/object.js +72 -0
  75. package/programs/helpers/blender/index.js +1 -0
  76. package/programs/helpers/blender/program.js +79 -0
  77. package/programs/helpers/fadeaway/index.js +7 -0
  78. package/programs/helpers/fadeaway/logic.js +72 -0
  79. package/programs/helpers/fadeaway/object.js +20 -0
  80. package/programs/helpers/index.js +8 -0
  81. package/programs/index.js +58 -0
  82. package/programs/interface.js +1 -0
  83. package/programs/line-on-globe/angled-line.js +176 -0
  84. package/programs/line-on-globe/circle-accurate-3d.js +141 -0
  85. package/programs/line-on-globe/circle-accurate-flat.js +216 -0
  86. package/programs/line-on-globe/circle-accurate.js +178 -0
  87. package/programs/line-on-globe/circle.js +167 -0
  88. package/programs/line-on-globe/degree-padding-around-circle-3d.js +159 -0
  89. package/programs/line-on-globe/index.js +1 -0
  90. package/programs/line-on-globe/lines-color-instanced-flat.js +136 -0
  91. package/programs/line-on-globe/linestrip.js +171 -0
  92. package/programs/line-on-globe/naive-accurate-flexible.js +195 -0
  93. package/programs/line-on-globe/to-the-surface.js +111 -0
  94. package/programs/line-on-globe/util.js +8 -0
  95. package/programs/picking/pickable-renderer.js +188 -0
  96. package/programs/point-on-globe/element-globe-surface-glow.js +142 -0
  97. package/programs/point-on-globe/element-point-glow.js +153 -0
  98. package/programs/point-on-globe/square-pixel-point.js +174 -0
  99. package/programs/programcache.js +131 -0
  100. package/programs/rings/distancering/circleflatprogram.js +156 -0
  101. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +369 -0
  102. package/programs/rings/distancering/circlepaddysharedbuffer.js +357 -0
  103. package/programs/rings/distancering/index.js +14 -0
  104. package/programs/rings/distancering/paddyflatprogram.js +172 -0
  105. package/programs/rings/distancering/paddyflatprogram2d.js +174 -0
  106. package/programs/rings/distancering/paddyflatprogram3d.js +172 -0
  107. package/programs/rings/distancering/shader.js +1 -0
  108. package/programs/rings/index.js +17 -0
  109. package/programs/rings/partial-ring/piece-of-pie.js +275 -0
  110. package/programs/totems/camerauniformblock.js +160 -0
  111. package/programs/totems/canvas-webglobe-info.js +110 -0
  112. package/programs/totems/gpu-selection-uniform-block.js +108 -0
  113. package/programs/totems/index.js +40 -0
  114. package/programs/two-d/pixel-circle.js +1 -0
  115. package/programs/two-d/pixel-padding-for-compass.js +162 -0
  116. package/programs/util.js +17 -0
  117. package/programs/vectorfields/index.js +23 -0
  118. package/programs/vectorfields/logics/drawrectangleparticles.js +107 -0
  119. package/programs/vectorfields/logics/index.js +12 -0
  120. package/programs/vectorfields/logics/pixelbased.js +142 -0
  121. package/programs/vectorfields/logics/ubo.js +63 -0
  122. package/programs/vectorfields/pingpongbuffermanager.js +76 -0
  123. package/rangerings/enum.js +5 -0
  124. package/rangerings/index.js +15 -0
  125. package/rangerings/plugin.js +560 -0
  126. package/rangerings/rangeringangletext.js +329 -0
  127. package/rangerings/ring-account.js +117 -0
  128. package/shaders/fragment-toy/firework.js +58 -0
  129. package/shaders/fragment-toy/singularity.js +59 -0
  130. package/shape-on-terrain/arc/naive/plugin.js +252 -0
  131. package/timetracks/adaptors-line-strip.js +71 -0
  132. package/timetracks/adaptors.js +122 -0
  133. package/timetracks/index.js +19 -0
  134. package/timetracks/plugin-line-strip.js +250 -0
  135. package/timetracks/plugin.js +258 -0
  136. package/timetracks/program-line-strip.js +611 -0
  137. package/timetracks/program.js +772 -0
  138. package/timetracks/programpoint-line-strip.js +154 -0
  139. package/timetracks/programpoint.js +147 -0
  140. package/types.js +15 -0
  141. package/util/account/bufferoffsetmanager.js +179 -0
  142. package/util/account/index.js +23 -0
  143. package/util/account/single-attribute-buffer-management/buffer-manager.js +108 -0
  144. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +150 -0
  145. package/util/account/single-attribute-buffer-management/index.js +9 -0
  146. package/util/account/single-attribute-buffer-management/object-store.js +51 -0
  147. package/util/account/single-attribute-buffer-management/types.js +2 -0
  148. package/util/account/util.js +22 -0
  149. package/util/algorithms/index.js +1 -0
  150. package/util/algorithms/search-binary.js +28 -0
  151. package/util/check/get.js +18 -0
  152. package/util/check/index.js +1 -0
  153. package/util/check/typecheck.js +49 -0
  154. package/util/geometry/index.js +51 -0
  155. package/util/gl-util/buffer/attribute-loader.js +69 -0
  156. package/util/gl-util/buffer/index.js +6 -0
  157. package/util/gl-util/buffer/types.js +1 -0
  158. package/util/gl-util/draw-options/methods.js +38 -0
  159. package/util/gl-util/draw-options/types.js +15 -0
  160. package/util/gl-util/uniform-block/manager.js +156 -0
  161. package/util/gl-util/uniform-block/shader.js +1 -0
  162. package/util/gl-util/uniform-block/types.js +8 -0
  163. package/util/heatwavedatamanager/datamanager.js +152 -0
  164. package/util/heatwavedatamanager/index.js +10 -0
  165. package/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +122 -0
  166. package/util/heatwavedatamanager/pointcoordsmeta.js +20 -0
  167. package/util/index.js +57 -0
  168. package/util/interpolation/index.js +1 -0
  169. package/util/interpolation/timetrack/index.js +5 -0
  170. package/util/interpolation/timetrack/timetrack-interpolator.js +79 -0
  171. package/util/interpolation/timetrack/web-worker-str.js +183 -0
  172. package/util/interpolation/timetrack/web-worker.js +48 -0
  173. package/util/jshelpers/data-filler.js +20 -0
  174. package/util/jshelpers/equality.js +20 -0
  175. package/util/jshelpers/index.js +37 -0
  176. package/util/jshelpers/timefilters.js +32 -0
  177. package/util/picking/fence.js +46 -0
  178. package/util/picking/picker-displayer.js +139 -0
  179. package/util/programs/draw-texture-on-canvas.js +89 -0
  180. package/util/programs/index.js +17 -0
  181. package/util/programs/shapesonglobe.js +214 -0
  182. package/util/programs/supersampletotextures.js +113 -0
  183. package/util/programs/texturetoglobe.js +182 -0
  184. package/util/shaderfunctions/geometrytransformations.js +340 -0
  185. package/util/shaderfunctions/index.js +18 -0
  186. package/util/shaderfunctions/nodata.js +11 -0
  187. package/util/shaderfunctions/noisefunctions.js +43 -0
  188. package/util/surface-line-data/arc-bboxes.js +25 -0
  189. package/util/surface-line-data/arcs-to-cuts.js +50 -0
  190. package/util/surface-line-data/cut-arc.js +1 -0
  191. package/util/surface-line-data/flow.js +28 -0
  192. package/util/surface-line-data/rbush-manager.js +1 -0
  193. package/util/surface-line-data/types.js +1 -0
  194. package/util/surface-line-data/web-worker.js +1 -0
  195. package/util/webglobe/gldefaultstates.js +7 -0
  196. package/util/webglobe/index.js +18 -0
  197. package/util/webglobe/rasteroverlay.js +78 -0
  198. package/util/webglobjectbuilders.js +388 -0
  199. package/util/webglobjectbuilders1.js +237 -0
  200. package/waveparticles/adaptor.js +17 -0
  201. package/waveparticles/index.js +10 -0
  202. package/waveparticles/plugin.js +266 -0
  203. package/wind/imagetovectorfieldandmagnitude.js +35 -0
  204. package/wind/index.js +14 -0
  205. package/wind/plugin.js +926 -0
  206. package/wind/vectorfieldimage.js +25 -0
  207. package/write-text/attached-text-writer.js +91 -0
  208. package/write-text/context-text.js +98 -0
  209. package/write-text/context-text3.js +155 -0
  210. package/write-text/index.js +5 -0
  211. package/write-text/writer-plugin.js +8 -0
@@ -0,0 +1,343 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.IsobarRasterToVector = void 0;
40
+ const util_1 = require("../../util");
41
+ const quadtreecontours_1 = __importStar(require("./quadtreecontours"));
42
+ const objectarraylabels_1 = __importDefault(require("./objectarraylabels"));
43
+ const typecheck_1 = require("../../util/check/typecheck");
44
+ class IsobarRasterToVector {
45
+ /**
46
+ * @typedef {Object} IsobarData
47
+ * @property {number} threshold
48
+ * @property {[number, number, number]} color | rgb color
49
+ * @property {string} label
50
+ *
51
+ * @param {*} id
52
+ * @param {Array<IsobarData>} isabors
53
+ * @param {number} width
54
+ * @param {number} height
55
+ * @param {Object} options
56
+ * @param {boolean} options.xFlip
57
+ * @param {boolean} options.yFlip
58
+ * @param {boolean} options.isOn
59
+ * @param {boolean} options.isLabelsOn
60
+ * @param {Object} options.labelStyle
61
+ */
62
+ constructor(id, dataManager, isobars, width, height, [minLon, minLat, maxLon, maxLat] = [-180, -90, 180, 90], { xFlip = false, yFlip = true, isOn = true, isLabelsOn = true, labelStyle = null, maxMipmapLevel = null } = {}) {
63
+ this.id = id;
64
+ this._isobarsCheckAndComplete(isobars);
65
+ this.isobars = isobars;
66
+ this.contourMipmap = null;
67
+ this.width = width;
68
+ this.height = height;
69
+ this.xFlip = xFlip;
70
+ this.yFlip = yFlip;
71
+ this.bbox = [minLon, minLat, maxLon, maxLat];
72
+ this.dataManager = dataManager;
73
+ this._transformationMethod = getTransformationMethod(xFlip, yFlip, width, height, minLon, minLat, maxLon, maxLat);
74
+ this._isOn = isOn;
75
+ this._isLabelsOn = isLabelsOn;
76
+ this._labelsLayer = null;
77
+ this._labelsLayerId = id + '_isobar-labels';
78
+ this._lineStrignRanges = [];
79
+ this._transpos = new Float32Array(3);
80
+ this._maxMipmapLevel = maxMipmapLevel;
81
+ this._labelStyle = labelStyle;
82
+ // this._transformationMethod = null;
83
+ }
84
+ // API
85
+ setData(data, on = false) {
86
+ if (!data)
87
+ return;
88
+ this._data = data;
89
+ if (on)
90
+ this._isOn = true;
91
+ if (this._isOn)
92
+ this._calculateAll(data);
93
+ }
94
+ on() {
95
+ this._isOn = true;
96
+ if (this._data)
97
+ this._calculateAll(this._data);
98
+ }
99
+ off() {
100
+ this._isOn = false;
101
+ this.clean();
102
+ }
103
+ clean() {
104
+ this.flush();
105
+ this.globe.DrawRender();
106
+ }
107
+ setFlip(xFlip, yFlip) {
108
+ (0, typecheck_1.isBoolean)(xFlip);
109
+ (0, typecheck_1.isBoolean)(yFlip);
110
+ if (this.xFlip === xFlip && this.yFlip === yFlip)
111
+ return;
112
+ this.xFlip = xFlip;
113
+ this.yFlip = yFlip;
114
+ const [minLon, minLat, maxLon, maxLat] = this.bbox;
115
+ const { width, height } = this;
116
+ this._transformationMethod = getTransformationMethod(xFlip, yFlip, width, height, minLon, minLat, maxLon, maxLat);
117
+ this._calculateLines();
118
+ this.globe.DrawRender();
119
+ }
120
+ setBoundingBox([minLon, minLat, maxLon, maxLat]) {
121
+ this.bbox = [minLon, minLat, maxLon, maxLat];
122
+ const { width, height, xFlip, yFlip } = this;
123
+ this._transformationMethod = getTransformationMethod(xFlip, yFlip, width, height, minLon, minLat, maxLon, maxLat);
124
+ this._calculateLines();
125
+ this.globe.DrawRender();
126
+ }
127
+ setIsLabelsOn(isLabelsOn) {
128
+ (0, typecheck_1.isBoolean)(isLabelsOn);
129
+ if (this._isLabelsOn === isLabelsOn)
130
+ return;
131
+ this._isLabelsOn = isLabelsOn;
132
+ if (!isLabelsOn) {
133
+ this._labelsLayer.removeFromMap();
134
+ }
135
+ else {
136
+ if (this._labelsLayer === null)
137
+ this._createLabelsLayer();
138
+ this._labelsLayer.addToMap();
139
+ this._createBufferData();
140
+ }
141
+ }
142
+ getIsobars() {
143
+ return this.isobars;
144
+ }
145
+ setIsobars(isobars) {
146
+ this._isobarsCheckAndComplete(isobars);
147
+ this.isobars = isobars;
148
+ this._calculateLines();
149
+ this.globe.DrawRender();
150
+ }
151
+ setWidthHeight(width, height) {
152
+ this.width = width;
153
+ this.height = height;
154
+ const { xFlip, yFlip } = this;
155
+ const [minLon, minLat, maxLon, maxLat] = this.bbox;
156
+ this._transformationMethod = getTransformationMethod(xFlip, yFlip, width, height, minLon, minLat, maxLon, maxLat);
157
+ this._calculateLines();
158
+ this.globe.DrawRender();
159
+ }
160
+ getLabelStyle() {
161
+ return this._labelsLayer.getLabelStyle();
162
+ }
163
+ setOpacity(opacity) {
164
+ (0, typecheck_1.opacityCheck)(opacity);
165
+ this.program.setOpacity(opacity);
166
+ }
167
+ setLabelStyle(style) {
168
+ this._labelStyle = style;
169
+ if (this._labelsLayer)
170
+ this._labelsLayer.setLabelStyle(style);
171
+ const lastState = this._isLabelsOn;
172
+ this.setIsLabelsOn(false);
173
+ this.setIsLabelsOn(lastState);
174
+ if (lastState)
175
+ this._createBufferData();
176
+ }
177
+ setMaxMipmapLevel(maxMipmapLevel = null) {
178
+ this._maxMipmapLevel = maxMipmapLevel;
179
+ this._calculateLines();
180
+ this.globe.DrawRender();
181
+ }
182
+ flush() {
183
+ this.program.setBufferData(new Float32Array(0));
184
+ this._lineStrignRanges = [];
185
+ if (this._isLabelsOn)
186
+ this._labelsLayer.flush();
187
+ }
188
+ //
189
+ // implicit methods
190
+ init(globe, gl) {
191
+ this.gl = gl;
192
+ this.globe = globe;
193
+ this.program = new util_1.ShapesOnGlobeProgram(gl, globe, 'line_strip');
194
+ if (this._isLabelsOn) {
195
+ this._createLabelsLayer();
196
+ this._labelsLayer.addToMap();
197
+ }
198
+ this.dataManager.register(this.id, (ratio, t1, t2) => {
199
+ if (!t1 || !t2) {
200
+ this.clean();
201
+ return;
202
+ }
203
+ const data = dataMixer(t1, t2, ratio);
204
+ if (this._isOn)
205
+ this.setData(data);
206
+ });
207
+ }
208
+ resize(width, height) {
209
+ this.program.resize(width, height);
210
+ }
211
+ draw3D(projMatrix, modelviewMatrix, transPos) {
212
+ if (!this._ready)
213
+ return;
214
+ this._drawContour(projMatrix, modelviewMatrix, transPos);
215
+ }
216
+ _calculateLines() {
217
+ this._calculateContours();
218
+ this._bufferData = this._createBufferData();
219
+ this.program.setBufferData(this._bufferData);
220
+ }
221
+ _drawContour(projMatrix, modelviewMatrix, transPos) {
222
+ this.program.draw(projMatrix, modelviewMatrix, transPos, this._lineStrignRanges);
223
+ }
224
+ _calculateIntersections(threshold) {
225
+ const { _transformationMethod } = this;
226
+ const lines = this.contourMipmap.contour([threshold], { maxMipmapLevel: this._maxMipmapLevel }).map(coords => {
227
+ return coords.map(([x, y]) => _transformationMethod(x, y));
228
+ });
229
+ return lines;
230
+ }
231
+ _calculateAll(data) {
232
+ this.contourMipmap = new quadtreecontours_1.default(data, this.width, this.height);
233
+ this._calculateContours();
234
+ this._bufferData = this._createBufferData();
235
+ this.program.setBufferData(this._bufferData);
236
+ this.globe.DrawRender();
237
+ this._ready = true;
238
+ }
239
+ _calculateContours() {
240
+ const { isobars } = this;
241
+ for (const isobar of isobars) {
242
+ const { threshold } = isobar;
243
+ const lines = this._calculateIntersections(threshold);
244
+ isobar.lines = lines;
245
+ }
246
+ }
247
+ _isobarsCheckAndComplete(isobars) {
248
+ window.isobars = isobars;
249
+ if (!Array.isArray(isobars))
250
+ throw new Error("isobars must be an array");
251
+ if (isobars.length === 0)
252
+ throw new Error("isobars must contain at least one element");
253
+ for (const isobar of isobars) {
254
+ if (!isobar || typeof isobar !== 'object')
255
+ throw new Error("isobar must be an object");
256
+ if (typeof isobar.threshold !== 'number')
257
+ throw new Error("isobar.threshold must be a number");
258
+ if (isobar.color) {
259
+ if (!Array.isArray(isobar.color) || isobar.color.length !== 3)
260
+ throw new Error("isobar.color must be an array with 3 elements");
261
+ for (const color of isobar.color) {
262
+ if (color < 0 || color > 1)
263
+ throw new Error("isobar.color elements must be between 0 and 1");
264
+ }
265
+ }
266
+ if (!isobar.color)
267
+ isobar.color = [1, 1, 1];
268
+ }
269
+ }
270
+ _createBufferData() {
271
+ const { isobars } = this;
272
+ const pointCount = isobars.reduce((acc, { lines }) => acc + lines.reduce((acc, line) => acc + line.length, 0), 0);
273
+ const bufferData = new Float32Array(pointCount * 6);
274
+ let index = 0;
275
+ let pointCounter = 0;
276
+ this._lineStrignRanges = [];
277
+ // gather label data label
278
+ const labelPoints = {
279
+ coords: [],
280
+ coordsZ: [],
281
+ attribs: []
282
+ };
283
+ const { coords, coordsZ, attribs } = labelPoints;
284
+ let fidCounter = 0;
285
+ for (const { lines, color, threshold } of isobars) {
286
+ for (const line of lines) {
287
+ let startIndex = pointCounter;
288
+ for (const [x, y] of line) {
289
+ const pixXY = (0, util_1.latLongToPixelXY)(y, x);
290
+ bufferData[index++] = pixXY.x;
291
+ bufferData[index++] = pixXY.y;
292
+ bufferData[index++] = color[0];
293
+ bufferData[index++] = color[1];
294
+ bufferData[index++] = color[2];
295
+ bufferData[index++] = 1.0;
296
+ pointCounter++;
297
+ }
298
+ coords.push(line[0][0], line[0][1]);
299
+ coordsZ.push(0);
300
+ attribs.push({ value: threshold, fid: fidCounter++ });
301
+ this._lineStrignRanges.push([startIndex, pointCounter - startIndex]);
302
+ }
303
+ }
304
+ if (this._isLabelsOn)
305
+ this._labelsLayer.setData(labelPoints);
306
+ return bufferData;
307
+ }
308
+ _createLabelsLayer() {
309
+ this._labelsLayer = new objectarraylabels_1.default(this._labelsLayerId, this.globe, this._labelStyle);
310
+ }
311
+ setGeometry() {
312
+ this.program.setGeometry();
313
+ }
314
+ free() {
315
+ this.flush();
316
+ this.program.free();
317
+ if (this._isLabelsOn)
318
+ this._labelsLayer.removeFromMap();
319
+ this.dataManager.unregister(this.id);
320
+ }
321
+ }
322
+ exports.IsobarRasterToVector = IsobarRasterToVector;
323
+ const getTransformationMethod = (xFlip, yFlip, width, height, minX, minY, maxX, maxY) => {
324
+ const { scaleX, scaleY } = (0, quadtreecontours_1.scaleParameters)(minX, minY, maxX, maxY, width, height);
325
+ if (xFlip && yFlip)
326
+ return (x, y) => [maxX - x * scaleX, maxY - y * scaleY];
327
+ if (xFlip && !yFlip)
328
+ return (x, y) => [maxX - x * scaleX, minY + y * scaleY];
329
+ if (!xFlip && yFlip)
330
+ return (x, y) => [minX + x * scaleX, maxY - y * scaleY];
331
+ return (x, y) => [minX + x * scaleX, minY + y * scaleY];
332
+ };
333
+ function dataMixer(data1, data2, ratio) {
334
+ if (!data1 || !data2)
335
+ return null;
336
+ if (data1.length !== data2.length)
337
+ throw new Error("Data length mismatch");
338
+ const data = new Float32Array(data1.length);
339
+ for (let i = 0; i < data1.length; i++) {
340
+ data[i] = data1[i] * (1 - ratio) + data2[i] * ratio;
341
+ }
342
+ return data;
343
+ }
@@ -0,0 +1,300 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scaleParameters = scaleParameters;
4
+ // © 2019 3D Robotics. License: Apache-2.0
5
+ /* eslint no-plusplus: "off", prefer-rest-params: "off" */
6
+ const OUTSIDE = 0;
7
+ const ABOVE = 1;
8
+ const BELOW = 2;
9
+ const WITHIN = 3;
10
+ // Build mipmap layer N from layer N+1
11
+ function mipmapReduce({ min, max, width, height, scale }) {
12
+ const outWidth = Math.ceil(width / 2);
13
+ const outHeight = Math.ceil(height / 2);
14
+ function reduceWith(data, reduce) {
15
+ const out = new Float32Array(outWidth * outHeight);
16
+ let x;
17
+ let y;
18
+ for (y = 0; y < Math.floor(height / 2); y++) {
19
+ for (x = 0; x < Math.floor(width / 2); x++) {
20
+ out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 0) * width + (x * 2 + 1)], data[(y * 2 + 1) * width + (x * 2 + 0)], data[(y * 2 + 1) * width + (x * 2 + 1)]);
21
+ }
22
+ if (x < outWidth) {
23
+ out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 1) * width + (x * 2 + 0)]);
24
+ }
25
+ }
26
+ if (y < outHeight) {
27
+ for (x = 0; x < Math.floor(width / 2); x++) {
28
+ out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 0) * width + (x * 2 + 1)]);
29
+ }
30
+ }
31
+ if (x < outWidth && y < outHeight) {
32
+ out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)]);
33
+ }
34
+ return out;
35
+ }
36
+ function minFinite() {
37
+ let r = Infinity;
38
+ for (let i = 0; i < arguments.length; i++) { // significantly faster than the code Babel generates for ...args
39
+ const v = arguments[i];
40
+ if (v < r)
41
+ r = v;
42
+ }
43
+ return r;
44
+ }
45
+ function maxFinite() {
46
+ let r = -Infinity;
47
+ for (let i = 0; i < arguments.length; i++) {
48
+ const v = arguments[i];
49
+ if (v > r)
50
+ r = v;
51
+ }
52
+ return r;
53
+ }
54
+ return {
55
+ min: reduceWith(min, minFinite),
56
+ max: reduceWith(max, maxFinite),
57
+ width: outWidth,
58
+ height: outHeight,
59
+ scale: scale * 2,
60
+ };
61
+ }
62
+ class ContourMipmap {
63
+ constructor(raster, width, height) {
64
+ // Bottom mipmap layer is just the raster: at each pixel the minimum and maximum are the same
65
+ this.levels = [{ min: raster, max: raster, width, height, scale: 1 }];
66
+ while (this.levels[0].width > 1 || this.levels[0].height > 1) {
67
+ this.levels.unshift(mipmapReduce(this.levels[0]));
68
+ }
69
+ }
70
+ // Get the minimum elevation in the mipmap
71
+ min() { return this.levels[0].min[0]; }
72
+ // Get the maximum elevation in the mipmap
73
+ max() { return this.levels[0].max[0]; }
74
+ // Get an array of contour levels for a specified contour interval
75
+ intervals(interval) {
76
+ if (interval <= 0)
77
+ throw new Error('Contour interval must be positive');
78
+ const min = this.min();
79
+ const max = this.max();
80
+ const levels = [];
81
+ let level = Math.ceil(min / interval) * interval;
82
+ while (level < max) {
83
+ levels.push(level);
84
+ level += interval;
85
+ }
86
+ return levels;
87
+ }
88
+ // Walk the quadtree for a specified contour level, and pass quadtree nodes
89
+ // and contour line segments to the callbacks. This is used for visualizing
90
+ // the quadtree; in most cases you should use .contour() instead, which
91
+ // assembles the line segments into lines and rings.
92
+ evaluateContour(contourLevel, { maxMipmapLevel }, addLine, addNode) {
93
+ maxMipmapLevel = maxMipmapLevel || this.levels.length - 1;
94
+ // Test the mipmap at the given coordinate and level, returning whether the contour line is ABOVE, BELOW, or WITHIN this mipmap cell
95
+ // If the mipmap is out of bounds or NaN at that point, OUTSIDE is returned.
96
+ const evaluate = (l, x, y) => {
97
+ const ml = this.levels[l];
98
+ const i = ml.width * y + x;
99
+ if (x >= ml.width || y >= ml.height || !Number.isFinite(ml.min[i]) || !Number.isFinite(ml.max[i]))
100
+ return OUTSIDE;
101
+ if (ml.min[i] >= contourLevel)
102
+ return ABOVE;
103
+ if (ml.max[i] < contourLevel)
104
+ return BELOW;
105
+ // If we've reached the maximum mipmap level, arbitrarily decide that cells that contain
106
+ // the contour elevation go inside the contour line.
107
+ if (l >= maxMipmapLevel)
108
+ return ABOVE;
109
+ return WITHIN;
110
+ };
111
+ // Add any vertical contour lines that exist between passed mipmap cell and
112
+ // its horizontal neighbor to the right. If the line exists at this mipmap
113
+ // level, it is added directly, otherwise split the edge and recurse at a
114
+ // more detailed mipmap level.
115
+ function edgeH(l, x, y) {
116
+ const e1 = evaluate(l, x, y);
117
+ const e2 = evaluate(l, x + 1, y);
118
+ if (e1 === ABOVE && e2 === BELOW) {
119
+ addLine(l, x + 1, y + 1, x + 1, y);
120
+ }
121
+ else if (e2 === ABOVE && e1 === BELOW) {
122
+ // reverse order of coordinates compared to case above so that lines
123
+ // go counterclockwise around the region above the contour value
124
+ addLine(l, x + 1, y, x + 1, y + 1);
125
+ }
126
+ else if (e1 === WITHIN || e2 === WITHIN) {
127
+ edgeH(l + 1, x * 2 + 1, y * 2 + 0);
128
+ edgeH(l + 1, x * 2 + 1, y * 2 + 1);
129
+ }
130
+ }
131
+ // Like edgeH, but for horizontal contour lines between the passed cell
132
+ // and its vertical neighbor below.
133
+ function edgeV(l, x, y) {
134
+ const e1 = evaluate(l, x, y);
135
+ const e2 = evaluate(l, x, y + 1);
136
+ if (e1 === ABOVE && e2 === BELOW) {
137
+ addLine(l, x, y + 1, x + 1, y + 1);
138
+ }
139
+ else if (e2 === ABOVE && e1 === BELOW) {
140
+ addLine(l, x + 1, y + 1, x, y + 1);
141
+ }
142
+ else if (e1 === WITHIN || e2 === WITHIN) {
143
+ edgeV(l + 1, x * 2 + 0, y * 2 + 1);
144
+ edgeV(l + 1, x * 2 + 1, y * 2 + 1);
145
+ }
146
+ }
147
+ // Add all contour lines within a mipmap cell.
148
+ // It recurses into the four quadrants of the cell, and also uses edgeH and
149
+ // edgeV to add the contour lines that exist between quadrants.
150
+ function node(l, x, y) {
151
+ let e = evaluate(l, x, y);
152
+ if (e === WITHIN) {
153
+ node(l + 1, x * 2 + 0, y * 2 + 0);
154
+ node(l + 1, x * 2 + 1, y * 2 + 0);
155
+ node(l + 1, x * 2 + 0, y * 2 + 1);
156
+ node(l + 1, x * 2 + 1, y * 2 + 1);
157
+ edgeH(l + 1, x * 2 + 0, y * 2 + 0);
158
+ edgeV(l + 1, x * 2 + 0, y * 2 + 0);
159
+ edgeH(l + 1, x * 2 + 0, y * 2 + 1);
160
+ edgeV(l + 1, x * 2 + 1, y * 2 + 0);
161
+ }
162
+ else {
163
+ if (addNode)
164
+ addNode(l, x, y, e);
165
+ }
166
+ }
167
+ node(0, 0, 0);
168
+ }
169
+ // Generate a contour line for a specified value
170
+ //
171
+ // level: Value in the input array at which to draw a contour line
172
+ // opts: {
173
+ // maxMipmapLevel: Maximum recursion depth in the mipmap. As if you rescaled
174
+ // the input to a maximum dimension of 2^n pixels.
175
+ // (default unlimited)
176
+ // minPoints: Lines and rings with fewer points are removed. (default 0)
177
+ // smoothKernelWidth: Width of the rectangular filter for smoothing (default 2)
178
+ // smoothCycles: Number of iterations of smoothing (default 2)
179
+ // }
180
+ //
181
+ // Returns an array of lines, where each line is an array of [x, y] pairs.
182
+ contour(level, { maxMipmapLevel, smoothKernelWidth = 2, smoothCycles = 2, minPoints = 0 } = {}) {
183
+ // Use the quadtree algorithm to generate line segments that make up the contour
184
+ const segments = [];
185
+ this.evaluateContour(level, { maxMipmapLevel }, (l, x1, y1, x2, y2) => {
186
+ const scale = this.levels[l].scale;
187
+ const start = [scale * x1, scale * y1];
188
+ const end = [scale * x2, scale * y2];
189
+ segments.push({ start, end });
190
+ });
191
+ segments.sort((a, b) => key(a.start) - key(b.start));
192
+ // .. and then join them together into rings
193
+ // An arbitrary function to use a 2D point as a Map key
194
+ function key(a) { return a[0] + a[1] * 65536; }
195
+ const fragmentStart = new Map();
196
+ const fragmentEnd = new Map();
197
+ const rings = [];
198
+ segments.forEach(({ start, end }) => {
199
+ const a = fragmentEnd.get(key(start));
200
+ const b = fragmentStart.get(key(end));
201
+ if (a && b) {
202
+ fragmentEnd.delete(key(start));
203
+ fragmentStart.delete(key(end));
204
+ if (a === b) {
205
+ // Close a ring
206
+ a.push(end);
207
+ rings.push(a);
208
+ }
209
+ else {
210
+ // Join two lines together
211
+ const c = a.concat(b);
212
+ fragmentStart.set(key(c[0]), c);
213
+ fragmentEnd.set(key(c[c.length - 1]), c);
214
+ }
215
+ }
216
+ else if (a) {
217
+ // Extend an existing line from the end
218
+ fragmentEnd.delete(key(start));
219
+ a.push(end);
220
+ fragmentEnd.set(key(end), a);
221
+ }
222
+ else if (b) {
223
+ // Extend an existing line from the start
224
+ fragmentStart.delete(key(end));
225
+ b.unshift(start);
226
+ fragmentStart.set(key(start), b);
227
+ }
228
+ else {
229
+ // New line doesn't connect to any existing line
230
+ const c = [start, end];
231
+ fragmentStart.set(key(start), c);
232
+ fragmentEnd.set(key(end), c);
233
+ }
234
+ if (fragmentStart.size !== fragmentEnd.size) {
235
+ console.error(`Contour remaining fragment size mismatch ${fragmentStart.size} ${fragmentEnd.size}`);
236
+ }
237
+ });
238
+ const smoothOpts = {
239
+ kernelWidth: smoothKernelWidth,
240
+ cycles: smoothCycles,
241
+ };
242
+ // Closed rings and any unclosed line strings
243
+ return [...rings, ...fragmentStart.values()]
244
+ .filter(l => l.length >= minPoints && l.length >= smoothKernelWidth * 2)
245
+ .map(l => smooth(l, smoothOpts));
246
+ }
247
+ }
248
+ // Smooth a line by repeatedly applying a rectangular filter to approximate
249
+ // a gaussian filter. It detects closed loops and preserves them.
250
+ // The line is passed as an array of `[x, y]` pairs.
251
+ //
252
+ // kernelWidth: Width of the rectangular filter kernel
253
+ // cycles: Number of times to apply the kernel
254
+ function smooth(line, { kernelWidth = 2, cycles = 2 }) {
255
+ const isLoop = line[0][0] === line[line.length - 1][0] && line[0][1] === line[line.length - 1][1];
256
+ let pointAt;
257
+ if (isLoop) {
258
+ pointAt = i => line[(i + line.length) % line.length];
259
+ }
260
+ else {
261
+ pointAt = i => line[Math.min(Math.max(i, 0), line.length - 1)];
262
+ }
263
+ const sc = 1.0 / (kernelWidth * 2);
264
+ for (let cycle = 0; cycle < cycles; cycle++) {
265
+ let px = 0;
266
+ let py = 0;
267
+ if (isLoop) {
268
+ for (let i = line.length - kernelWidth; i < line.length; i++) {
269
+ px += line[i][0];
270
+ py += line[i][1];
271
+ }
272
+ }
273
+ else {
274
+ px = line[0][0] * kernelWidth;
275
+ py = line[0][1] * kernelWidth;
276
+ }
277
+ for (let i = 0; i < kernelWidth; i++) {
278
+ px += line[i][0];
279
+ py += line[i][1];
280
+ }
281
+ const res = line.slice();
282
+ for (let i = 0; i < line.length; i++) {
283
+ res[i] = [px * sc, py * sc];
284
+ px += pointAt(i + kernelWidth)[0] - pointAt(i - kernelWidth)[0];
285
+ py += pointAt(i + kernelWidth)[1] - pointAt(i - kernelWidth)[1];
286
+ }
287
+ if (isLoop) {
288
+ // Keep the loop closed
289
+ res[res.length - 1] = res[0].slice();
290
+ }
291
+ line = res;
292
+ }
293
+ return line;
294
+ }
295
+ function scaleParameters(minLongitude, minLatitude, maxLongitude, maxLatitude, width, height) {
296
+ const scaleX = (maxLongitude - minLongitude) / width;
297
+ const scaleY = (maxLatitude - minLatitude) / height;
298
+ return { scaleX, scaleY };
299
+ }
300
+ exports.default = ContourMipmap;