@pirireis/webglobeplugins 0.6.24-a → 0.6.26-a

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.
@@ -13,8 +13,8 @@ export class PixelPaddingCompassPlugin {
13
13
 
14
14
  defaultProperties = {
15
15
  rgba: [1, 1, 1, 1],
16
- pixelRadiusBig: 250,
17
- pixelRadiusSmall: 200
16
+ pixelRadiusRatioBig: 0.8,
17
+ pixelRadiusRatioSmall: 0.6,
18
18
  },
19
19
  font = {
20
20
  name: 'Arial',
@@ -50,6 +50,7 @@ export class PixelPaddingCompassPlugin {
50
50
 
51
51
  init(globe, gl) {
52
52
  this.globe = globe;
53
+ this.resize();
53
54
  this.gl = gl;
54
55
  if (this.textAngleOn) {
55
56
  this._createTextWriter();
@@ -63,8 +64,8 @@ export class PixelPaddingCompassPlugin {
63
64
  * @param {number} long
64
65
  * @param {number} lat
65
66
  * @typedef properties
66
- * @property {number} pixelRadiusBig
67
- * @property {number} pixelRadiusSmall
67
+ * @property {number} pixelRadiusRatioBig
68
+ * @property {number} pixelRadiusRatioSmall
68
69
  * @property {[4 numbers between 0-1]} rgba
69
70
  */
70
71
  insert(key, long, lat, properties = null) {
@@ -115,13 +116,13 @@ export class PixelPaddingCompassPlugin {
115
116
  'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
116
117
  'adaptor': (item) => new Float32Array([item.x, item.y])
117
118
  }],
118
- ["pixelRadiusSmall", {
119
+ ["pixelRadiusRatioSmall", {
119
120
  'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
120
- 'adaptor': (item) => new Float32Array([item.properties.pixelRadiusSmall])
121
+ 'adaptor': (item) => new Float32Array([item.properties.pixelRadiusRatioSmall])
121
122
  }],
122
- ["pixelRadiusBig", {
123
+ ["pixelRadiusRatioBig", {
123
124
  'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
124
- 'adaptor': (item) => new Float32Array([item.properties.pixelRadiusBig])
125
+ 'adaptor': (item) => new Float32Array([item.properties.pixelRadiusRatioBig])
125
126
  }],
126
127
  ["rgba", {
127
128
  'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
@@ -134,7 +135,7 @@ export class PixelPaddingCompassPlugin {
134
135
  return { 'buffer': bufferManagerComp.bufferManager.buffer, 'stride': 0, 'offset': 0 }
135
136
  };
136
137
  this.paddingVao = this.paddingProgram.createVAO(
137
- ...['screenCoordinates', 'pixelRadiusSmall', 'pixelRadiusBig', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
138
+ ...['screenCoordinates', 'pixelRadiusRatioSmall', 'pixelRadiusRatioBig', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
138
139
  }
139
140
  }
140
141
 
@@ -143,15 +144,19 @@ export class PixelPaddingCompassPlugin {
143
144
  }
144
145
 
145
146
 
147
+ resize() {
148
+ this.writer?.resize();
149
+ }
150
+
146
151
 
147
152
  __insertText(key, x, y, { properties, update = false } = {}) {
148
153
  if (!this.writer) return;
149
154
  if (update) {
150
155
  let radius;
151
- if (properties != null && properties.pixelRadiusBig) {
152
- radius = properties.pixelRadiusBig
156
+ if (properties != null && properties.pixelRadiusRatioBig) {
157
+ radius = properties.pixelRadiusRatioBig * this.radiusMultiplier;
153
158
  } else {
154
- radius = this.defaultProperties.pixelRadiusBig;
159
+ radius = this.defaultProperties.pixelRadiusRatioBig * this.radiusMultiplier;
155
160
  }
156
161
  this.writer.insertTextItem(key, x, y, radius + textGapFit);
157
162
  } else {
@@ -185,6 +190,23 @@ export class PixelPaddingCompassPlugin {
185
190
  })
186
191
 
187
192
  }
193
+
194
+ resize() {
195
+ this.radiusMultiplier = this._shorterDimension() * 0.5;
196
+ this._reinsertAllText();
197
+ }
198
+
199
+
200
+ _reinsertAllText() {
201
+ this.compassMap.query(this.globe, this.writer).forEach((v) => {
202
+ this.__insertText(v.key, v.x, v.y, { properties: v.properties, update: true });
203
+ });
204
+ }
205
+
206
+ _shorterDimension() {
207
+ const globe = this.globe;
208
+ return Math.min(globe.api_ScrW(), globe.api_ScrH());
209
+ }
188
210
  }
189
211
 
190
212
 
@@ -1,4 +1,4 @@
1
- // import { CSZMode } from "@pirireis/webglobe";
1
+ import { CSZMode, CSMeasureTextPositionTypes } from "@pirireis/webglobe";
2
2
 
3
3
  // const defaultStyle = {
4
4
  // textFont: {
@@ -49,16 +49,25 @@ export class PixelPaddingCompassTextWriter {
49
49
  this.northFont = northFont;
50
50
  this.doDraw = doDraw;
51
51
  this.angle = angle;
52
-
52
+ console.log("CSMeasureTextPositionTypes", CSMeasureTextPositionTypes);
53
53
  this.angles = []
54
54
  this.texts = []
55
+ this.positions = []
55
56
  let currentAngle = 0;
56
57
  while (currentAngle < 360) {
58
+ if (currentAngle > 180) {
59
+ this.positions.push(CSMeasureTextPositionTypes.CENTER);
60
+ } else {
61
+ this.positions.push(null);
62
+ }
57
63
  this.angles.push(currentAngle);
58
64
  if (currentAngle == 0) {
59
65
  this.texts.push("K");
60
66
  } else {
61
- this.texts.push(currentAngle.toString());
67
+ // to string 3 chars fill left with 0
68
+
69
+
70
+ this.texts.push(currentAngle.toString().padStart(3, '0'));
62
71
  }
63
72
  currentAngle += this.angle;
64
73
  }
@@ -92,7 +101,6 @@ export class PixelPaddingCompassTextWriter {
92
101
  _checkSetOffsets() {
93
102
  const { globe } = this;
94
103
  const newAngle = globe.api_GetCurrentLookInfo()["NorthAng"] * (Math.PI / 180);;
95
- console.log("n angle", newAngle);
96
104
  if (newAngle !== this._lastNorthAngle) {
97
105
  this._lastNorthAngle = newAngle;
98
106
  this.offsets = this.__offset();
@@ -102,7 +110,7 @@ export class PixelPaddingCompassTextWriter {
102
110
 
103
111
  draw() {
104
112
  if (!this.doDraw) return;
105
- const { globe, font, opacity: opacity_, northFont, itemMap, texts, angles } = this;
113
+ const { globe, font, opacity: opacity_, northFont, itemMap, texts, angles, positions } = this;
106
114
  this._checkSetOffsets();// zMode: CSZMode.Z_GROUND_PERVERTEX,
107
115
  const offsets = this.offsets;
108
116
  for (const [key, { center, radius, opacity = null }] of itemMap) {
@@ -111,6 +119,7 @@ export class PixelPaddingCompassTextWriter {
111
119
  offsets.forEach(({ offsetX, offsetY }, i) => {
112
120
  const text = texts[i];
113
121
  const angle = angles[i];
122
+ font.position = positions[i];
114
123
  if (angle === 0) {
115
124
  globe.api_DrawContextTextMultiLine(text, northFont, o, { x: center.x + offsetX * radius + xGapFit, y: center.y + offsetY * radius + yGapFit });
116
125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.6.24-a",
3
+ "version": "0.6.26-a",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -1,5 +1,5 @@
1
1
  import { CameraUniformBlockTotemCache, CameraUniformBlockString } from "../totems";
2
- import { mercatorXYToGLPosition } from "../../util/shaderfunctions/geometrytransformations";
2
+ import { mercatorXYToGLPosition, POLE } from "../../util/shaderfunctions/geometrytransformations";
3
3
  import { noRegisterGlobeProgramCache } from "../programcache";
4
4
  import { createProgram } from "../../util";
5
5
  import { vaoAttributeLoader } from "../../util/account/util";
@@ -25,26 +25,29 @@ in vec2 posA;
25
25
  in vec2 posB;
26
26
  in vec4 color;
27
27
 
28
+ out vec2 v_frame;
28
29
  out vec4 v_color;
29
-
30
30
  void main() {
31
+
31
32
  if ( is3D ) {
32
33
  return;
33
34
  }
35
+ float gap = distance(posA, posB);
34
36
  float z_alpha;
35
- if ( z_alpha_on == 1){
36
- z_alpha = z_level * z_level / (distance(posA, posB) / 100.0 );
37
+ if ( z_alpha_on == 1 || gap > 40000000.0){
38
+ z_alpha = z_level * z_level / ( gap / 100.0 );
37
39
  if( z_alpha < 0.1 ) {return;}
38
40
  if( z_alpha > 1.0 ) {z_alpha = 1.0;}
39
41
  } else {
40
42
  z_alpha = 1.0;
41
43
  }
42
44
  vec2 pos;
43
- if ( gl_VertexID == 0 ) {
44
- pos = posA;
45
- } else {
46
- pos = posB;
47
- }
45
+ if ( gl_VertexID == 0 ) {
46
+ pos = posA;
47
+ } else {
48
+ pos = posB;
49
+ }
50
+ v_frame = pos;
48
51
  gl_Position = mercatorXYToGLPosition( pos );
49
52
  v_color = color;
50
53
  v_color.a *= z_alpha * opacity;
@@ -53,10 +56,14 @@ void main() {
53
56
 
54
57
 
55
58
  const fragmentShaderSource = `#version 300 es
59
+ ${POLE}
56
60
  precision highp float;
57
61
  in vec4 v_color;
62
+ in vec2 v_frame;
58
63
  out vec4 outColor;
59
64
  void main() {
65
+ if ( v_frame.x < -POLE || v_frame.x > POLE || v_frame.y < -POLE || v_frame.y > POLE ){ discard; }
66
+
60
67
  outColor = v_color;
61
68
  }`;
62
69
 
@@ -41,6 +41,7 @@ void main() {
41
41
  gl_Position = cartesian3DToGLPosition(cartesian);
42
42
  v_limp = vec2(0.0, 0.0);
43
43
  } else {
44
+ if ( distance( start_position, end_position) > 30000000.0) { return; }
44
45
  interpolation = float(gl_VertexID);
45
46
  if (gl_VertexID % 2 == 0) {
46
47
  longLat = start_position;
@@ -6,8 +6,8 @@ const vertexShaderSource = `#version 300 es
6
6
  ${CameraUniformBlockString}
7
7
 
8
8
  in vec2 screen_coordinate;
9
- in float pixel_radius_small;
10
- in float pixel_radius_big;
9
+ in float pixel_radius_small_ratio;
10
+ in float pixel_radius_big_ratio;
11
11
  in vec4 rgba;
12
12
  out vec4 v_rgba;
13
13
  uniform float plugin_opacity;
@@ -15,31 +15,31 @@ uniform float plugin_opacity;
15
15
  vec3 coord_opacity(){
16
16
  float radius;
17
17
  float angle;
18
- float gap = (pixel_radius_big - pixel_radius_small);
18
+ float gap = (pixel_radius_big_ratio - pixel_radius_small_ratio);
19
19
  if( gl_VertexID % 2 == 0){
20
- if( gl_VertexID % 180 == 0){
21
- radius = pixel_radius_small ;
22
- }
23
- else if ( gl_VertexID % 60 == 0){
24
- radius = pixel_radius_small + gap * 0.5;
20
+ // if( gl_VertexID % 180 == 0){
21
+ // radius = pixel_radius_small_ratio ;
22
+ // } else
23
+ if ( gl_VertexID % 60 == 0){
24
+ radius = pixel_radius_small_ratio;
25
25
  } else if( gl_VertexID % 10 == 0) {
26
- radius = pixel_radius_small + gap * 0.75;
26
+ radius = pixel_radius_small_ratio + gap * 0.5;
27
27
  } else {
28
- radius = pixel_radius_small + gap* 0.90;
28
+ radius = pixel_radius_small_ratio + gap* 0.75;
29
29
  }
30
30
  angle = (float(gl_VertexID) / (${vertexCount}.0));
31
31
  } else {
32
32
  if ( gl_VertexID % 180 == 1){
33
- radius = pixel_radius_big + gap * 0.1;
33
+ radius = pixel_radius_big_ratio + gap * 0.1;
34
34
 
35
35
  } else {
36
- radius = pixel_radius_big;
36
+ radius = pixel_radius_big_ratio;
37
37
  }
38
38
  angle = (float(gl_VertexID - 1) / (${vertexCount}.0));
39
39
  }
40
40
  float opacity = fract(angle + 0.2475) / 1.5 + 0.33;
41
41
  angle = angle * ${Math.PI * 2.0} + world_north_angle;
42
-
42
+ radius = radius * min(screenWH.x, screenWH.y) / 2.0;;
43
43
  return vec3( screen_coordinate + vec2( cos(angle), sin(angle)) * radius, opacity);
44
44
  }
45
45
 
@@ -78,13 +78,13 @@ class Logic {
78
78
  const { gl, program } = this;
79
79
  { // assign attribute locations
80
80
  // in vec2 screen_coordinate;
81
- // in float pixel_radius_small;
82
- // in float pixel_radius_big;
81
+ // in float pixel_radius_small_ratio;
82
+ // in float pixel_radius_big_ratio;
83
83
  // in vec4 rgba;
84
84
 
85
85
  gl.bindAttribLocation(program, 0, "screen_coordinate");
86
- gl.bindAttribLocation(program, 1, "pixel_radius_small");
87
- gl.bindAttribLocation(program, 2, "pixel_radius_big");
86
+ gl.bindAttribLocation(program, 1, "pixel_radius_small_ratio");
87
+ gl.bindAttribLocation(program, 2, "pixel_radius_big_ratio");
88
88
  gl.bindAttribLocation(program, 3, "rgba");
89
89
  }
90
90
  {
@@ -118,7 +118,7 @@ class Logic {
118
118
  cameraBlockTotem.unbind(cameraBlockBindingPoint);
119
119
  }
120
120
 
121
- createVAO(screenCoordsBufferObj, pixelRadiusSmallBufferObj, pixelRadiusBigBufferObj, rgbaBufferObj) {
121
+ createVAO(screenCoordsBufferObj, pixelRadiusRatioSmallBufferObj, pixelRadiusRatioBigBufferObj, rgbaBufferObj) {
122
122
  const { gl } = this;
123
123
  const vao = gl.createVertexArray();
124
124
  gl.bindVertexArray(vao);
@@ -130,14 +130,14 @@ class Logic {
130
130
  gl.vertexAttribDivisor(0, 1);
131
131
  }
132
132
  {
133
- const { buffer, stride = 0, offset = 0 } = pixelRadiusSmallBufferObj;
133
+ const { buffer, stride = 0, offset = 0 } = pixelRadiusRatioSmallBufferObj;
134
134
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
135
135
  gl.enableVertexAttribArray(1);
136
136
  gl.vertexAttribPointer(1, 1, gl.FLOAT, false, stride, offset);
137
137
  gl.vertexAttribDivisor(1, 1);
138
138
  }
139
139
  {
140
- const { buffer, stride = 0, offset = 0 } = pixelRadiusBigBufferObj;
140
+ const { buffer, stride = 0, offset = 0 } = pixelRadiusRatioBigBufferObj;
141
141
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
142
142
  gl.enableVertexAttribArray(2);
143
143
  gl.vertexAttribPointer(2, 1, gl.FLOAT, false, stride, offset);
@@ -356,7 +356,7 @@ export default class RangeRingAngleText {
356
356
  // fidkey is the key
357
357
  attribs.push({
358
358
  "__fid__": key,
359
- "aci": (360 - aci).toString()
359
+ "aci": (360 - aci).toString().padStart(3, '0')
360
360
  })
361
361
  aci += stepAngle;
362
362
  }
@@ -1,29 +0,0 @@
1
- // TODO: Implement compass rose in 2D
2
- // TODO: enrich cameraBlockTotem with globe tile and more...
3
-
4
- const vertexShader = `#version 300 es
5
-
6
-
7
- in vec2 center;
8
- in float pixel_radius;
9
- in vec4 color;
10
- out vec4 v_color;
11
- void main() {
12
- const float PI = 3.14159265359;
13
- float angle = float(gl_VertexID) / 180.0 * PI;
14
- vec2 limp = vec2(
15
-
16
- )
17
- vec2 position =
18
- v_color = color;
19
- }
20
- `;
21
-
22
- const fragmentShader = `#version 300 es
23
- precision mediump float;
24
- in vec4 v_color;
25
- out vec4 outColor;
26
- void main() {
27
- outColor = v_color;
28
- }
29
- `;