@pirireis/webglobeplugins 0.5.0 → 0.5.2

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.
@@ -36,7 +36,7 @@ export class ChainListMap {
36
36
  break;
37
37
  }
38
38
  }
39
- node.identity = this.keyMethod(chainKey, node.key);
39
+ node.__identity__ = this.keyMethod(chainKey, node.key);
40
40
  this._resetIndexChain(chainKey);
41
41
  }
42
42
 
@@ -53,7 +53,7 @@ export class ChainListMap {
53
53
  const removeSet = new Set(nodeKeys);
54
54
  const newChain = []
55
55
  for (const node of chain) {
56
- const dKey = node.identity;
56
+ const dKey = node.__identity__;
57
57
  this._indexMap.delete(dKey);
58
58
  if (removeSet.has(node.key)) {
59
59
  compKeys.push(dKey);
@@ -75,7 +75,7 @@ export class ChainListMap {
75
75
  updateNode(node, chainKey) {
76
76
  const index = this.getIndexOfNode(chainKey, node.key)
77
77
  const chain = this._chainMap.get(chainKey);
78
- node.identity = this.keyMethod(chainKey, node.key);
78
+ node.__identity__ = this.keyMethod(chainKey, node.key);
79
79
  chain[index] = node;
80
80
  }
81
81
 
@@ -83,7 +83,7 @@ export class ChainListMap {
83
83
  setChain(chainKey, nodeList) {
84
84
  if (this._chainMap.has(chainKey)) this._flushIndexMap();
85
85
  this._chainMap.set(chainKey, nodeList);
86
- nodeList.forEach((v) => v.identity = this.keyMethod(chainKey, v.key))
86
+ nodeList.forEach((v) => v.__identity__ = this.keyMethod(chainKey, v.key))
87
87
  }
88
88
 
89
89
 
@@ -182,7 +182,7 @@ export class ChainListMap {
182
182
  getNodeKeysOfChain(chainKey) {
183
183
  const chain = this._chainMap.get(chainKey);
184
184
  if (!chain) return [];
185
- const result = chain.map((v) => v.identity);
185
+ const result = chain.map((v) => v.__identity__);
186
186
  return result
187
187
  }
188
188
 
@@ -25,13 +25,14 @@ const radian = Math.PI / 180;
25
25
 
26
26
  export class CircleLineChainPlugin {
27
27
 
28
- constructor(id, { textContextWriterInjectionMap = new Map() } = {}) {
28
+ constructor(id, { drawCircleOn = true, textContextWriterInjectionMap = new Map() } = {}) {
29
29
  this.id = id;
30
30
  this._textContextWriterInjectionMap = textContextWriterInjectionMap;
31
- this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, probs) => v.identity));
31
+ this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, probs) => v.__identity__));
32
32
  this._opacity = 1;
33
33
  this._chainListMap = new ChainListMap(keyMethod);
34
34
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
35
+ this._drawCircleOn = drawCircleOn
35
36
  }
36
37
 
37
38
  // init
@@ -99,6 +100,12 @@ export class CircleLineChainPlugin {
99
100
 
100
101
  // API
101
102
 
103
+
104
+ setDrawCircleOn(bool) {
105
+ if (typeof bool !== 'boolean') throw new Error("setDrawCircleOn parameter must be a boolean");
106
+ this._drawCircleOn = bool;
107
+ this.globe.DrawRender();
108
+ }
102
109
  // -- update bulk family
103
110
  /**
104
111
  *
@@ -198,7 +205,11 @@ export class CircleLineChainPlugin {
198
205
 
199
206
 
200
207
  setOpacity(opacity) {
208
+ if (typeof opacity !== 'number') throw new Error("opacity must be a number");
209
+ if (opacity < 0 || 1 < opacity) throw new Error("opacity must be between 0-1");
210
+ this._textContextWriterInjectionMap.forEach((writer) => writer.setOpacity(opacity));
201
211
  this._opacity = opacity;
212
+ this.globe.DrawRender();
202
213
  }
203
214
 
204
215
 
@@ -272,7 +283,7 @@ export class CircleLineChainPlugin {
272
283
  lat: v.lat,
273
284
  targetLong: array[i + 1].long,
274
285
  targetLat: array[i + 1].lat,
275
- key: v.identity
286
+ key: v.__identity__
276
287
  }
277
288
  }
278
289
  const bulkData = [];
@@ -308,7 +319,7 @@ export class CircleLineChainPlugin {
308
319
  const { gl } = this;
309
320
  gl.disable(gl.DEPTH_TEST);
310
321
  this.lineProgram.draw(this.lineVao, this.bufferOrchestrator.length, this._opacity);
311
- this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
322
+ if (this._drawCircleOn) this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
312
323
  this._textContextWriterInjectionMap.forEach((writer) => writer.draw());
313
324
  gl.enable(gl.DEPTH_TEST);
314
325
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -292,6 +292,30 @@ export default class RangeRingAngleText {
292
292
 
293
293
 
294
294
 
295
+ showAllVisiableCircleText() {
296
+ this._hideAll = false;
297
+ const addBucket = {
298
+ coords: [],
299
+ coordsZ: [],
300
+ attribs: []
301
+ }
302
+ for (const [centerID, centerMap] of this._centerCollection) {
303
+ const hide = centerMap.get("hide");
304
+ const hideText = centerMap.get("textHide");
305
+ if (hide === ENUM_HIDE) continue
306
+ const isHidden = hideText === ENUM_TEXT_HIDE.HIDE;
307
+ if (isHidden) {
308
+ const x = centerMap.get("x");
309
+ const y = centerMap.get("y");
310
+ const maxRadius = centerMap.get("maxRadius");
311
+ const stepAngle = centerMap.get("stepAngle");
312
+ this._appendCircle(x, y, maxRadius, stepAngle, centerID, addBucket);
313
+ centerMap.set("textHide", ENUM_TEXT_HIDE.SHOW);
314
+ }
315
+ }
316
+ if (addBucket.coords.length) this._updateData(addBucket, CSObjectArrayUpdateTypes.ADD);
317
+ }
318
+
295
319
  flush() {
296
320
  const data = {
297
321
  coords: [],
@@ -15,10 +15,13 @@ const defaultStyle = {
15
15
  }
16
16
 
17
17
  /**
18
- * keyAdaptor should be set but higher context since it nows key methods and key method might be implicit to user
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
19
22
  */
20
23
  export class ContextTextWriter2 {
21
- constructor(globe, { style = null, doDraw = true, textAdaptor = null, coordinatesAdaptor = null, keyAdaptor = null, opacityAdaptor = null } = {}) {
24
+ constructor(globe, { style = null, doDraw = true, textAdaptor = null, coordinatesAdaptor = null, keyAdaptor = null, opacityAdaptor = null, angleAdaptor = null, angleOnSphere = false } = {}) {
22
25
  this.globe = globe;
23
26
  this.itemMap = new Map();
24
27
  this.style = style || defaultStyle;
@@ -28,10 +31,15 @@ export class ContextTextWriter2 {
28
31
  this.textAdaptor = textAdaptor;
29
32
  this.coordinatesAdaptor = coordinatesAdaptor;
30
33
  this.keyAdaptor = keyAdaptor;
31
- if (opacityAdaptor) {
32
- this.opacityAdaptor = opacityAdaptor
34
+
35
+ this.opacityAdaptor = opacityAdaptor ? opacityAdaptor : () => 1;
36
+ this.angleOnSphere = angleOnSphere;
37
+ if (angleAdaptor) {
38
+ this.angleAdaptor = angleAdaptor
39
+ this.angleAdaptorIsOn = true;
33
40
  } else {
34
- this.opacityAdaptor = () => 1;
41
+ this.angleAdaptor = () => null
42
+ this.angleAdaptorIsOn = false
35
43
  }
36
44
  }
37
45
 
@@ -57,8 +65,9 @@ export class ContextTextWriter2 {
57
65
  if (!this.doDraw) return;
58
66
  const { globe, style, itemMap } = this;
59
67
  const { textFont, opacity: opacity_ } = style;
60
-
61
- for (const [key, { lat, long, text, opacity = null }] of itemMap) {
68
+ const is3D = globe.api_GetCurrentGeometry() === 0;
69
+ const angleIsOn = is3D ? (this.angleAdaptorIsOn && this.angleOnSphere) : (this.angleAdaptorIsOn)
70
+ for (const [key, { lat, long, text, opacity = null, angle = null }] of itemMap) {
62
71
  const { x, y } = globe.api_GetScreenPointFromGeo(
63
72
  {
64
73
  long: long,
@@ -68,7 +77,8 @@ export class ContextTextWriter2 {
68
77
  style.zMode === CSZMode.Z_MSL,
69
78
  );
70
79
  const o = opacity === null ? opacity_ : opacity * opacity_;
71
- if (x !== null && y !== null) globe.api_DrawContextTextMultiLine(text, textFont, o, { x, y });
80
+
81
+ if (x !== null && y !== null) globe.api_DrawContextTextMultiLine(text, textFont, o, { x, y }, angleIsOn, angle);
72
82
  }
73
83
  }
74
84
 
@@ -99,6 +109,7 @@ export class ContextTextWriter2 {
99
109
  if (coords == null) return;
100
110
  const key = this.keyAdaptor(item, i, container, properties);
101
111
  const data = this.itemMap.get(key)
112
+ data.angle = this.angleAdaptor(item, i, container, properties);
102
113
  data.long = coords.long;
103
114
  data.lat = coords.lat;
104
115
  }
@@ -122,8 +133,10 @@ export class ContextTextWriter2 {
122
133
  const text = this.textAdaptor(item, id, container, properties)
123
134
  if (text == null) return;
124
135
  const opacity = this.opacityAdaptor(item, id, container, properties);
136
+ const angle = this.angleAdaptor(item, id, container, properties);
137
+ console.log(angle, "angle")
125
138
  const key = this.keyAdaptor(item, id, container, properties)
126
- this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity });
139
+ this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity, angle });
127
140
  }
128
141
 
129
142
  clear() {