@pirireis/webglobeplugins 0.9.5 → 0.9.7

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