@pirireis/webglobeplugins 0.4.2-a → 0.5.1

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,19 +1,20 @@
1
- import { keyMethod } from "./util";
2
1
  /**
3
2
  * set and get node data
4
3
  * node indexes;
5
4
  */
6
5
  export class ChainListMap {
7
6
 
8
- constructor() {
7
+ constructor(keyMethod) {
9
8
  this._chainMap = new Map();
10
9
  this._chainSideProperties = new Map();
11
10
  this._indexMap = new Map(); // hold list index of lastly updated nodes. on add delete goes empty
11
+ this.keyMethod = keyMethod;
12
12
  }
13
13
 
14
14
  getChain(chainKey) {
15
15
  if (!this._chainMap.has(chainKey)) this._chainMap.set(chainKey, []);
16
16
  return this._chainMap.get(chainKey);
17
+
17
18
  }
18
19
 
19
20
  /**
@@ -35,6 +36,7 @@ export class ChainListMap {
35
36
  break;
36
37
  }
37
38
  }
39
+ node.__identity__ = this.keyMethod(chainKey, node.key);
38
40
  this._resetIndexChain(chainKey);
39
41
  }
40
42
 
@@ -51,7 +53,7 @@ export class ChainListMap {
51
53
  const removeSet = new Set(nodeKeys);
52
54
  const newChain = []
53
55
  for (const node of chain) {
54
- const dKey = keyMethod(chainKey, node.key);
56
+ const dKey = node.__identity__;
55
57
  this._indexMap.delete(dKey);
56
58
  if (removeSet.has(node.key)) {
57
59
  compKeys.push(dKey);
@@ -65,7 +67,6 @@ export class ChainListMap {
65
67
 
66
68
  deleteChainAndReturnChainKeys(chainKey) {
67
69
  const keys = this.getNodeKeysOfChain(chainKey);
68
- console.log('chainKey', chainKey, "keys", keys);
69
70
  this._chainMap.delete(chainKey);
70
71
  for (const key of keys) this._indexMap.delete(key);
71
72
  return keys;
@@ -74,6 +75,7 @@ export class ChainListMap {
74
75
  updateNode(node, chainKey) {
75
76
  const index = this.getIndexOfNode(chainKey, node.key)
76
77
  const chain = this._chainMap.get(chainKey);
78
+ node.__identity__ = this.keyMethod(chainKey, node.key);
77
79
  chain[index] = node;
78
80
  }
79
81
 
@@ -81,6 +83,7 @@ export class ChainListMap {
81
83
  setChain(chainKey, nodeList) {
82
84
  if (this._chainMap.has(chainKey)) this._flushIndexMap();
83
85
  this._chainMap.set(chainKey, nodeList);
86
+ nodeList.forEach((v) => v.__identity__ = this.keyMethod(chainKey, v.key))
84
87
  }
85
88
 
86
89
 
@@ -151,7 +154,7 @@ export class ChainListMap {
151
154
 
152
155
 
153
156
  getIndexOfNode(chainKey, nodeKey) {
154
- const key = keyMethod(chainKey, nodeKey);
157
+ const key = this.keyMethod(chainKey, nodeKey);
155
158
  if (this._indexMap.has(key)) return this._indexMap.get(key);
156
159
 
157
160
  const chain = this._chainMap.get(chainKey);
@@ -172,16 +175,14 @@ export class ChainListMap {
172
175
  const chain = this._chainMap.get(chainKey);
173
176
  for (let i = 0; i < chain.length; i++) {
174
177
  const node = chain[i]
175
- this._indexMap.set(keyMethod(chainKey, node.key), i);
178
+ this._indexMap.set(this.keyMethod(chainKey, node.key), i);
176
179
  }
177
180
  }
178
181
 
179
182
  getNodeKeysOfChain(chainKey) {
180
183
  const chain = this._chainMap.get(chainKey);
181
- console.log("node keys", chain);
182
184
  if (!chain) return [];
183
- const result = chain.map((v) => keyMethod(chainKey, v.key));
184
- console.log("buffer Keys", result);
185
+ const result = chain.map((v) => v.__identity__);
185
186
  return result
186
187
  }
187
188
 
@@ -2,8 +2,7 @@ import { LineOnGlobeCache } from '../programs/line-on-globe/naive';
2
2
  import { CircleCache } from '../programs/line-on-globe/circle';
3
3
  import { BufferOrchestrator, BufferManager } from "../util/account";
4
4
  import { ChainListMap } from "./chain-list-map";
5
- import { keyMethod } from "./util";
6
-
5
+ import { keyMethod } from './util';
7
6
  // TODO: Add update buffer and update text mehods on add, delete, update methods
8
7
 
9
8
 
@@ -26,13 +25,14 @@ const radian = Math.PI / 180;
26
25
 
27
26
  export class CircleLineChainPlugin {
28
27
 
29
- constructor(id, { textContextWriterInjectionMap = new Map() } = {}) {
28
+ constructor(id, { drawCircleOn = true, textContextWriterInjectionMap = new Map() } = {}) {
30
29
  this.id = id;
31
30
  this._textContextWriterInjectionMap = textContextWriterInjectionMap;
32
- this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, probs) => keyMethod(probs.chainKey, v.key)));
31
+ this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, probs) => v.__identity__));
33
32
  this._opacity = 1;
34
- this._chainListMap = new ChainListMap();
33
+ this._chainListMap = new ChainListMap(keyMethod);
35
34
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
35
+ this._drawCircleOn = drawCircleOn
36
36
  }
37
37
 
38
38
  // init
@@ -100,6 +100,12 @@ export class CircleLineChainPlugin {
100
100
 
101
101
  // API
102
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
+ }
103
109
  // -- update bulk family
104
110
  /**
105
111
  *
@@ -107,7 +113,6 @@ export class CircleLineChainPlugin {
107
113
  * @typedef chain
108
114
  * @property {string} chainKey
109
115
  * @property {Array<node>} nodes
110
- *
111
116
  * @typedef {Object} node
112
117
  * @property {string} key
113
118
  * @property {number} long
@@ -183,7 +188,6 @@ export class CircleLineChainPlugin {
183
188
  */
184
189
  addNode(node, chainKey, { theNodeKeyFront = null, textWriterIDs = [] } = {}) {
185
190
  // TODO: if before object is null update the last two elements of the chain only.
186
- console.log("addNode", node, chainKey, theNodeKeyFront);
187
191
  this._chainListMap.addNode(node, chainKey, theNodeKeyFront);
188
192
  if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
189
193
  this._reconstructChains([chainKey]);
@@ -201,7 +205,11 @@ export class CircleLineChainPlugin {
201
205
 
202
206
 
203
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));
204
211
  this._opacity = opacity;
212
+ this.globe.DrawRender();
205
213
  }
206
214
 
207
215
 
@@ -219,8 +227,6 @@ export class CircleLineChainPlugin {
219
227
  for (const chainKey of chainKeys) {
220
228
  bufferKeys.push(...this._chainListMap.deleteChainAndReturnChainKeys(chainKey));
221
229
  }
222
- console.log("delete chain keys", chainKeys);
223
- console.log("deletechains bufferKeys", bufferKeys);
224
230
  this._updateTexts(chainKeys, this._textContextWriterInjectionMap.keys());
225
231
  this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
226
232
  this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
@@ -277,7 +283,7 @@ export class CircleLineChainPlugin {
277
283
  lat: v.lat,
278
284
  targetLong: array[i + 1].long,
279
285
  targetLat: array[i + 1].lat,
280
- key: keyMethod(probs.chainKey, v.key)
286
+ key: v.__identity__
281
287
  }
282
288
  }
283
289
  const bulkData = [];
@@ -313,7 +319,7 @@ export class CircleLineChainPlugin {
313
319
  const { gl } = this;
314
320
  gl.disable(gl.DEPTH_TEST);
315
321
  this.lineProgram.draw(this.lineVao, this.bufferOrchestrator.length, this._opacity);
316
- this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
322
+ if (this._drawCircleOn) this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
317
323
  this._textContextWriterInjectionMap.forEach((writer) => writer.draw());
318
324
  gl.enable(gl.DEPTH_TEST);
319
325
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.4.2-a",
3
+ "version": "0.5.1",
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() {
File without changes