@pirireis/webglobeplugins 0.0.1
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.
- package/arrowfield/adaptor.js +11 -0
- package/arrowfield/index.js +4 -0
- package/arrowfield/plugin.js +128 -0
- package/compassrose/compassrose.js +394 -0
- package/compassrose/index.js +2 -0
- package/heatwavemaps/index.js +4 -0
- package/heatwavemaps/isobar/objectarraylabels.js +247 -0
- package/heatwavemaps/isobar/plugin.js +337 -0
- package/heatwavemaps/isobar/quadtreecontours.js +338 -0
- package/heatwavemaps/plugins/heatwaveglobeshell.js +257 -0
- package/index.js +8 -0
- package/package.json +7 -0
- package/programs/arrowfield/index.js +2 -0
- package/programs/arrowfield/logic.js +284 -0
- package/programs/arrowfield/object.js +89 -0
- package/programs/float2legendwithratio/index.js +3 -0
- package/programs/float2legendwithratio/logic.js +189 -0
- package/programs/float2legendwithratio/object.js +132 -0
- package/programs/globeshell/index.js +2 -0
- package/programs/globeshell/noise/noises.js +0 -0
- package/programs/globeshell/wiggle/index.js +6 -0
- package/programs/globeshell/wiggle/logic.js +374 -0
- package/programs/globeshell/wiggle/object.js +94 -0
- package/programs/helpers/blender/index.js +0 -0
- package/programs/helpers/blender/program.js +91 -0
- package/programs/helpers/fadeaway/index.js +3 -0
- package/programs/helpers/fadeaway/logic.js +76 -0
- package/programs/helpers/fadeaway/object.js +20 -0
- package/programs/helpers/index.js +2 -0
- package/programs/index.js +21 -0
- package/programs/programcache.js +119 -0
- package/programs/rings/distancering/circleflatprogram.js +135 -0
- package/programs/rings/distancering/circlepaddysharedbuffer.js +502 -0
- package/programs/rings/distancering/index.js +5 -0
- package/programs/rings/distancering/paddyflatprogram.js +131 -0
- package/programs/rings/distancering/shader.js +0 -0
- package/programs/rings/index.js +9 -0
- package/programs/totems/camerauniformblock.js +129 -0
- package/programs/totems/index.js +2 -0
- package/programs/util.js +17 -0
- package/programs/vectorfields/index.js +3 -0
- package/programs/vectorfields/logics/drawrectangleparticles.js +125 -0
- package/programs/vectorfields/logics/index.js +5 -0
- package/programs/vectorfields/logics/pixelbased.js +161 -0
- package/programs/vectorfields/logics/ubo.js +64 -0
- package/programs/vectorfields/pingpongbuffermanager.js +80 -0
- package/rangerings/index.js +3 -0
- package/rangerings/rangerings.js +88 -0
- package/timetracks/adaptors.js +133 -0
- package/timetracks/index.js +3 -0
- package/timetracks/plugin.js +304 -0
- package/timetracks/program.js +850 -0
- package/timetracks/programpoint.js +168 -0
- package/util/datamanager/datamanager.js +168 -0
- package/util/datamanager/index.js +3 -0
- package/util/datamanager/pointcoordinatesdatacalculator.js +133 -0
- package/util/datamanager/pointcoordsmeta.js +22 -0
- package/util/geometry/geodatafromtexture.js +52 -0
- package/util/geometry/index.js +44 -0
- package/util/index.js +13 -0
- package/util/jshelpers/index.js +1 -0
- package/util/jshelpers/timefilters.js +32 -0
- package/util/jshelpers/timemethods.js +19 -0
- package/util/programs/index.js +2 -0
- package/util/programs/shapesonglobe.js +248 -0
- package/util/programs/supersampletotextures.js +142 -0
- package/util/programs/texturetoglobe.js +203 -0
- package/util/shaderfunctions/geometrytransformations.js +129 -0
- package/util/shaderfunctions/index.js +2 -0
- package/util/shaderfunctions/nodata.js +10 -0
- package/util/shaderfunctions/noisefunctions.js +44 -0
- package/util/webglobe/gldefaultstates.js +4 -0
- package/util/webglobe/index.js +2 -0
- package/util/webglobe/rasteroverlay.js +96 -0
- package/util/webglobjectbuilders.js +256 -0
- package/waveparticles/adaptor.js +16 -0
- package/waveparticles/index.js +4 -0
- package/waveparticles/plugin.js +281 -0
- package/wind/imagetovectorfieldandmagnitude.js +39 -0
- package/wind/index.js +7 -0
- package/wind/plugin.js +1032 -0
- package/wind/vectorfieldimage.js +27 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { createProgram, shaderfunctions } from "../util";
|
|
2
|
+
import { CameraUniformBlockTotem, globeProgramCache } from "../programs";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const vertexShader = `#version 300 es
|
|
6
|
+
|
|
7
|
+
layout(std140) uniform GlobeCamera {
|
|
8
|
+
mat4 view; // 64 bytes 0
|
|
9
|
+
mat4 projection; // 64 bytes 64
|
|
10
|
+
vec3 translate; // 12 bytes 128
|
|
11
|
+
bool is3D; // 4 bytes 140
|
|
12
|
+
vec2 mapWH; // 8 bytes 144
|
|
13
|
+
vec2 screenWH; // 8 bytes 152
|
|
14
|
+
float z_level; // 4 bytes 160
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
layout(std140) uniform Globals {
|
|
18
|
+
float head_time;
|
|
19
|
+
float final_opacity;
|
|
20
|
+
float point_size;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
in vec3 start_position;
|
|
24
|
+
in float start_time;
|
|
25
|
+
in vec3 start_color;
|
|
26
|
+
in vec3 end_position;
|
|
27
|
+
in float end_time;
|
|
28
|
+
in vec3 end_color;
|
|
29
|
+
out vec4 v_color;
|
|
30
|
+
|
|
31
|
+
`+ shaderfunctions.pixelXYToCartesian3DPoint + shaderfunctions.pixelXYToCartesian2DPoint + `
|
|
32
|
+
|
|
33
|
+
void main() {
|
|
34
|
+
if (head_time < start_time || head_time > end_time) { return; }
|
|
35
|
+
float t = (head_time - start_time) / (end_time - start_time);
|
|
36
|
+
vec3 position = mix(start_position, end_position, t);
|
|
37
|
+
if (is3D){
|
|
38
|
+
vec3 pos = pixelXYToCartesian3DPoint(position);
|
|
39
|
+
gl_Position = projection * view * vec4(pos - translate, 1.0);
|
|
40
|
+
} else {
|
|
41
|
+
vec2 xy = pixelXYToCartesian2DPoint(position.xy, translate.xy, mapWH, screenWH);
|
|
42
|
+
gl_Position = projection * vec4(xy.x, xy.y, 0.0, 1.0);
|
|
43
|
+
}
|
|
44
|
+
v_color = vec4(mix(start_color, end_color, t), final_opacity);
|
|
45
|
+
gl_PointSize = point_size;
|
|
46
|
+
}`;
|
|
47
|
+
|
|
48
|
+
const fragmentShader = `#version 300 es
|
|
49
|
+
precision highp float;
|
|
50
|
+
in vec4 v_color;
|
|
51
|
+
out vec4 outColor;
|
|
52
|
+
void main() {
|
|
53
|
+
outColor = v_color;
|
|
54
|
+
}`;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export default class {
|
|
58
|
+
|
|
59
|
+
constructor(gl, globe, attrBuffer, options) {
|
|
60
|
+
|
|
61
|
+
this.gl = gl;
|
|
62
|
+
this._cameraBlockBindingPoint = 0;
|
|
63
|
+
this._globalsBlockBindingPoint = 1;
|
|
64
|
+
this.cameraUniformBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
|
|
65
|
+
this._vao = gl.createVertexArray();
|
|
66
|
+
this._attbuffer = attrBuffer;
|
|
67
|
+
this.program = this._createProgram();
|
|
68
|
+
this._drawCount = 0;
|
|
69
|
+
|
|
70
|
+
this._globalsbuffer = gl.createBuffer();
|
|
71
|
+
{
|
|
72
|
+
const { gl, _globalsbuffer } = this;
|
|
73
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
74
|
+
gl.bufferData(gl.UNIFORM_BUFFER, 12, gl.STREAM_DRAW); // TODO: sperate head time to make it dynamic maybe?
|
|
75
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([0, options.opacity, options.pointSize]));
|
|
76
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, this._globalsBlockBindingPoint, _globalsbuffer);
|
|
77
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
_createProgram() {
|
|
83
|
+
const gl = this.gl
|
|
84
|
+
|
|
85
|
+
const program = createProgram(gl, vertexShader, fragmentShader);
|
|
86
|
+
const ubo = this.cameraUniformBlockTotem.getUBO(); // ubo bl
|
|
87
|
+
const cameraBlockIndex = gl.getUniformBlockIndex(program, "GlobeCamera");
|
|
88
|
+
gl.uniformBlockBinding(program, cameraBlockIndex, this._cameraBlockBindingPoint);
|
|
89
|
+
const globalsBlockIndex = gl.getUniformBlockIndex(program, "Globals");
|
|
90
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, this._cameraBlockBindingPoint, ubo);
|
|
91
|
+
gl.uniformBlockBinding(program, globalsBlockIndex, this._globalsBlockBindingPoint);
|
|
92
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, this._globalsBlockBindingPoint, this._globalsbuffer);
|
|
93
|
+
|
|
94
|
+
// numaralarda yanlışlık olabilir
|
|
95
|
+
const start_position = gl.getAttribLocation(program, "start_position");
|
|
96
|
+
const start_time = gl.getAttribLocation(program, "start_time");
|
|
97
|
+
const start_color = gl.getAttribLocation(program, "start_color");
|
|
98
|
+
const end_position = gl.getAttribLocation(program, "end_position");
|
|
99
|
+
const end_time = gl.getAttribLocation(program, "end_time");
|
|
100
|
+
const end_color = gl.getAttribLocation(program, "end_color");
|
|
101
|
+
|
|
102
|
+
gl.bindVertexArray(this._vao);
|
|
103
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._attbuffer);
|
|
104
|
+
gl.enableVertexAttribArray(start_position);
|
|
105
|
+
gl.vertexAttribPointer(start_position, 3, gl.FLOAT, false, 72, 0);
|
|
106
|
+
gl.enableVertexAttribArray(start_time);
|
|
107
|
+
gl.vertexAttribPointer(start_time, 1, gl.FLOAT, false, 72, 12);
|
|
108
|
+
gl.enableVertexAttribArray(start_color);
|
|
109
|
+
gl.vertexAttribPointer(start_color, 3, gl.FLOAT, false, 72, 16);
|
|
110
|
+
gl.enableVertexAttribArray(end_position);
|
|
111
|
+
gl.vertexAttribPointer(end_position, 3, gl.FLOAT, false, 72, 36);
|
|
112
|
+
gl.enableVertexAttribArray(end_time);
|
|
113
|
+
gl.vertexAttribPointer(end_time, 1, gl.FLOAT, false, 72, 48);
|
|
114
|
+
gl.enableVertexAttribArray(end_color);
|
|
115
|
+
gl.vertexAttribPointer(end_color, 3, gl.FLOAT, false, 72, 52);
|
|
116
|
+
gl.bindVertexArray(null);
|
|
117
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
118
|
+
return program;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
setOpacity(opacity) {
|
|
123
|
+
const { gl, _globalsbuffer } = this;
|
|
124
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
125
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 4, new Float32Array([opacity]));
|
|
126
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
setDrawCount(count) {
|
|
130
|
+
this._drawCount = count;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
setPointSize(size) {
|
|
135
|
+
const { gl, _globalsbuffer } = this;
|
|
136
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
137
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 8, new Float32Array([size]));
|
|
138
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
setHeadTime(time) {
|
|
143
|
+
const { gl, _globalsbuffer } = this;
|
|
144
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
145
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([time]));
|
|
146
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
draw() {
|
|
151
|
+
const { gl, program, _vao, _drawCount } = this;
|
|
152
|
+
gl.useProgram(program);
|
|
153
|
+
gl.bindVertexArray(_vao);
|
|
154
|
+
gl.disable(gl.DEPTH_TEST);
|
|
155
|
+
gl.drawArrays(gl.POINTS, 0, _drawCount);
|
|
156
|
+
gl.enable(gl.DEPTH_TEST);
|
|
157
|
+
gl.bindVertexArray(null);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
free() {
|
|
162
|
+
const { gl, _vao, _globalsbuffer, program } = this;
|
|
163
|
+
gl.deleteVertexArray(_vao);
|
|
164
|
+
// gl.deleteBuffer(_attbuffer);
|
|
165
|
+
gl.deleteBuffer(_globalsbuffer);
|
|
166
|
+
gl.deleteProgram(program);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* todo:
|
|
3
|
+
* data must be processed before being set to the cache
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export default class DataManager {
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {Array<number>} timeEpocs | array of time epocs
|
|
10
|
+
* @param {Function} fetchMethod | fetchMethod(time) => Promise<data>
|
|
11
|
+
* @param {boolean} autoDownload | auto download data or not
|
|
12
|
+
*/
|
|
13
|
+
constructor(timeEpocs, fetchMethod, { autoDownload = true } = {}) {
|
|
14
|
+
|
|
15
|
+
this._timeEpocs = timeEpocs.sort((a, b) => a - b);
|
|
16
|
+
this._datas = []; this._datas.length = timeEpocs.length;
|
|
17
|
+
|
|
18
|
+
// in construction
|
|
19
|
+
this._dataPromises = []; this._dataPromises.length = timeEpocs.length;
|
|
20
|
+
|
|
21
|
+
this._fetchMethod = fetchMethod;
|
|
22
|
+
this._callbackmethods = [];
|
|
23
|
+
this._callbackmethodOwners = [];
|
|
24
|
+
this._lastTime = -1;
|
|
25
|
+
this._lastIndex = -1;
|
|
26
|
+
this.autoDownload(autoDownload);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
autoDownload(bool, time) {
|
|
31
|
+
if (!bool) {
|
|
32
|
+
this._autoDownload = false;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let index = this._lastIndex === -1 ? 0 : this._lastIndex;
|
|
36
|
+
if (time !== undefined) {
|
|
37
|
+
if (time < this._timeEpocs[0] || time > this._timeEpocs[this._timeEpocs.length - 1]) {
|
|
38
|
+
this._autoDownload = bool;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
index = this._findIndex(time);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (this._downloadStartIndex === index && this._autoDownload === bool) return;
|
|
45
|
+
this._downloadStartIndex = index;
|
|
46
|
+
this._autoDownload = bool;
|
|
47
|
+
const recursion = (startId, currentDownloadId) => {
|
|
48
|
+
if (startId !== this._downloadStartIndex) return;
|
|
49
|
+
if (currentDownloadId < this._timeEpocs.length && this._autoDownload) {
|
|
50
|
+
this._getData(currentDownloadId).then(() => {
|
|
51
|
+
recursion(startId, currentDownloadId + 1);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
recursion(index, index);
|
|
56
|
+
// save index as start index
|
|
57
|
+
//start recursive download
|
|
58
|
+
|
|
59
|
+
// use started id as a flag to stop the download
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {number} time
|
|
66
|
+
* It looks like async function is not needed here. changes just overwrites the previous changes.
|
|
67
|
+
*/
|
|
68
|
+
updateTime(time) {
|
|
69
|
+
if (time < this._timeEpocs[0] || time > this._timeEpocs[this._timeEpocs.length - 1]) {
|
|
70
|
+
this._dontRender();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this._lastTime = time;
|
|
74
|
+
const index = this._findIndex(time);
|
|
75
|
+
const ratio = this._getRatio(time, index);
|
|
76
|
+
Promise.all([this._getData(index - 1), this._getData(index)]).then((datas) => {
|
|
77
|
+
if (this._lastTime === time) {
|
|
78
|
+
this._lastIndex = index;
|
|
79
|
+
this._ratio = ratio;
|
|
80
|
+
this._pushCallback(ratio, datas);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
register(key, callback) {
|
|
87
|
+
if (this._callbackmethodOwners.indexOf(key) !== -1) {
|
|
88
|
+
console.warn("key already registered, old one is unregistered");
|
|
89
|
+
this.unregister(key);
|
|
90
|
+
}
|
|
91
|
+
this._callbackmethods.push(callback);
|
|
92
|
+
this._callbackmethodOwners.push(key);
|
|
93
|
+
if (this._lastIndex !== -1) callback(this._ratio, this._datas[this._lastIndex - 1], this._datas[this._lastIndex]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {*} key | id of the owner of the callback
|
|
99
|
+
*/
|
|
100
|
+
unregister(key) {
|
|
101
|
+
let index = this._callbackmethodOwners.indexOf(key);
|
|
102
|
+
if (index !== -1) {
|
|
103
|
+
this._callbackmethods.splice(index, 1);
|
|
104
|
+
this._callbackmethodOwners.splice(index, 1);
|
|
105
|
+
}
|
|
106
|
+
if (this._callbackmethods.length === 0) {
|
|
107
|
+
this.free();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
free() {
|
|
113
|
+
this._callbackmethods = [];
|
|
114
|
+
this._callbackmethodOwners = [];
|
|
115
|
+
this._autoDownload = false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
_findIndex(time) {
|
|
119
|
+
const { _timeEpocs } = this;
|
|
120
|
+
let index = this._lastIndex === -1 ? 1 : this._lastIndex;
|
|
121
|
+
if (this)
|
|
122
|
+
if (time < _timeEpocs[index - 1]) {
|
|
123
|
+
while (index > 1 && time < _timeEpocs[index - 1]) {
|
|
124
|
+
index--;
|
|
125
|
+
}
|
|
126
|
+
} else if (time > _timeEpocs[index]) {
|
|
127
|
+
while (index < _timeEpocs.length - 1 && time > _timeEpocs[index]) {
|
|
128
|
+
index++;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return index;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
_getRatio(time, index) {
|
|
136
|
+
return (time - this._timeEpocs[index - 1]) / (this._timeEpocs[index] - this._timeEpocs[index - 1]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
_pushCallback(ratio, datas) {
|
|
141
|
+
for (let i = 0; i < this._callbackmethods.length; i++) {
|
|
142
|
+
this._callbackmethods[i](ratio, ...datas);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
async _getData(index) {
|
|
148
|
+
if (index < 0 || index >= this._timeEpocs.length) {
|
|
149
|
+
throw new Error("Index out of range");
|
|
150
|
+
}
|
|
151
|
+
if (!this._datas[index]) {
|
|
152
|
+
if (!this._dataPromises[index]) this._dataPromises[index] = this._fetchMethod(this._timeEpocs[index]).then((data) => {
|
|
153
|
+
this._datas[index] = data;
|
|
154
|
+
}, (error) => {
|
|
155
|
+
console.error("error", error);
|
|
156
|
+
}).finally(() => {
|
|
157
|
+
this._dataPromises[index] = null;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
await this._dataPromises[index];
|
|
161
|
+
return this._datas[index];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
_dontRender() {
|
|
165
|
+
this._pushCallback(0, [null, null]);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import PointCoordsMeta from "./pointcoordsmeta";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const pointObject = (long, lat, posIndex, callback) => {
|
|
5
|
+
return { long, lat, posIndex, callback };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default class PointCoordinatesDataCalculator {
|
|
9
|
+
constructor(bbox, width, height) {
|
|
10
|
+
this._pointObjects = {};
|
|
11
|
+
|
|
12
|
+
this._ratio = 0.0;
|
|
13
|
+
|
|
14
|
+
this._bbox = bbox;
|
|
15
|
+
this._width = width;
|
|
16
|
+
this._height = height;
|
|
17
|
+
this._metaCalculater = new PointCoordsMeta(bbox, width, height);
|
|
18
|
+
|
|
19
|
+
this._texture0 = null;
|
|
20
|
+
this._texture1 = null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param {*} key
|
|
26
|
+
* @param {*} lat
|
|
27
|
+
* @param {*} long
|
|
28
|
+
* @param {*} callback | callback(data0, data1, interpolated)
|
|
29
|
+
*/
|
|
30
|
+
registerPoint(key, long, lat, callback) {
|
|
31
|
+
if (key in this._pointObjects) {
|
|
32
|
+
console.warn("key already registered, old one is unregistered");
|
|
33
|
+
this.unregisterPoint(key);
|
|
34
|
+
}
|
|
35
|
+
if (!this._isInBBox(long, lat)) return false;
|
|
36
|
+
|
|
37
|
+
const meta = this._metaCalculater.getFlooredMeta(long, lat)
|
|
38
|
+
|
|
39
|
+
this._pointObjects[key] = pointObject(long, lat, meta.index, callback);
|
|
40
|
+
if (this._texture0 && this._texture1) {
|
|
41
|
+
const { data0, data1, interpolated } = this._findAPoint(meta.index);
|
|
42
|
+
callback(data0, data1, interpolated);
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
_isInBBox(long, lat) {
|
|
48
|
+
return lat >= this._bbox[1] && lat <= this._bbox[3] && long >= this._bbox[0] && long <= this._bbox[2];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
unregisterPoint(key) {
|
|
53
|
+
if (!(key in this._pointObjects)) return false;
|
|
54
|
+
delete this._pointObjects[key];
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
updatePoint(key, long, lat) {
|
|
59
|
+
|
|
60
|
+
if (!(key in this._pointObjects)) return false;
|
|
61
|
+
if (!this._isInBBox(long, lat)) return false;
|
|
62
|
+
this._pointObjects[key].long = long;
|
|
63
|
+
this._pointObjects[key].lat = lat;
|
|
64
|
+
const meta = this._metaCalculater.getFlooredMeta(long, lat);
|
|
65
|
+
this._pointObjects[key].posIndex = meta.index;
|
|
66
|
+
const { data0, data1, interpolated } = this._findAPoint(meta.index);
|
|
67
|
+
this._pointObjects[key].callback(data0, data1, interpolated);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {Number} ratio 0-1
|
|
73
|
+
* @param {} textureData0
|
|
74
|
+
* @param {*} textureData1
|
|
75
|
+
*/
|
|
76
|
+
updateData(ratio, textureData0 = null, textureData1 = null) {
|
|
77
|
+
if (!textureData0 && !textureData1) {
|
|
78
|
+
this._pushPointCallBackEmpty();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (textureData0 && textureData1) {
|
|
82
|
+
this._texture0 = textureData0;
|
|
83
|
+
this._texture1 = textureData1;
|
|
84
|
+
}
|
|
85
|
+
this._ratio = ratio;
|
|
86
|
+
this._pushPointCallbackAll();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
_findAPoint(posIndex) {
|
|
91
|
+
const data0 = this._texture0[posIndex];
|
|
92
|
+
const data1 = this._texture1[posIndex];
|
|
93
|
+
const interpolated = data0 * (1 - this._ratio) + data1 * this._ratio;
|
|
94
|
+
return { data0, data1, interpolated };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_pushPointCallbackAll() {
|
|
98
|
+
for (const key in this._pointObjects) {
|
|
99
|
+
const { posIndex, callback } = this._pointObjects[key];
|
|
100
|
+
const { data0, data1, interpolated } = this._findAPoint(posIndex);
|
|
101
|
+
callback(data0, data1, interpolated);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_pushPointCallBackEmpty() {
|
|
106
|
+
for (const key in this._pointObjects) {
|
|
107
|
+
const { callback } = this._pointObjects[key];
|
|
108
|
+
callback(null, null, null);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
flush() {
|
|
113
|
+
this._pointObjects = {};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function test() {
|
|
118
|
+
const cp = window.plugin.getPointCoordinatesDataCalculator();
|
|
119
|
+
const bbox = [-15, 25, 70, 60];
|
|
120
|
+
cp.registerPoint("left up", -15, 60, (data0, data1, interpolated) => {
|
|
121
|
+
console.log("left up", data0, data1, interpolated);
|
|
122
|
+
});
|
|
123
|
+
cp.registerPoint("right up", 70, 60, (data0, data1, interpolated) => {
|
|
124
|
+
console.log("right up", data0, data1, interpolated);
|
|
125
|
+
});
|
|
126
|
+
cp.registerPoint("left down", -15, 25, (data0, data1, interpolated) => {
|
|
127
|
+
console.log("right down", data0, data1, interpolated);
|
|
128
|
+
});
|
|
129
|
+
cp.registerPoint("right down", 70, 25, (data0, data1, interpolated) => {
|
|
130
|
+
console.log("right down", data0, data1, interpolated);
|
|
131
|
+
});
|
|
132
|
+
return cp;
|
|
133
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default class PointCoordsMeta {
|
|
2
|
+
|
|
3
|
+
constructor(bbox, width, height) {
|
|
4
|
+
this._bbox = bbox;
|
|
5
|
+
this._width = width;
|
|
6
|
+
this._height = height;
|
|
7
|
+
this._xRatio = this._width / (this._bbox[2] - this._bbox[0]);
|
|
8
|
+
this._yRatio = this._height / (this._bbox[3] - this._bbox[1]);
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
getFlooredMeta(long, lat) {
|
|
13
|
+
let x = (long - this._bbox[0]) * this._xRatio;
|
|
14
|
+
let y = (this._bbox[3] - lat) * this._yRatio;
|
|
15
|
+
x = x > 0 ? x - 1 : 0;
|
|
16
|
+
y = y > 0 ? y - 1 : 0;
|
|
17
|
+
const index = Math.floor(y) * this._width + Math.floor(x);
|
|
18
|
+
return { index };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class GeoDataFromTexture {
|
|
2
|
+
/**
|
|
3
|
+
* @param {Array} bbox - [minLong, minLat, maxLong, maxLat]
|
|
4
|
+
* @param {Array} textureData - array of data
|
|
5
|
+
* @param {Number} width - width of the texture
|
|
6
|
+
* @param {Number} height - height of the texture
|
|
7
|
+
* */
|
|
8
|
+
constructor(bbox, textureData, width, height) {
|
|
9
|
+
this.bbox = null;
|
|
10
|
+
this.textureData = textureData;
|
|
11
|
+
this.width = width;
|
|
12
|
+
this.height = height;
|
|
13
|
+
this.setBBox(bbox);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setBBox(bbox) {
|
|
17
|
+
this.bbox = bbox;
|
|
18
|
+
this._longRatio = (this.bbox[2] - this.bbox[0]) / this.width;
|
|
19
|
+
|
|
20
|
+
this._latRatio = (this.bbox[3] - this.bbox[1]) / this.height;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setTextureData(textureData) {
|
|
24
|
+
this.textureData = textureData;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getFloored(lat, long) {
|
|
28
|
+
const x = (long - this.bbox[0]) / this._longRatio;
|
|
29
|
+
const y = (lat - this.bbox[1]) / this._latRatio;
|
|
30
|
+
console.log(x + " = (" + long + " - " + this.bbox[0] + ") / " + this._longRatio);
|
|
31
|
+
console.log(y + " = (" + lat + " - " + this.bbox[1] + ") / " + this._latRatio);
|
|
32
|
+
const index = Math.floor(y) * this.width + Math.floor(x);
|
|
33
|
+
console.log({ index, x, y, w: this.width, h: this.height, "total": this.width * this.height });
|
|
34
|
+
return this.textureData[index];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getInterpolated(lat, long) {
|
|
38
|
+
// this has bug for the last row and column
|
|
39
|
+
const x = (long - this.bbox[0]) / (this.bbox[2] - this.bbox[0]);
|
|
40
|
+
const y = (lat - this.bbox[1]) / (this.bbox[3] - this.bbox[1]);
|
|
41
|
+
const xIndex = Math.floor(x * this.width);
|
|
42
|
+
const yIndex = Math.floor(y * this.height);
|
|
43
|
+
const xRatio = x * this.width - xIndex;
|
|
44
|
+
const yRatio = y * this.height - yIndex;
|
|
45
|
+
const index = yIndex * this.width + xIndex;
|
|
46
|
+
const data = this.textureData[index];
|
|
47
|
+
const data1 = this.textureData[index + 1];
|
|
48
|
+
const data2 = this.textureData[index + this.width];
|
|
49
|
+
const data3 = this.textureData[index + this.width + 1];
|
|
50
|
+
return data * (1 - xRatio) * (1 - yRatio) + data1 * xRatio * (1 - yRatio) + data2 * (1 - xRatio) * yRatio + data3 * xRatio * yRatio;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const PI_BY_180 = Math.PI / 180;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export function latLongToPixelXY(latitude, longitude) {
|
|
7
|
+
return {
|
|
8
|
+
x: (longitude + 180) / 360,
|
|
9
|
+
y: (90 - latitude) / 180
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// export function latLongToRadiansTwist(latitude, longitude) {
|
|
15
|
+
|
|
16
|
+
// return {
|
|
17
|
+
// y: (90 - latitude) * PI_BY_180,
|
|
18
|
+
// x: longitude * PI_BY_180
|
|
19
|
+
// };
|
|
20
|
+
// }
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* createBBoxMatrix( minX, maxX, minY, maxY)
|
|
25
|
+
* use this matrix to transform a point from 0 to 1 range to the bounding box
|
|
26
|
+
* for example: Transform image coordinates to map coordinates
|
|
27
|
+
* glsl`vec3 pos = u_bbox_matrix * vec3(v_particle_pos.x, v_particle_pos.y, 1.0);`
|
|
28
|
+
*/
|
|
29
|
+
export function createBBoxMatrix(minX, maxX, minY, maxY) {
|
|
30
|
+
return new Float32Array([
|
|
31
|
+
maxX - minX, 0, 0,
|
|
32
|
+
0, maxY - minY, 0,
|
|
33
|
+
minX, minY, 1
|
|
34
|
+
])
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function latLongBboxtoPixelXYBbox(minX, minY, maxX, maxY) {
|
|
38
|
+
const minXY = latLongToPixelXY(minY, minX);
|
|
39
|
+
const maxXY = latLongToPixelXY(maxY, maxX);
|
|
40
|
+
return createBBoxMatrix(minXY.x, maxXY.x, minXY.y, maxXY.y);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export { GeoDataFromTexture } from './geodatafromtexture';
|
package/util/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as webglobjectbuilders from './webglobjectbuilders';
|
|
2
|
+
import * as shaderfunctions from './shaderfunctions';
|
|
3
|
+
import * as geometry from './geometry';
|
|
4
|
+
import * as webglobe from './webglobe';
|
|
5
|
+
import * as programs from './programs';
|
|
6
|
+
import * as DataManagers from './datamanager';
|
|
7
|
+
export { webglobjectbuilders, shaderfunctions, geometry, webglobe, programs, DataManagers };
|
|
8
|
+
export * from './webglobe';
|
|
9
|
+
export * from './webglobjectbuilders';
|
|
10
|
+
export * from './shaderfunctions';
|
|
11
|
+
export * from './geometry';
|
|
12
|
+
export * from './programs';
|
|
13
|
+
export * from './datamanager';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as timefilters from './timefilters';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// TODO: fix logic error in instantDebounce
|
|
2
|
+
function instantDebounce(func, delay) {
|
|
3
|
+
let timeout = null;
|
|
4
|
+
let lastArgs = null;
|
|
5
|
+
let runAtEnd = false;
|
|
6
|
+
|
|
7
|
+
const timeoutMethod = () => {
|
|
8
|
+
setTimeout(() => {
|
|
9
|
+
if (runAtEnd) {
|
|
10
|
+
func(...lastArgs);
|
|
11
|
+
lastArgs = null;
|
|
12
|
+
console.log("processed with delay")
|
|
13
|
+
runAtEnd = false;
|
|
14
|
+
}
|
|
15
|
+
timeout = null;
|
|
16
|
+
}, delay);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return function () {
|
|
20
|
+
if (timeout) {
|
|
21
|
+
lastArgs = arguments;
|
|
22
|
+
runAtEnd = true;
|
|
23
|
+
return;
|
|
24
|
+
} else {
|
|
25
|
+
func(...args);
|
|
26
|
+
console.log("processed instantly")
|
|
27
|
+
timeout = timeoutMethod();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { instantDebounce };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function instantDebounce(func, delay) {
|
|
2
|
+
let timeout = null;
|
|
3
|
+
let lastArgs = null;
|
|
4
|
+
return function (arguments) {
|
|
5
|
+
if (timeout) {
|
|
6
|
+
lastArgs = arguments;
|
|
7
|
+
return;
|
|
8
|
+
} else {
|
|
9
|
+
func(...arguments);
|
|
10
|
+
timeout = setTimeout(() => {
|
|
11
|
+
if (lastArgs) {
|
|
12
|
+
func(...lastArgs);
|
|
13
|
+
lastArgs = null;
|
|
14
|
+
}
|
|
15
|
+
timeout = null;
|
|
16
|
+
}, delay);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|