@pirireis/webglobeplugins 0.5.12 → 0.6.0

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.
@@ -1,38 +1,44 @@
1
1
  import { PixelPaddingForFlatCompassCache } from "../programs/two-d/pixel-padding-for-compass";
2
2
  import { BufferManager, BufferOrchestrator } from "../util/account";
3
3
  // import { ContextTextWriter2 } from "../write-text/context-text2";
4
- import { ContextTextWriter2Offsets } from "../write-text/context-text-2d-offsets"
4
+ import { ContextTextWriter2Offsets } from "./compass-text-writer"
5
+
6
+ const PaddingAngle = 30;
5
7
 
6
8
  export class PixelPaddingCompassPlugin {
7
9
  constructor(id, {
8
10
  opacity = 1,
9
- textAngle = null, defaultProperties = {
11
+ textAngle = true,
12
+ defaultProperties = {
10
13
  rgba: [1, 1, 1, 1],
11
14
  pixelRadiusBig: 350,
12
15
  pixelRadiusSmall: 270
13
16
  }
14
17
  } = {}) {
15
18
  this.id = id;
16
- this._textAngle = textAngle;
17
19
  this.textWriters = null
18
- if (textAngle == null) {
19
- this._createTextWriters();
20
- }
20
+ this.textAngle = textAngle
21
+ this.defaultProperties = defaultProperties
21
22
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
22
- this.compassMap = new CompassMap({ defaultProperties });
23
+
24
+ this.compassMap = new CompassMap(this);
23
25
  this._opacity = opacity;
24
26
  }
25
27
 
26
28
  init(globe, gl) {
27
29
  this.globe = globe;
28
30
  this.gl = gl;
29
-
31
+ if (this.textAngle) {
32
+ this._createTextWriter();
33
+ }
30
34
  this._initOrchestrations()
31
35
  }
32
36
 
33
37
  insert(key, long, lat, properties = null) {
38
+ this.__insertText(key, null, null, properties);
34
39
  this.compassMap.insert(key, long, lat, properties);
35
40
  this.globe.DrawRender();
41
+
36
42
  }
37
43
 
38
44
 
@@ -42,14 +48,9 @@ export class PixelPaddingCompassPlugin {
42
48
  }
43
49
 
44
50
 
45
- setTextAngle(textAngle) {
46
- this._textAngle = textAngle;
47
- this._createTextWriters();
48
- this.globe.DrawRender();
49
- }
50
51
 
51
52
  setTextStyle(textStyle) {
52
- this.textWriters?.forEach((writer) => writer.setStyle(textStyle));
53
+ this.writer.setStyle(textStyle);
53
54
  this.globe.DrawRender();
54
55
  }
55
56
 
@@ -94,48 +95,53 @@ export class PixelPaddingCompassPlugin {
94
95
  }
95
96
  }
96
97
 
97
- _createTextWriters() {
98
- this.writer = new ContextTextWriter2Offsets(this.globe);
98
+ _createTextWriter() {
99
+ this.writer = new ContextTextWriter2Offsets(this.globe, { angle: PaddingAngle });
100
+ }
101
+
102
+ __insertText(key, x, y, properties) {
103
+ if (!this.writer) return;
104
+ let radius;
105
+ if (properties != null && properties.pixelRadiusBig) {
106
+ radius = properties.pixelRadiusBig
107
+ } else {
108
+ radius = this.defaultProperties.pixelRadiusBig;
109
+ }
110
+ this.writer.insertTextItem(key, x, y, radius);
99
111
  }
100
112
 
101
113
  // Globe API interface methods
102
114
 
103
115
  draw2D() {
104
-
105
116
  const { gl, globe, paddingProgram, paddingVao, bufferOrchestrator, bufferManagersCompMap } = this;
106
- const items = this.compassMap.query(globe);
117
+ const is3D = globe.api_GetCurrentGeometry() === 0;
118
+ if (is3D) return;
119
+ const items = this.compassMap.query(globe, this.writer);
107
120
  if (items.length === 0) return;
108
- const { x, y, properties } = items[0];
109
- console.log(x, y, properties);
110
121
  bufferOrchestrator.flush();
111
122
  bufferOrchestrator.insertBulk(items, bufferManagersCompMap);
123
+ items.forEach((v) => {
124
+ this.__insertText(v.key, v.x, v.y)
125
+ });
112
126
  gl.disable(gl.DEPTH_TEST);
113
127
  paddingProgram.draw(paddingVao, bufferOrchestrator.length, this._opacity)
114
128
  gl.enable(gl.DEPTH_TEST);
129
+ this.writer?.draw();
115
130
  }
116
131
 
117
132
  free() {
118
133
 
134
+
119
135
  }
120
136
  }
121
137
 
122
138
 
123
139
 
124
140
  class CompassMap {
125
- constructor({ defaultProperties = null } = {}) {
141
+ constructor(parent) {
126
142
  this.coordsMemory = new Map();
127
143
  this.propertyMemory = new Map();
128
- if (defaultProperties !== null) {
129
-
130
- this.defaultProperties = defaultProperties
131
- } else {
132
-
133
- this.defaultProperties = {
134
- rgba: [1, 1, 1, 1],
135
- pixelRadiusBig: 350,
136
- pixelRadiusSmall: 270
137
- }
138
- }
144
+ this.parent = parent;
139
145
  }
140
146
 
141
147
  insert(key, long, lat, properties = null) {
@@ -148,8 +154,9 @@ class CompassMap {
148
154
  this.propertyMemory.delete(key);
149
155
  }
150
156
 
151
- query(globe) {
152
- const { coordsMemory, propertyMemory, defaultProperties } = this;
157
+ query(globe, writer) {
158
+ const { coordsMemory, propertyMemory } = this;
159
+ const defaultProperties = this.parent.defaultProperties;
153
160
  const result = [];
154
161
  coordsMemory.forEach((v, k, c) => {
155
162
  const { x, y } = globe.api_GetScreenPointFromGeo(
@@ -160,6 +167,8 @@ class CompassMap {
160
167
  },
161
168
 
162
169
  );
170
+ writer?.insertTextItem(k, x, y);
171
+
163
172
  if (x !== null) {
164
173
  const properties = { ...defaultProperties, ...propertyMemory.get(k) };
165
174
  result.push({ key: k, x, y, properties })
@@ -0,0 +1,120 @@
1
+ import { CSZMode } from "@pirireis/webglobe";
2
+
3
+ const defaultStyle = {
4
+ textFont: {
5
+ name: 'Arial',
6
+ textColor: '#FFFFFF', // beyaz
7
+ hollowColor: '#000000', // siyah
8
+ size: 12, // piksel
9
+ hollow: true,
10
+ bold: true,
11
+ italic: false,
12
+ },
13
+ opacity: 1.0,
14
+ zMode: CSZMode.Z_GROUND_PERVERTEX,
15
+ }
16
+
17
+ /**
18
+ * TODOs:
19
+ * 1) update all if initials change (propably need a context and a callback to iterate over data)
20
+ * 2) expose a mechanic to update text on zoom change
21
+ * 3) extend the mechanic on 2 to other events
22
+ */
23
+ export class ContextTextWriter2Offsets {
24
+ constructor(globe, { style = null, doDraw = true, angle = 30, } = {}) {
25
+ this.globe = globe;
26
+ this.itemMap = new Map();
27
+ this.style = style || defaultStyle;
28
+ this.doDraw = doDraw;
29
+ this.angle = angle;
30
+
31
+
32
+ }
33
+
34
+ setKeyAdaptor(adaptor) {
35
+ this.keyAdaptor = adaptor;
36
+ }
37
+
38
+ setDoDraw(bool) {
39
+ this.doDraw = bool;
40
+ }
41
+
42
+ setStyle(style) {
43
+ this.style = style;
44
+ }
45
+
46
+ setOpacity(opacity) {
47
+ this.style.opacity = opacity;
48
+ }
49
+
50
+
51
+
52
+ draw() {
53
+ if (!this.doDraw) return;
54
+ const { globe, style, itemMap } = this;
55
+ const { textFont, opacity: opacity_ } = style;
56
+ const is3D = globe.api_GetCurrentGeometry() === 0;
57
+ if (is3D) return;
58
+ const angleIsOn = is3D ? (this.angleAdaptorIsOn && this.angleOnSphere) : (this.angleAdaptorIsOn)
59
+ for (const [key, { center, offsets, texts, opacity = null, angles }] of itemMap) {
60
+ const o = opacity === null ? opacity_ : opacity * opacity_;
61
+ if (center.x !== null && center.y !== null) {
62
+ offsets.forEach(({ offsetX, offsetY }, i) => {
63
+ const text = texts[i];
64
+ const angle = angles[i];
65
+ console.log("asdfadsf", text, angle, center, offsetX, offsetY);
66
+ globe.api_DrawContextTextMultiLine(text, textFont, o, { x: center.x + offsetX, y: center.y + offsetY }, angleIsOn, angle);
67
+ });
68
+ }
69
+
70
+ }
71
+ }
72
+
73
+
74
+ insertTextItem(key, x, y, radius) {
75
+ const item = this.getItem(key);
76
+ item.center = { x, y };
77
+ if (item.radius != undefined && item.radius === radius) return;
78
+ item.radius = radius;
79
+ const { offsets, angles, texts } = this.__offsetAngleText(radius);
80
+ item.offsets = offsets;
81
+ item.angles = angles;
82
+ item.texts = texts;
83
+ }
84
+
85
+ getItem(key) {
86
+ if (!this.itemMap.has(key)) this.itemMap.set(key, {});
87
+ return this.itemMap.get(key);
88
+ }
89
+
90
+ __calculateOffset(radius, angle) {
91
+ const rAngle = (angle - 90) * (Math.PI / 180);
92
+ return { offsetX: Math.cos(rAngle) * radius, offsetY: Math.sin(rAngle) * radius };
93
+ }
94
+
95
+ __offsetAngleText(radius) {
96
+ const angle = this.angle;
97
+ const offsets = []
98
+ const angles = []
99
+ const texts = []
100
+ let currentAngle = 0;
101
+ while (currentAngle < 360) {
102
+ offsets.push(this.__calculateOffset(radius + 10, currentAngle));
103
+ angles.push(currentAngle);
104
+ if (currentAngle == 0) {
105
+ texts.push("K");
106
+ } else {
107
+ texts.push(currentAngle.toString());
108
+ }
109
+ currentAngle += angle;
110
+ }
111
+ return { offsets, angles, texts };
112
+ }
113
+
114
+
115
+ clear() {
116
+ this.itemMap.clear();
117
+ }
118
+ }
119
+
120
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.5.12",
3
+ "version": "0.6.0",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -20,15 +20,24 @@ vec3 coord_opacity(){
20
20
  if( gl_VertexID % 2 == 0){
21
21
  if ( gl_VertexID % 60 == 0){
22
22
  radius = pixel_radius_small;
23
+ } else if( gl_VertexID % 10 == 0) {
24
+ float gap = (pixel_radius_big - pixel_radius_small) / 4.0;
25
+ radius = pixel_radius_small + gap;
23
26
  } else {
24
- radius = (pixel_radius_big + pixel_radius_small) / 2.0;
27
+ float gap = (pixel_radius_big - pixel_radius_small) * 0.75;
28
+ radius = pixel_radius_small + gap;
25
29
  }
26
30
  angle = (float(gl_VertexID) / (${vertexCount}.0));
27
31
  } else {
28
- radius = pixel_radius_big;
32
+ if ( gl_VertexID % 60 == 1){
33
+ radius = pixel_radius_big + 10.0;
34
+
35
+ } else {
36
+ radius = pixel_radius_big;
37
+ }
29
38
  angle = (float(gl_VertexID - 1) / (${vertexCount}.0));
30
39
  }
31
- float opacity = fract(angle + 0.2475) / 1.5 + 0.25;
40
+ float opacity = fract(angle + 0.2475) / 1.5 + 0.33;
32
41
  angle = angle * ${Math.PI * 2.0} + world_north_angle;
33
42
 
34
43
  return vec3( screen_coordinate + vec2( cos(angle), sin(angle)) * radius, opacity);
@@ -1,149 +0,0 @@
1
- import { CSZMode } from "@pirireis/webglobe";
2
-
3
- const defaultStyle = {
4
- textFont: {
5
- name: 'Arial',
6
- textColor: '#FFFFFF', // beyaz
7
- hollowColor: '#000000', // siyah
8
- size: 12, // piksel
9
- hollow: true,
10
- bold: true,
11
- italic: false,
12
- },
13
- opacity: 1.0,
14
- zMode: CSZMode.Z_GROUND_PERVERTEX,
15
- }
16
-
17
- /**
18
- * TODOs:
19
- * 1) update all if initials change (propably need a context and a callback to iterate over data)
20
- * 2) expose a mechanic to update text on zoom change
21
- * 3) extend the mechanic on 2 to other events
22
- */
23
- export class ContextTextWriter2Offsets {
24
- constructor(globe, { style = null, doDraw = true, textAdaptor = null, coordinatesAdaptor = null, keyAdaptor = null, opacityAdaptor = null, angleAdaptor = null, angleOnSphere = false } = {}) {
25
- this.globe = globe;
26
- this.itemMap = new Map();
27
- this.style = style || defaultStyle;
28
- this.doDraw = doDraw;
29
-
30
-
31
- this.textAdaptor = textAdaptor;
32
- this.coordinatesAdaptor = coordinatesAdaptor;
33
- this.keyAdaptor = keyAdaptor;
34
-
35
- this.opacityAdaptor = opacityAdaptor ? opacityAdaptor : () => 1;
36
- this.angleOnSphere = angleOnSphere;
37
- if (angleAdaptor) {
38
- this.angleAdaptor = angleAdaptor
39
- this.angleAdaptorIsOn = true;
40
- } else {
41
- this.angleAdaptor = () => null
42
- this.angleAdaptorIsOn = false
43
- }
44
- }
45
-
46
- setKeyAdaptor(adaptor) {
47
- this.keyAdaptor = adaptor;
48
- }
49
-
50
- setDoDraw(bool) {
51
- this.doDraw = bool;
52
- }
53
-
54
- setStyle(style) {
55
- this.style = style;
56
- }
57
-
58
- setOpacity(opacity) {
59
- this.style.opacity = opacity;
60
- }
61
-
62
-
63
-
64
- draw() {
65
- if (!this.doDraw) return;
66
- const { globe, style, itemMap } = this;
67
- const { textFont, opacity: opacity_ } = style;
68
- const is3D = globe.api_GetCurrentGeometry() === 0;
69
- const angleIsOn = is3D ? (this.angleAdaptorIsOn && this.angleOnSphere) : (this.angleAdaptorIsOn)
70
- for (const [key, { center, offsets, texts, opacity = null, angle = null }] of itemMap) {
71
- const o = opacity === null ? opacity_ : opacity * opacity_;
72
- if (center.x !== null && center.y !== null) {
73
- offsets.forEach(({ offsetX, offsetY }, i) => {
74
- const text = texts[i];
75
- globe.api_DrawContextTextMultiLine(text, textFont, o, { x: center.x + offsetX, y: center.y + offsetY }, angleIsOn, angle);
76
- });
77
- }
78
-
79
- }
80
- }
81
-
82
-
83
- updateOpacityOfItem(item, i, container, properties) {
84
- const opacity = this.opacityAdaptor(item, i, container, properties);
85
- if (opacity == null) return;
86
- const key = this.keyAdaptor(item, i, container, properties);
87
- const data = this.itemMap.get(key)
88
- data.opacity = opacity;
89
- }
90
-
91
- updateOpacityContainer(container, properties) {
92
- container.forEach((v, i, c) => {
93
- this.updateOpacityOfItem(v, i, c, properties);
94
- })
95
- }
96
-
97
-
98
- insertTextBulk(container, properties) {
99
- container.forEach((v, i, c) => {
100
- this.insertText(v, i, c, properties);
101
- })
102
- }
103
-
104
- updateTextCoords(item, i, container, properties) {
105
- const coords = this.coordinatesAdaptor(item, i, container, properties);
106
- if (coords == null) return;
107
- const key = this.keyAdaptor(item, i, container, properties);
108
- const data = this.itemMap.get(key)
109
- data.angle = this.angleAdaptor(item, i, container, properties);
110
- data.long = coords.long;
111
- data.lat = coords.lat;
112
- }
113
-
114
- updateTextCoordsBulk(container, properties) {
115
- container.forEach((v, i, c) => {
116
- this.updateTextCoords(v, i, c, properties)
117
- })
118
- }
119
-
120
- deleteTextBulk(keys) {
121
- for (const key of keys) {
122
- this.itemMap.delete(key);
123
- }
124
- }
125
-
126
-
127
- insertText(item, id, container, properties) {
128
- const key = this.keyAdaptor(item, id, container, properties)
129
- const coords = this.coordinatesAdaptor(item, id, container, properties)
130
- if (coords == null) {
131
- this.itemMap.delete(key);
132
- return;
133
- }
134
- const text = this.textAdaptor(item, id, container, properties)
135
- if (text == null) {
136
- this.itemMap.delete(key);
137
- return
138
- };
139
- const opacity = this.opacityAdaptor(item, id, container, properties);
140
- const angle = this.angleAdaptor(item, id, container, properties);
141
- this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity, angle });
142
- }
143
-
144
- clear() {
145
- this.itemMap.clear();
146
- }
147
- }
148
-
149
-