@pirireis/webglobeplugins 0.12.0-alpha → 0.14.0-alpha

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 (68) hide show
  1. package/Math/arc-cdf-points.js +20 -0
  2. package/Math/arc-generate-points copy.js +1 -0
  3. package/Math/arc.js +21 -8
  4. package/Math/circle-cdf-points.js +0 -2
  5. package/Math/circle.js +35 -16
  6. package/Math/templete-shapes/grid-visually-equal.js +66 -0
  7. package/altitude-locator/plugin.js +3 -2
  8. package/bearing-line/plugin.js +1 -2
  9. package/circle-line-chain/plugin.js +4 -7
  10. package/compass-rose/compass-rose-padding-flat.js +12 -0
  11. package/package.json +1 -1
  12. package/programs/line-on-globe/degree-padding-around-circle-3d.js +1 -1
  13. package/programs/line-on-globe/linestrip/data.js +4 -0
  14. package/programs/line-on-globe/{linestrip.js → linestrip/linestrip.js} +37 -35
  15. package/programs/line-on-globe/naive-accurate-flexible.js +23 -16
  16. package/programs/picking/pickable-renderer.js +1 -2
  17. package/programs/rings/distancering/circleflatprogram.js +116 -120
  18. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +1 -1
  19. package/programs/rings/distancering/circlepaddysharedbuffer.js +368 -354
  20. package/programs/rings/distancering/index.js +6 -5
  21. package/programs/rings/distancering/paddyflatprogram.js +127 -136
  22. package/programs/rings/distancering/paddyflatprogram2d.js +129 -138
  23. package/programs/rings/distancering/paddyflatprogram3d.js +128 -136
  24. package/programs/rings/partial-ring/piece-of-pie copy.js +286 -0
  25. package/programs/rings/partial-ring/piece-of-pie.js +26 -13
  26. package/programs/totems/camerauniformblock.js +1 -1
  27. package/programs/totems/index.js +1 -1
  28. package/programs/vectorfields/logics/pixelbased.js +5 -21
  29. package/range-tools-on-terrain/bearing-line/adapters.js +111 -0
  30. package/range-tools-on-terrain/bearing-line/plugin.js +360 -0
  31. package/range-tools-on-terrain/bearing-line/types.js +1 -0
  32. package/range-tools-on-terrain/circle-line-chain/adapters.js +83 -0
  33. package/range-tools-on-terrain/circle-line-chain/chain-list-map.js +351 -0
  34. package/range-tools-on-terrain/circle-line-chain/plugin.js +389 -0
  35. package/range-tools-on-terrain/circle-line-chain/types.js +1 -0
  36. package/range-tools-on-terrain/range-ring/adapters.js +25 -0
  37. package/range-tools-on-terrain/range-ring/plugin.js +31 -0
  38. package/range-tools-on-terrain/range-ring/types.js +1 -0
  39. package/rangerings/plugin.js +7 -11
  40. package/semiplugins/lightweight/line-plugin.js +195 -0
  41. package/semiplugins/lightweight/piece-of-pie-plugin.js +175 -0
  42. package/semiplugins/shape-on-terrain/arc-plugin.js +368 -0
  43. package/{shape-on-terrain/circle/plugin.js → semiplugins/shape-on-terrain/circle-plugin.js} +129 -68
  44. package/semiplugins/shape-on-terrain/derived/padding-plugin.js +96 -0
  45. package/semiplugins/type.js +1 -0
  46. package/types.js +0 -11
  47. package/util/account/create-buffermap-orchastration.js +39 -0
  48. package/util/account/index.js +2 -2
  49. package/util/account/single-attribute-buffer-management/buffer-manager.js +2 -3
  50. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +14 -3
  51. package/util/build-strategy/static-dynamic.js +1 -1
  52. package/util/check/typecheck.js +15 -1
  53. package/util/geometry/index.js +3 -2
  54. package/util/gl-util/buffer/attribute-loader.js +2 -5
  55. package/util/gl-util/draw-options/methods.js +4 -5
  56. package/util/webglobjectbuilders.js +4 -9
  57. package/write-text/context-text3.js +17 -0
  58. package/write-text/context-text3old.js +152 -0
  59. package/programs/line-on-globe/circle-accurate.js +0 -175
  60. package/programs/line-on-globe/circle.js +0 -164
  61. package/programs/line-on-globe/to-the-surface.js +0 -109
  62. package/programs/rings/distancering/shader.js +0 -1
  63. package/programs/totems/canvas-webglobe-info1.js +0 -106
  64. package/shape-on-terrain/arc/naive/plugin.js +0 -205
  65. package/util/check/get.js +0 -14
  66. package/util/gl-util/buffer/types.js +0 -1
  67. package/util/gl-util/draw-options/types.js +0 -15
  68. package/util/webglobjectbuilders1.js +0 -219
@@ -1,205 +0,0 @@
1
- import { LineStripProgramCache } from "../../../programs/line-on-globe/linestrip";
2
- import { createBufferAndReadInfo } from '../../../util/gl-util/buffer/attribute-loader';
3
- // import { populateFloat32Array } from "../../../util/jshelpers/data-filler";
4
- import { BufferManager, BufferOrchestrator } from "../../../util/account/single-attribute-buffer-management/index";
5
- import { globe3Dcoordinates, globe2Dcoordinates, RADIANS } from "../../../Math/methods";
6
- import { generateArcPoints } from "../../../Math/arc-cdf-points";
7
- import * as vec3 from "../../../Math/vec3";
8
- import * as arc from "../../../Math/arc";
9
- import { CameraUniformBlockTotemCache } from "../../../programs/totems/camerauniformblock";
10
- import { WORLD_RADIUS_3D } from "../../../Math/constants";
11
- const VERTEX_COUNT = 70;
12
- const INITAL_CAPACITY = 10;
13
- const _0vector = [0, 0, 0];
14
- const _attractionPoint = [0, 0, 0];
15
- const _start = [0, 0, 0];
16
- const _end = [0, 0, 0];
17
- const _0arc = arc.create([1, 0, 0], [0, 1, 0]); // zero arc for intersection tests
18
- let interval = 1;
19
- export class NaiveLineOnTerrainPlugin {
20
- id;
21
- program = null;
22
- _bufferManagersCompMap = null;
23
- _bufferManagersCompMapTest = null;
24
- _bufferOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
25
- _testOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
26
- _opacity = 1;
27
- _arcUBOHandler = null;
28
- _vao = null;
29
- _vaoAllTest = null;
30
- _ubohandlerAllTest = null;
31
- globe = null;
32
- gl = null;
33
- _arcMap;
34
- _arcMapTest;
35
- _doBuild = false;
36
- _cameraUniformBlock = null;
37
- _attractionStrength = 8;
38
- constructor(id) {
39
- this.id = id;
40
- this._arcMap = new Map();
41
- this._arcMapTest = new Map();
42
- }
43
- insertArcFromLongLat(key, startPoint, endPoint) {
44
- if (this._arcMap.has(key)) {
45
- this._arcMap.delete(key);
46
- }
47
- vec3.fromLongLatToUnitVector(_start, [startPoint.long * RADIANS, startPoint.lat * RADIANS]);
48
- vec3.fromLongLatToUnitVector(_end, [endPoint.long * RADIANS, endPoint.lat * RADIANS]);
49
- const _arc = arc.create(_start, _end);
50
- this._arcMap.set(key, _arc);
51
- this._arcMapTest.set(key, arc.clone(_arc));
52
- this._doBuild = true;
53
- this.globe.DrawRender();
54
- }
55
- deleteArcs(keys) {
56
- for (const key of keys) {
57
- if (this._arcMap.has(key)) {
58
- this._arcMap.delete(key);
59
- }
60
- }
61
- this._doBuild = true;
62
- this.globe.DrawRender();
63
- }
64
- init(globe, gl) {
65
- this.globe = globe;
66
- this.gl = gl;
67
- this.program = LineStripProgramCache.get(globe);
68
- const g3D = globe3Dcoordinates(globe, 30);
69
- const g2D = globe2Dcoordinates(globe);
70
- this._cameraUniformBlock = CameraUniformBlockTotemCache.get(globe);
71
- this._bufferManagersCompMap = new Map([
72
- ["position3d", {
73
- bufferManager: new BufferManager(gl, 3 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
74
- adaptor: (item) => {
75
- const { longLatArr } = item;
76
- const result = g3D(longLatArr, { paddingCount: 1 });
77
- // console.log("result", result);
78
- return result;
79
- }
80
- }],
81
- ["position2d", {
82
- bufferManager: new BufferManager(gl, 2 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
83
- adaptor: (item) => {
84
- const { longLatArr } = item;
85
- return g2D(longLatArr, { paddingCount: 1 });
86
- }
87
- }
88
- ],
89
- ]);
90
- this._bufferManagersCompMapTest = new Map([
91
- ["positionTest3d", {
92
- bufferManager: new BufferManager(gl, 3 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
93
- adaptor: (item) => {
94
- const { longLatArr } = item;
95
- const result = g3D(longLatArr, { paddingCount: 1 });
96
- return result;
97
- }
98
- }],
99
- ["positionTest2d", {
100
- bufferManager: new BufferManager(gl, 2 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
101
- adaptor: (item) => {
102
- const { longLatArr } = item;
103
- return g2D(longLatArr, { paddingCount: 1 });
104
- }
105
- }
106
- ]
107
- ]);
108
- this._bufferOrchestrator = new BufferOrchestrator();
109
- this._arcUBOHandler = this.program.createUBO();
110
- this._arcUBOHandler.update(new Map([
111
- ["u_color", new Float32Array([1, 0, 0, 1])],
112
- ]));
113
- this._ubohandlerAllTest = this.program.createUBO();
114
- this._ubohandlerAllTest.update(new Map([
115
- ["u_color", new Float32Array([0, 0, 1, 1])],
116
- ]));
117
- this._vao = this.program.createVAO(createBufferAndReadInfo(this._bufferManagersCompMap.get("position3d")?.bufferManager.buffer), createBufferAndReadInfo(this._bufferManagersCompMap.get("position2d")?.bufferManager.buffer), null, null, null);
118
- this._vaoAllTest = this.program.createVAO(createBufferAndReadInfo(this._bufferManagersCompMapTest.get("positionTest3d")?.bufferManager.buffer), createBufferAndReadInfo(this._bufferManagersCompMapTest.get("positionTest2d")?.bufferManager.buffer), null, null, null);
119
- }
120
- draw3D() {
121
- // Drawing logic here
122
- this._buildArcs(); // can be async
123
- const { gl, program, _bufferOrchestrator, _vao, _arcUBOHandler, _vaoAllTest, _ubohandlerAllTest, _testOrchestrator } = this;
124
- if (!gl || !program || !_bufferOrchestrator || !_vao || !_arcUBOHandler
125
- || !_vaoAllTest || !_ubohandlerAllTest || !_testOrchestrator) {
126
- console.warn("WebGL context, program, or buffer orchestrator is not initialized.");
127
- return;
128
- }
129
- gl.disable(gl.DEPTH_TEST);
130
- const drawOptions = {
131
- drawRange: {
132
- first: 0,
133
- count: _bufferOrchestrator.length * (VERTEX_COUNT + 1)
134
- },
135
- indexes: null
136
- };
137
- program.draw(_vao, drawOptions, this._opacity, _arcUBOHandler);
138
- gl.enable(gl.DEPTH_TEST);
139
- }
140
- _buildArcs() {
141
- if (!this._doBuild)
142
- return; // if not needed to build, return early
143
- const { globe, _arcMap, _cameraUniformBlock, _bufferManagersCompMap } = this;
144
- if (!globe || !_cameraUniformBlock || !_bufferManagersCompMap) {
145
- console.warn("Globe or camera uniform block is not initialized.");
146
- return;
147
- }
148
- const lookAtPosition = _cameraUniformBlock.getLookAtVector();
149
- const cameraPosition = _cameraUniformBlock.getCameraVector();
150
- vec3.divideScalar(cameraPosition, cameraPosition, WORLD_RADIUS_3D);
151
- vec3.add(cameraPosition, cameraPosition, lookAtPosition);
152
- // vec3.normalize(cameraPosition, cameraPosition);
153
- vec3.divideScalar(cameraPosition, cameraPosition, 2);
154
- // vec3.multiplyScalar(cameraPosition, cameraPosition, 1.3);
155
- const _attractionStrength = (() => {
156
- const lod = globe.api_GetCurrentLODWithDecimal();
157
- if (lod < 11) {
158
- return 1;
159
- }
160
- return lod * (lod - 8.5);
161
- })();
162
- console.log("Attraction strength: ", _attractionStrength);
163
- const result = [];
164
- const longLat = [0, 0];
165
- for (const [key, arcInstance] of _arcMap) {
166
- arc.copy(_0arc, arcInstance);
167
- const isOnArc = arc.closestPoint(_attractionPoint, _0arc, cameraPosition);
168
- if (!isOnArc) {
169
- if (vec3.distanceSquared(cameraPosition, _0arc.p0) < vec3.distanceSquared(cameraPosition, _0arc.p1)) {
170
- vec3.copy(_attractionPoint, _0arc.p0);
171
- }
172
- else {
173
- vec3.copy(_attractionPoint, _0arc.p1);
174
- }
175
- }
176
- const generatedPoints = generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, VERTEX_COUNT, _attractionStrength);
177
- const longLatArr = new Float32Array(2 * VERTEX_COUNT);
178
- for (let i = 0; i < generatedPoints.length; i++) {
179
- const point = generatedPoints[i];
180
- vec3.fromUnitVectorToLongLat(longLat, point);
181
- longLatArr.set([longLat[0] / RADIANS, longLat[1] / RADIANS], i * 2);
182
- }
183
- result.push({
184
- key: key,
185
- longLatArr: longLatArr,
186
- });
187
- }
188
- this._bufferOrchestrator.resetWithCapacity(_bufferManagersCompMap, result.length);
189
- this._bufferOrchestrator.insertBulk(result, _bufferManagersCompMap);
190
- this._doBuild = false; // reset build flag
191
- this._checkIfCorrupted(); // check if any arc is corrupted
192
- }
193
- _checkIfCorrupted() {
194
- for (const [key, arcInstance] of this._arcMap) {
195
- const copyarc = this._arcMapTest.get(key);
196
- if (!copyarc) {
197
- console.warn(`Arc with key ${key} is missing in the test map.`);
198
- continue;
199
- }
200
- if (!arc.equals(arcInstance, copyarc)) {
201
- console.warn(`Arc with key ${key} is corrupted: p0 and p1 are the same point.`);
202
- }
203
- }
204
- }
205
- }
package/util/check/get.js DELETED
@@ -1,14 +0,0 @@
1
- export const mapGetOrThrow = (errorNote) => {
2
- return (mapInstance, ids) => {
3
- if (!ids)
4
- throw new Error("There is no map keys to get");
5
- const result = [];
6
- for (let i = 0; i < ids.length; i++) {
7
- const e = mapInstance.get(ids[i]);
8
- if (e === undefined)
9
- throw new Error(errorNote + " " + ids[i]);
10
- result.push(e);
11
- }
12
- return result;
13
- };
14
- };
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,15 +0,0 @@
1
- /**
2
- * @typedef DrawRange
3
- * @type {Object}
4
- * @property {int} first
5
- * @property {int} count
6
- *
7
- * @typedef DrawRangeIndexParams
8
- * @type {Object}
9
- * @property {null|DrawRange} drawRange
10
- * @property {null|ElementBuffer} elementBuffer
11
- * @property {null|indexType} indexType
12
- * @property {null|int} drawMode
13
- *
14
- */
15
- export {};
@@ -1,219 +0,0 @@
1
- // export function createShader(gl, type, source) {
2
- // const shader = gl.createShader(type);
3
- // gl.shaderSource(shader, source);
4
- // gl.compileShader(shader);
5
- // if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
6
- // throw new Error(gl.getShaderInfoLog(shader));
7
- // }
8
- // return shader;
9
- // }
10
- export function createShader(gl, type, source) {
11
- const shader = gl.createShader(type);
12
- gl.shaderSource(shader, source);
13
- gl.compileShader(shader);
14
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
15
- const errorLog = gl.getShaderInfoLog(shader);
16
- const shaderType = type === gl.VERTEX_SHADER ? 'VERTEX_SHADER' : 'FRAGMENT_SHADER';
17
- const sourceWithLineNumbers = source.split('\n').map((line, i) => `${i + 1}: ${line}`).join('\n');
18
- throw new Error(`Error compiling ${shaderType}:\n${errorLog}\nSource:\n${sourceWithLineNumbers}`);
19
- }
20
- return shader;
21
- }
22
- export function createProgram(gl, vertexSource, fragmentSource) {
23
- const program = gl.createProgram();
24
- const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexSource);
25
- const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
26
- gl.compileShader(vertexShader);
27
- if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
28
- console.error(gl.getShaderInfoLog(vertexShader));
29
- return;
30
- }
31
- gl.compileShader(fragmentShader);
32
- if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
33
- console.error(gl.getShaderInfoLog(fragmentShader));
34
- return;
35
- }
36
- gl.attachShader(program, vertexShader);
37
- gl.attachShader(program, fragmentShader);
38
- gl.linkProgram(program);
39
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
40
- console.error(gl.getProgramInfoLog(program));
41
- return;
42
- }
43
- return program;
44
- }
45
- export function createProgramWrapper(gl, vertexSource, fragmentSource) {
46
- const program = gl.createProgram();
47
- const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexSource);
48
- const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
49
- gl.attachShader(program, vertexShader);
50
- gl.attachShader(program, fragmentShader);
51
- gl.linkProgram(program);
52
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
53
- // console.log(gl.getProgramInfoLog(program));
54
- throw new Error(gl.getProgramInfoLog(program));
55
- }
56
- const wrapper = { program: program };
57
- const numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
58
- for (let i = 0; i < numAttributes; i++) {
59
- const attribute = gl.getActiveAttrib(program, i);
60
- wrapper[attribute.name] = gl.getAttribLocation(program, attribute.name);
61
- }
62
- const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
63
- for (let i = 0; i < numUniforms; i++) {
64
- const uniform = gl.getActiveUniform(program, i);
65
- wrapper[uniform.name] = gl.getUniformLocation(program, uniform.name);
66
- }
67
- return wrapper;
68
- }
69
- export function createTexture(gl, filter, data, width, height) {
70
- const texture = gl.createTexture();
71
- gl.bindTexture(gl.TEXTURE_2D, texture);
72
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
73
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
74
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
75
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
76
- if (data instanceof Uint8Array) {
77
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
78
- }
79
- else {
80
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, data);
81
- }
82
- gl.bindTexture(gl.TEXTURE_2D, null);
83
- return texture;
84
- }
85
- export function bindTexture(gl, texture, unit) {
86
- gl.activeTexture(gl.TEXTURE0 + unit);
87
- gl.bindTexture(gl.TEXTURE_2D, texture);
88
- }
89
- export function createBuffer(gl, data) {
90
- const buffer = gl.createBuffer();
91
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
92
- gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
93
- return buffer;
94
- }
95
- export function bindAttribute(gl, buffer, attribute, numComponents) {
96
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
97
- gl.enableVertexAttribArray(attribute);
98
- gl.vertexAttribPointer(attribute, numComponents, gl.FLOAT, false, 0, 0);
99
- }
100
- export function bindFramebuffer(gl, framebuffer, texture) {
101
- if (texture) {
102
- gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
103
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
104
- }
105
- else {
106
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
107
- }
108
- }
109
- export function decodeBase64(data) {
110
- const binary_string = atob(data);
111
- const len = binary_string.length;
112
- const bytes = new Uint8Array(len);
113
- for (let i = 0; i < len; i++) {
114
- bytes[i] = binary_string.charCodeAt(i);
115
- }
116
- return bytes;
117
- }
118
- export function createImageFromBase64(encodedData) {
119
- const bytes = decodeBase64(encodedData);
120
- const blob = new Blob([bytes.buffer], { type: "image/png" });
121
- const urlCreator = window.URL || window.webkitURL;
122
- const imageUrl = urlCreator.createObjectURL(blob);
123
- const image = new Image();
124
- image.src = imageUrl;
125
- return image;
126
- }
127
- export function getColorRamp(colors) {
128
- // console.log("getColorRamp", colors)
129
- const canvas = document.createElement('canvas');
130
- const ctx = canvas.getContext('2d');
131
- canvas.width = 256;
132
- canvas.height = 1;
133
- const gradient = ctx.createLinearGradient(0, 0, 256, 0);
134
- for (const stop in colors) {
135
- // console.log("stop", stop);
136
- gradient.addColorStop(colors[stop][0], colors[stop][1]);
137
- // Alttaki satir ile gradienti cevirip, shaderda ki `speed_t = 1.0 - speed_t`' kaldirdim.
138
- // gradientin en dusuk olmasi gereken siyah - mavi aralikta, mor renk gozlemledim.
139
- // gradient.addColorStop( 1.0 - colors[stop][0], colors[stop][1]);
140
- }
141
- ctx.fillStyle = gradient;
142
- ctx.fillRect(0, 0, 256, 1);
143
- return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
144
- }
145
- export function getColorRampDiscrate(values, thresholds) {
146
- const canvas = document.createElement('canvas');
147
- const ctx = canvas.getContext('2d');
148
- canvas.width = 256;
149
- canvas.height = 1;
150
- const gap = 1.0 / 256;
151
- const gradient = ctx.createLinearGradient(0, 0, 256, 0);
152
- for (let i = 0; i < thresholds.length - 1; i++) {
153
- gradient.addColorStop(thresholds[i], values[i]);
154
- gradient.addColorStop(thresholds[i + 1] - gap, values[i]);
155
- }
156
- gradient.addColorStop(thresholds[thresholds.length - 1], values[values.length - 1]);
157
- ctx.fillStyle = gradient;
158
- ctx.fillRect(0, 0, 256, 1);
159
- return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
160
- }
161
- export function getColorRampInterpolated(values, thresholds) {
162
- const canvas = document.createElement('canvas');
163
- const ctx = canvas.getContext('2d');
164
- canvas.width = 256;
165
- canvas.height = 1;
166
- const gradient = ctx.createLinearGradient(0, 0, 256, 0);
167
- // const gap = 1.0 / 256;
168
- // gradient.addColorStop(thresholds[0], values[0]);
169
- // gradient.addColorStop(thresholds[0] + gap, values[1]);
170
- for (let i = 0; i < thresholds.length; i++) {
171
- gradient.addColorStop(thresholds[i], values[i]);
172
- }
173
- // gradient.addColorStop(thresholds[thresholds.length - 1] - gap, values[values.length - 1]);
174
- ctx.fillStyle = gradient;
175
- ctx.fillRect(0, 0, 256, 1);
176
- return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
177
- }
178
- /**
179
- * values: n + 1 number of color hex values without alpha channel. Ex: ["#ff0000", "#00ff00", "#0000ff"]
180
- * thresholds: n number of thresholds. Ex: [0, 10, 20]
181
- * mode: [discrete, interpolated,]
182
- */
183
- export function getColorRampModed(values, thresholds, mode = "interpolated") {
184
- if (mode === "discrete") {
185
- return getColorRampDiscrate(values, thresholds);
186
- }
187
- else if (mode === "interpolated") {
188
- return getColorRampInterpolated(values, thresholds);
189
- }
190
- else {
191
- throw new Error("mode is not valid");
192
- }
193
- }
194
- export function defaultColorRamp() {
195
- const defaultRampColors = [
196
- [0.0, '#5e4fa2'],
197
- [0.15, '#3288bd'],
198
- [0.20, '#66c2a5'],
199
- [0.25, '#66c2a5'],
200
- [0.3, '#abdda4'],
201
- [0.4, '#e6f598'],
202
- [0.5, '#fee08b'],
203
- [0.6, '#fdae61'],
204
- [0.7, '#f46d43'],
205
- [1.0, '#ff1e13']
206
- ];
207
- return getColorRamp(defaultRampColors);
208
- }
209
- export function reloadCurrentGLProgram() {
210
- return function (target, key, descriptor) {
211
- const originalMethod = descriptor.value;
212
- descriptor.value = function () {
213
- const gl = target.gl;
214
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
215
- originalMethod.apply(this, arguments);
216
- gl.useProgram(currentProgram);
217
- };
218
- };
219
- }