@pirireis/webglobeplugins 0.9.9 → 0.9.11

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