@pirireis/webglobeplugins 0.3.6 → 0.3.8

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.
@@ -102,6 +102,8 @@
102
102
 
103
103
  */
104
104
 
105
+ const EXTRA_SIZE = 10;
106
+
105
107
  export class BufferOrchestrator {
106
108
 
107
109
  constructor({ capacity = 10 } = {}) {
@@ -172,7 +174,7 @@ export class BufferOrchestrator {
172
174
  for (const [key, { bufferManager }] of bufferManagersMap) {
173
175
  bufferManager.deleteBulk(offsets);
174
176
  }
175
- console.log("deleteBulk after item size", this.offsetMap.size);
177
+ //console.log("deleteBulk after item size", this.offsetMap.size);
176
178
  }
177
179
 
178
180
 
@@ -196,9 +198,9 @@ export class BufferOrchestrator {
196
198
  autoExtendBuffers(itemsLength, bufferManagersMap) {
197
199
  if (itemsLength <= this.emptySpace) return;
198
200
  const newCapacity = this.length + itemsLength;
199
- console.log("autoExtendBuffers", "item L", itemsLength, "E space", this.emptySpace, "cap", this.capacity, "length", this.length, 'new Cap', newCapacity);
201
+ //console.log("autoExtendBuffers", "item L", itemsLength, "E space", this.emptySpace, "cap", this.capacity, "length", this.length, 'new Cap', newCapacity);
200
202
  for (const [key, { bufferManager }] of bufferManagersMap) {
201
- console.log("length", this.length, "newCapacity", newCapacity);
203
+ //console.log("length", this.length, "newCapacity", newCapacity);
202
204
  bufferManager.extendBuffer(this.length, newCapacity);
203
205
  }
204
206
  this._capacity = newCapacity;
@@ -207,23 +209,23 @@ export class BufferOrchestrator {
207
209
 
208
210
  defrag(bufferManagers, bufferKeys) { // TODO defrag and leave some empty space
209
211
  const offsetMap = this.offsetMap;
210
- console.log("defrag size", offsetMap.size, "cap", this.capacity, "length", this.length);
212
+ const newCapacity = offsetMap.size + EXTRA_SIZE;
211
213
  if (bufferKeys) {
212
214
  for (const key of bufferKeys) {
213
215
  const offset = offsetMap.get(key);
214
216
  if (offset !== undefined) {
215
217
  for (const [key, { bufferManager }] of bufferManagers) {
216
- bufferManager.defrag([offset], this.length, offsetMap.size);
218
+ bufferManager.defrag([offset], this.length, newCapacity);
217
219
  }
218
220
  }
219
221
  }
220
222
  } else {
221
223
  for (const [key, { bufferManager }] of bufferManagers) {
222
- bufferManager.defrag(offsetMap.values(), this.length, offsetMap.size);
224
+ bufferManager.defrag(offsetMap.values(), this.length, newCapacity);
223
225
  }
224
226
  }
225
227
  this._defrag();
226
- this._length = this._capacity = offsetMap.size;
228
+ this._length = this._capacity = newCapacity;
227
229
  this.tombstoneOffsets = [];
228
230
  }
229
231
 
@@ -233,7 +235,7 @@ export class BufferOrchestrator {
233
235
  const newOffsetMap = new Map();
234
236
  let newOffset = 0;
235
237
  for (const [key, offset] of this.offsetMap) {
236
- console.log("defrag", key, offset, newOffset);
238
+ //console.log("defrag", key, offset, newOffset);
237
239
  newOffsetMap.set(key, newOffset++);
238
240
  }
239
241
  this.offsetMap = newOffsetMap
@@ -27,10 +27,10 @@ export class GeoDataFromTexture {
27
27
  getFloored(lat, long) {
28
28
  const x = (long - this.bbox[0]) / this._longRatio;
29
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);
30
+ //console.log(x + " = (" + long + " - " + this.bbox[0] + ") / " + this._longRatio);
31
+ //console.log(y + " = (" + lat + " - " + this.bbox[1] + ") / " + this._latRatio);
32
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 });
33
+ //console.log({ index, x, y, w: this.width, h: this.height, "total": this.width * this.height });
34
34
  return this.textureData[index];
35
35
  }
36
36
 
@@ -9,7 +9,7 @@ function instantDebounce(func, delay) {
9
9
  if (runAtEnd) {
10
10
  func(...lastArgs);
11
11
  lastArgs = null;
12
- console.log("processed with delay")
12
+ // console.log("processed with delay")
13
13
  runAtEnd = false;
14
14
  }
15
15
  timeout = null;
@@ -23,7 +23,7 @@ function instantDebounce(func, delay) {
23
23
  return;
24
24
  } else {
25
25
  func(...args);
26
- console.log("processed instantly")
26
+ // console.log("processed instantly")
27
27
  timeout = timeoutMethod();
28
28
  }
29
29
  }
@@ -7,7 +7,7 @@ import { latLongBboxtoPixelXYBbox } from "..";
7
7
 
8
8
 
9
9
  class TextureToGlobeProgram {
10
- constructor (gl, globe) {
10
+ constructor(gl, globe) {
11
11
  this.globe = globe;
12
12
  this.gl = gl;
13
13
  this._is3D = true;
@@ -19,7 +19,7 @@ class TextureToGlobeProgram {
19
19
  }
20
20
 
21
21
  _initUniforms() {
22
-
22
+
23
23
  const { gl, _programWrapper } = this;
24
24
  const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
25
25
  gl.useProgram(_programWrapper.program);
@@ -32,7 +32,7 @@ class TextureToGlobeProgram {
32
32
  gl.uniform1f(_programWrapper.u_is3D, 1.0);
33
33
  gl.uniform1f(_programWrapper.height, 0.0);
34
34
  gl.useProgram(currentProgram);
35
-
35
+
36
36
  }
37
37
 
38
38
  _createProgramWrapper() {
@@ -94,7 +94,7 @@ class TextureToGlobeProgram {
94
94
 
95
95
  const program = createProgram(gl, vertexSource, fragmentSource);
96
96
  const vao = gl.createVertexArray();
97
-
97
+
98
98
  const buffer = gl.createBuffer();
99
99
  gl.bindVertexArray(vao);
100
100
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
@@ -104,7 +104,7 @@ class TextureToGlobeProgram {
104
104
  1, 1,
105
105
  0, 1
106
106
  ]), gl.STATIC_DRAW);
107
- const a_position =- gl.getAttribLocation(program, 'a_position');
107
+ const a_position = - gl.getAttribLocation(program, 'a_position');
108
108
  gl.enableVertexAttribArray(a_position);
109
109
  gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);
110
110
  gl.bindVertexArray(null);
@@ -123,8 +123,8 @@ class TextureToGlobeProgram {
123
123
  };
124
124
  }
125
125
 
126
- draw( modelViewMatrix, projectionMatrix, transPos, texture) {
127
- console.log('draw')
126
+ draw(modelViewMatrix, projectionMatrix, transPos, texture) {
127
+ // console.log('draw')
128
128
  const { gl, _programWrapper, _is3D } = this;
129
129
  gl.useProgram(_programWrapper.program);
130
130
  gl.bindVertexArray(_programWrapper.vao);
@@ -138,12 +138,12 @@ class TextureToGlobeProgram {
138
138
  const mapWH = this.globe.api_GetCurrentWorldWH();
139
139
  gl.uniform2f(_programWrapper.u_mapWH, mapWH.width, mapWH.height);
140
140
  }
141
-
141
+
142
142
  gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
143
143
  gl.drawArrays(gl.POINTS, 0, 4);
144
144
  }
145
-
146
- setBBox( minx, maxx, miny, maxy) {
145
+
146
+ setBBox(minx, maxx, miny, maxy) {
147
147
  const { gl, _programWrapper } = this;
148
148
  const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
149
149
  gl.useProgram(_programWrapper.program);
@@ -155,7 +155,7 @@ class TextureToGlobeProgram {
155
155
  gl.useProgram(currentProgram);
156
156
  }
157
157
 
158
- setLatLongBBox(minx, maxx, miny, maxy){
158
+ setLatLongBBox(minx, maxx, miny, maxy) {
159
159
  const bboxMatrix = latLongBboxtoPixelXYBbox(minx, miny, maxx, maxy);
160
160
  const { gl, _programWrapper } = this;
161
161
  const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
@@ -165,7 +165,7 @@ class TextureToGlobeProgram {
165
165
  }
166
166
 
167
167
 
168
- setScreenWH(){
168
+ setScreenWH() {
169
169
  const { gl, _programWrapper, globe } = this;
170
170
  const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
171
171
  gl.useProgram(_programWrapper.program);
@@ -179,7 +179,7 @@ class TextureToGlobeProgram {
179
179
  this.setScreenWH();
180
180
  }
181
181
 
182
- setGeometry( ){
182
+ setGeometry() {
183
183
  const { gl, globe, _programWrapper } = this;
184
184
  this._is3D = globe.api_GetCurrentGeometry() === 0;
185
185
  const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
@@ -189,15 +189,15 @@ class TextureToGlobeProgram {
189
189
  this.resize();
190
190
  }
191
191
 
192
- free(){
192
+ free() {
193
193
  window.removeEventListener('resize',
194
- this._resizeHandler, true);
194
+ this._resizeHandler, true);
195
195
  }
196
196
 
197
- _resizeEventHandler(){
197
+ _resizeEventHandler() {
198
198
  this.resize();
199
199
  }
200
200
 
201
201
  }
202
202
 
203
- export {TextureToGlobeProgram};
203
+ export { TextureToGlobeProgram };
@@ -112,7 +112,7 @@ vec3 circleLimpFromLongLatRadCenterCartesian3D( vec2 center, float radius, float
112
112
 
113
113
  export const circleLimpFromLongLatRadCenterMercatorRealDistance = PI + `
114
114
  vec2 circleLimpFromLongLatRadCenterMercatorRealDistance(vec2 center, float radius, float angle){
115
- float ang = angle + PI / 2.0; // this is there because rest of the program is in angle 0 is +x axis orientatation
115
+ float ang = angle + PI / 2.0; // this is there because the other methods are implemented in, angle 0 is +x axis orientatation
116
116
  float r = radius / R;
117
117
  float sin_lat = sin( center.y) * cos(r) + cos(center.y)*sin(r)* cos(ang);
118
118
  float lat = asin(sin_lat);
@@ -22,6 +22,7 @@ export class ContextTextWriter {
22
22
  this.doDraw = doDraw;
23
23
  }
24
24
 
25
+
25
26
  setDoDraw(bool) {
26
27
  this.doDraw = bool;
27
28
  }
@@ -42,8 +43,9 @@ export class ContextTextWriter {
42
43
  draw() {
43
44
  if (!this.doDraw) return;
44
45
  const { globe, style, itemMap } = this;
45
- const { textFont, opacity } = style;
46
- for (const [key, { lat, long, text }] of itemMap) {
46
+ const { textFont, opacity: opacity_ } = style;
47
+
48
+ for (const [key, { lat, long, text, opacity = null }] of itemMap) {
47
49
  const { x, y } = globe.api_GetScreenPointFromGeo(
48
50
  {
49
51
  long: long,
@@ -52,17 +54,30 @@ export class ContextTextWriter {
52
54
  },
53
55
  style.zMode === CSZMode.Z_MSL,
54
56
  );
55
-
56
- globe.api_DrawContextTextMultiLine(text, textFont, opacity, { x, y });
57
+ const o = opacity === null ? opacity_ : opacity * opacity_;
58
+ globe.api_DrawContextTextMultiLine(text, textFont, o, { x, y });
57
59
  }
58
60
  }
59
61
 
60
62
 
61
- insertText(key, lat, long, text) {
63
+ insertText(key, lat, long, text,) { // TODO: Make it more generic
62
64
  this.itemMap.set(key, { lat, long, text });
63
65
  }
64
66
 
65
67
 
68
+ updateOpacityOfItem(key, opacity) {
69
+ this.itemMap.get(key).opacity = opacity;
70
+ }
71
+
72
+ updateOpacityBulk(items, keyAdaptor, valueAdaptor) {
73
+ for (const item of items) {
74
+ const key = keyAdaptor(item);
75
+ const opacity = valueAdaptor(item);
76
+ const data = this.itemMap.get(key)
77
+ data.opacity = opacity;
78
+ }
79
+ }
80
+
66
81
  updateText(key, text) {
67
82
  const item = this.itemMap.get(key);
68
83
  item.text = text;
@@ -94,7 +109,11 @@ export class ContextTextWriter {
94
109
  }
95
110
  }
96
111
 
112
+
113
+
97
114
  clear() {
98
115
  this.itemMap.clear();
99
116
  }
100
- }
117
+ }
118
+
119
+