@pirireis/webglobeplugins 0.15.22-alpha → 0.15.25

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/wind/plugin.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Author: Toprak Nihat Deniz Ozturk
3
3
  */
4
4
  import * as util from "../util";
5
- import imageToMagnitude from "./imagetovectorfieldandmagnitude";
5
+ import imageToMagnitude, { imageToRadianAngle } from "./imagetovectorfieldandmagnitude";
6
6
  import { TexturePointSampler } from "../util/heatwavedatamanager/texture-point-sampler";
7
7
  /**
8
8
  * Shader Dökümanı:
@@ -54,6 +54,9 @@ varying vec2 v_tex_pos;
54
54
  void main() {
55
55
  vec4 color = texture2D(u_screen, 1.0 - v_tex_pos);
56
56
  // a hack to guarantee opacity fade out even with a value close to 1.0
57
+ if ( color.a < 0.005) {
58
+ discard;
59
+ }
57
60
  gl_FragColor = vec4( floor(255.0 * color * u_opacity) / 255.0);
58
61
  }
59
62
 
@@ -82,15 +85,15 @@ float rand(const vec2 co) {
82
85
 
83
86
  // wind speed lookup; use manual bilinear filtering based on 4 adjacent pixels for smooth interpolation
84
87
  vec2 lookup_wind(const vec2 uv) {
85
- // return texture2D(u_wind, uv).rg; // lower-res hardware filtering
86
- vec2 px = 1.0 / u_wind_res;
87
- vec2 vc = (floor(uv * u_wind_res)) * px;
88
- vec2 f = fract(uv * u_wind_res);
89
- vec2 tl = texture2D(u_wind, vc).rg;
90
- vec2 tr = texture2D(u_wind, vc + vec2(px.x, 0)).rg;
91
- vec2 bl = texture2D(u_wind, vc + vec2(0, px.y)).rg;
92
- vec2 br = texture2D(u_wind, vc + px).rg;
93
- return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);
88
+ return texture2D(u_wind, uv).rg; // lower-res hardware filtering
89
+ // vec2 px = 1.0 / u_wind_res;
90
+ // vec2 vc = (floor(uv * u_wind_res)) * px;
91
+ // vec2 f = fract(uv * u_wind_res);
92
+ // vec2 tl = texture2D(u_wind, vc).rg;
93
+ // vec2 tr = texture2D(u_wind, vc + vec2(px.x, 0)).rg;
94
+ // vec2 bl = texture2D(u_wind, vc + vec2(0, px.y)).rg;
95
+ // vec2 br = texture2D(u_wind, vc + px).rg;
96
+ // return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);
94
97
  }
95
98
 
96
99
  void main() {
@@ -218,13 +221,16 @@ void main() {
218
221
  color.r / 255.0 + color.b,
219
222
  color.g / 255.0 + color.a);
220
223
 
221
-
222
- if ( v_particle_pos.y < 0.0265 || v_particle_pos.y > 0.9735 ) {
224
+
225
+ // if ( v_particle_pos.y < 0.0265 || v_particle_pos.y > 0.9735 ) {
226
+ float y = v_particle_pos.y - 0.0055;//a
227
+ if ( y > 0.9735 || y < 0.0265 ) {
223
228
  gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);
224
229
  return;
225
230
  }
226
- vec3 pos = u_bbox_matrix * vec3(v_particle_pos.x, v_particle_pos.y, 1.0);
227
-
231
+ // vec3 pos = u_bbox_matrix * vec3(v_particle_pos.x, v_particle_pos.y, 1.0);
232
+ vec3 pos = u_bbox_matrix * vec3(v_particle_pos.x, y, 1.0);
233
+
228
234
 
229
235
  float xRad = PI * (2.0 * pos.x - 1.0);
230
236
  float yRad = pos.y * PI;
@@ -267,12 +273,12 @@ void main() {
267
273
  v_particle_pos = vec2(
268
274
  color.r / 255.0 + color.b,
269
275
  color.g / 255.0 + color.a);
270
-
271
- if ( v_particle_pos.y < 0.0265 || v_particle_pos.y > 0.9735 ) {
276
+ float y = v_particle_pos.y - 0.0055;//a
277
+ if ( y < 0.0265 || y > 0.9735 ) {
272
278
  gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);
273
279
  return;
274
280
  }
275
- vec3 pos = u_bbox_matrix * vec3(v_particle_pos.x, v_particle_pos.y, 1.0);
281
+ vec3 pos = u_bbox_matrix * vec3(v_particle_pos.x, y, 1.0);
276
282
 
277
283
  float x = (2.0 * pos.x - 1.0);
278
284
  float mercator_x = x * POLE;
@@ -505,6 +511,7 @@ export default class WindPlugin {
505
511
  gl.uniform2f(this.updateProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
506
512
  gl.uniform2f(this.updateProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
507
513
  this.setGeometry();
514
+ console.log("windData bbox", windData.bbox);
508
515
  const minXY = this._latLongToPixelXY(windDataMeta.bbox[1], windDataMeta.bbox[0]);
509
516
  const maxXY = this._latLongToPixelXY(windDataMeta.bbox[3], windDataMeta.bbox[2]);
510
517
  this._loadBoundingBoxData(minXY.x, minXY.y, maxXY.x, maxXY.y);
@@ -531,22 +538,49 @@ export default class WindPlugin {
531
538
  this.setWind(windData);
532
539
  };
533
540
  }
534
- getTexturePointSampler() {
535
- if (!this.texturePointSampler)
536
- this._createTexturePointSampler();
537
- return this.texturePointSampler;
541
+ /**
542
+ * @param
543
+ * @returns
544
+ */
545
+ getTexturePointSampler(type = `magnitude`) {
546
+ if (type == `magnitude`) {
547
+ if (!this.texturePointSampler) {
548
+ this._createTexturePointSampler();
549
+ this._setCoorcinatesDataCalculatorData();
550
+ }
551
+ return this.texturePointSampler;
552
+ }
553
+ else if (type == `angle`) {
554
+ if (!this.texturePointSamplerAngle) {
555
+ this._createTexturePointSamplerAngle();
556
+ this._setCoorcinatesDataCalculatorData();
557
+ }
558
+ return this.texturePointSamplerAngle;
559
+ }
560
+ else {
561
+ throw new Error(`WindPlugin.getTexturePointSampler: type must be either 'magnitude' or 'angle'.`);
562
+ }
563
+ }
564
+ _createTexturePointSamplerAngle() {
565
+ const { bbox, width, height } = this._windDataMeta;
566
+ this.texturePointSamplerAngle = new TexturePointSampler(bbox, width, height);
538
567
  }
539
568
  _createTexturePointSampler() {
540
569
  const { bbox, width, height } = this._windDataMeta;
541
570
  this.texturePointSampler = new TexturePointSampler(bbox, width, height);
542
- this._setCoorcinatesDataCalculatorData();
543
571
  }
544
572
  _setCoorcinatesDataCalculatorData() {
545
- if (!this.windData || !this.texturePointSampler) {
573
+ if (!this.windData) {
546
574
  return;
547
575
  }
548
- const magnitude = imageToMagnitude(this.windData);
549
- this.texturePointSampler.updateTextureData(0, magnitude, magnitude);
576
+ if (this.texturePointSamplerAngle) {
577
+ const angle = imageToRadianAngle(this.windData);
578
+ this.texturePointSamplerAngle.updateTextureData(0, angle, angle);
579
+ }
580
+ if (this.texturePointSampler) {
581
+ const magnitude = imageToMagnitude(this.windData);
582
+ this.texturePointSampler.updateTextureData(0, magnitude, magnitude);
583
+ }
550
584
  }
551
585
  // -----------------------------------------------
552
586
  // --- inner methods ---
@@ -0,0 +1,140 @@
1
+ // @ts-ignore
2
+ import { CSZMode } from "@pirireis/webglobe";
3
+ import { isTextFont, opacityCheck } from "../util/check/typecheck";
4
+ /**
5
+ * TODOs:
6
+ * 1) update all if initials change (propably need a context and a callback to iterate over zPayload)
7
+ * 2) expose a mechanic to update text on zoom change
8
+ * 3) extend the mechanic on 2 to other events
9
+ *
10
+ * TODO: key check and raise error if doesnt exist
11
+ */
12
+ const defaultStyle = {
13
+ textFont: {
14
+ name: 'Arial',
15
+ textColor: '#FFFFFF', // beyaz
16
+ hollowColor: '#000000', // siyah
17
+ size: 12, // piksel
18
+ hollow: true,
19
+ bold: true,
20
+ italic: false,
21
+ },
22
+ opacity: 1.0,
23
+ zMode: CSZMode.Z_GROUND_PERVERTEX,
24
+ };
25
+ // xOffset = 0,
26
+ // yOffset = 0,
27
+ // doDraw = true,
28
+ // textAdaptor = null,
29
+ // coordinatesAdaptor = null,
30
+ // keyAdaptor = null,
31
+ // opacityAdaptor = null,
32
+ // angleAdaptor = null,
33
+ // angleOnSphere = false,
34
+ // positionAdaptor = (item: any, i: number, container: any[], properties?: any): string => "left",
35
+ export class ContextTextWriter4 {
36
+ globe;
37
+ itemMap;
38
+ style;
39
+ doDraw;
40
+ textAdaptor;
41
+ deleteAdaptor;
42
+ zoomLevelAdaptor;
43
+ xOffset;
44
+ yOffset;
45
+ angleOptions;
46
+ constructor(globe, textAdaptor, deleteAdaptor, zoomLevelAdaptor = (zoomLevel) => (item) => {
47
+ return {
48
+ opacityMultiplier: 1,
49
+ sizeMultiplier: 1
50
+ };
51
+ }, style = defaultStyle, angleOptions = {
52
+ angleOnSphere: false,
53
+ angleIsOn: false
54
+ }, doDraw = true, offset = { x: 0, y: 0 }) {
55
+ this.globe = globe;
56
+ this.itemMap = new Map();
57
+ this.setStyle(style);
58
+ this.angleOptions = angleOptions;
59
+ this.doDraw = doDraw;
60
+ this.style = style;
61
+ this.angleOptions = angleOptions;
62
+ this.textAdaptor = textAdaptor;
63
+ this.deleteAdaptor = deleteAdaptor;
64
+ this.zoomLevelAdaptor = zoomLevelAdaptor;
65
+ this.xOffset = offset.x;
66
+ this.yOffset = offset.y;
67
+ }
68
+ setDoDraw(bool) {
69
+ this.doDraw = bool;
70
+ this.globe.DrawRender();
71
+ }
72
+ setStyle(style) {
73
+ isTextFont(style.textFont);
74
+ opacityCheck(style.opacity); //TODO: use shallow copy
75
+ this.style = style;
76
+ this.globe.DrawRender();
77
+ }
78
+ setOpacity(opacity) {
79
+ this.style.opacity = opacity;
80
+ this.globe.DrawRender();
81
+ }
82
+ draw() {
83
+ if (!this.doDraw)
84
+ return;
85
+ const { globe, style, itemMap, xOffset, yOffset } = this;
86
+ const { textFont, opacity: opacity_ } = style;
87
+ const textSize = textFont.size;
88
+ const is3D = globe.api_GetCurrentGeometry() === 0;
89
+ const angleIsOn = is3D ? (this.angleOptions.angleIsOn && this.angleOptions.angleOnSphere) : (this.angleOptions.angleIsOn);
90
+ const zoomLevel = globe.api_GetCurrentLODWithDecimal();
91
+ const zoomAdaptor = this.zoomLevelAdaptor(zoomLevel);
92
+ for (const item of itemMap.values()) {
93
+ const { lat, long, text, opacity = null, angle = null, zPayload, position } = item;
94
+ const { x, y } = globe.api_GetScreenPointFromGeo({
95
+ long: long,
96
+ lat: lat,
97
+ z: 0,
98
+ }, style.zMode === CSZMode.Z_MSL);
99
+ const { opacityMultiplier, sizeMultiplier } = zoomAdaptor(zPayload);
100
+ const o = (opacity === null ? opacity_ : opacity * opacity_) * opacityMultiplier;
101
+ textFont.size = sizeMultiplier * textSize;
102
+ textFont.position = position;
103
+ if (x !== null && y !== null)
104
+ globe.api_DrawContextTextMultiLine(text, textFont, o, { x: x + xOffset, y: y - yOffset }, angleIsOn, angle);
105
+ }
106
+ textFont.size = textSize;
107
+ }
108
+ insertText(data) {
109
+ const textDatas = this.textAdaptor(data);
110
+ for (const textData of textDatas) {
111
+ this.itemMap.set(textData.key, textData);
112
+ }
113
+ }
114
+ insertTextBulk(datas) {
115
+ for (const data of datas) {
116
+ this.insertText(data);
117
+ }
118
+ }
119
+ deleteText(data) {
120
+ const key = this.deleteAdaptor ? this.deleteAdaptor(data) : data;
121
+ if (this.itemMap.has(key)) {
122
+ this.itemMap.delete(key);
123
+ }
124
+ }
125
+ deleteTextBulk(datas) {
126
+ for (const data of datas) {
127
+ this.deleteText(data);
128
+ }
129
+ }
130
+ setOffsets(x, y) {
131
+ this.xOffset = x;
132
+ this.yOffset = y;
133
+ }
134
+ clear() {
135
+ this.itemMap.clear();
136
+ }
137
+ free() {
138
+ this.itemMap = null;
139
+ }
140
+ }