@pirireis/webglobeplugins 0.5.2 → 0.5.4

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.
@@ -25,16 +25,24 @@ export class ChainListMap {
25
25
  */
26
26
  addNode(node, chainKey, theNodeKeyFront = null) {
27
27
  const chain = this.getChain(chainKey);
28
- if (theNodeKeyFront == null) {
29
- chain.push(node);
30
- return;
31
- }
28
+ let frontIndex = null;
32
29
  for (let i = 0; i < chain.length; i++) {
33
30
  const n_ode = chain[i];
34
- if (n_ode.key == theNodeKeyFront) {
35
- chain.splice(i, 0, node);
36
- break;
31
+ if (n_ode.key === node.key) {
32
+ throw new Error("Chain node already exists");
33
+ }
34
+ if (n_ode.key === theNodeKeyFront) {
35
+ frontIndex = i;
36
+ }
37
+ }
38
+ if (theNodeKeyFront !== null) {
39
+ if (frontIndex !== null) {
40
+ chain.splice(frontIndex, 0, node);
41
+ } else {
42
+ throw new Error("Could not find theNodeKeyFront");
37
43
  }
44
+ } else {
45
+ chain.push(node);
38
46
  }
39
47
  node.__identity__ = this.keyMethod(chainKey, node.key);
40
48
  this._resetIndexChain(chainKey);
@@ -49,20 +57,20 @@ export class ChainListMap {
49
57
 
50
58
  deleteNodesBelongToAChain(chainKey, nodeKeys) {
51
59
  const chain = this._chainMap.get(chainKey);
52
- const compKeys = [];
60
+ const deleteKeys = [];
53
61
  const removeSet = new Set(nodeKeys);
54
62
  const newChain = []
55
63
  for (const node of chain) {
56
64
  const dKey = node.__identity__;
57
65
  this._indexMap.delete(dKey);
58
66
  if (removeSet.has(node.key)) {
59
- compKeys.push(dKey);
67
+ deleteKeys.push(dKey);
60
68
  } else {
61
69
  newChain.push(node);
62
70
  }
63
71
  }
64
72
  this._chainMap.set(chainKey, newChain);
65
- return compKeys;
73
+ return deleteKeys;
66
74
  }
67
75
 
68
76
  deleteChainAndReturnChainKeys(chainKey) {
@@ -80,6 +88,25 @@ export class ChainListMap {
80
88
  }
81
89
 
82
90
 
91
+ updateNodeProperties(node, chainKey) {
92
+ const index = this.getIndexOfNode(chainKey, node.key)
93
+ const chainNode = this._chainMap.get(chainKey)[index];
94
+ if (node.circleProperties) {
95
+ node.circleProperties.forEach((value, key, container) => chainNode[key] = value);
96
+ }
97
+ if (node.lineProperties) {
98
+ node.lineProperties.forEach((value, key, container) => chainNode[key] = value);
99
+ }
100
+ }
101
+
102
+ updateCoordsinatesOfNode(node, chainKey) {
103
+ const index = this.getIndexOfNode(chainKey, node.key)
104
+ const chain = this._chainMap.get(chainKey);
105
+ chain[index].long = node.long;
106
+ chain[index].long = node.lat;
107
+
108
+ }
109
+
83
110
  setChain(chainKey, nodeList) {
84
111
  if (this._chainMap.has(chainKey)) this._flushIndexMap();
85
112
  this._chainMap.set(chainKey, nodeList);
@@ -116,11 +143,10 @@ export class ChainListMap {
116
143
  * @param {*} chainKey
117
144
  * @param {*} callback | (value, index, array) => expexted output
118
145
  */
119
- calculateBufferPropertiesChain(chainKey, callback, result, nodeIndexes = null) {
146
+ calculateBufferPropertiesChain(chainKey, callback, result,) {
120
147
  const chain = this._chainMap.get(chainKey);
121
148
  const props = this._chainSideProperties.get(chainKey);
122
- const iterator = nodeIndexes !== null ? nodeIndexes : chain.keys();
123
- for (const i of iterator) {
149
+ for (let i = 0; i < chain.length - 1; i++) {
124
150
  const node = callback(chain[i], i, chain, props);
125
151
  if (node !== null) result.push(node);
126
152
  }
@@ -132,21 +158,12 @@ export class ChainListMap {
132
158
  * @param {*} textWriterObjs
133
159
  * @param {*} nodeKeys use nodeKeys on updateCoordinatesOnly
134
160
  */
135
- textUpdate(chainKey, textWriterObjs, nodeIndexes = null) {
161
+ textUpdate(chainKey, textWriterObjs) {
136
162
  const chain = this._chainMap.get(chainKey);
137
163
  if (!chain) return;
138
164
  const properties = this._chainSideProperties.get(chainKey);
139
- if (nodeIndexes) {
140
- textWriterObjs.forEach((writer) => {
141
- nodeIndexes.forEach((i) => {
142
- writer.insertText(chain[i], i, chain, properties);
143
- });
144
- });
145
- return;
146
- }
147
165
  textWriterObjs.forEach((writer) => {
148
- const chain = this._chainMap.get(chainKey);
149
- const properties = this._chainSideProperties.get(chainKey);
166
+
150
167
  writer.insertTextBulk(chain, properties);
151
168
  });
152
169
 
@@ -2,7 +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';
5
+ import { keyMethod } from "./util";
6
6
  // TODO: Add update buffer and update text mehods on add, delete, update methods
7
7
 
8
8
 
@@ -21,6 +21,16 @@ import { keyMethod } from './util';
21
21
  * updateChainProperties
22
22
  */
23
23
 
24
+
25
+ /**
26
+ * @typedef StyleProperties
27
+ * @property {[0-1,0-1,0-1,0-1]} rgba
28
+ * @property { 0-1 } dashOpacity
29
+ * @property { 0-1 } dashRatio
30
+ * @property {0-360} circleDashAngle
31
+ * @property {Array<node>} nodes
32
+ */
33
+
24
34
  const radian = Math.PI / 180;
25
35
 
26
36
  export class CircleLineChainPlugin {
@@ -28,7 +38,7 @@ export class CircleLineChainPlugin {
28
38
  constructor(id, { drawCircleOn = true, textContextWriterInjectionMap = new Map() } = {}) {
29
39
  this.id = id;
30
40
  this._textContextWriterInjectionMap = textContextWriterInjectionMap;
31
- this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, probs) => v.__identity__));
41
+ this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, properties) => v.__identity__));
32
42
  this._opacity = 1;
33
43
  this._chainListMap = new ChainListMap(keyMethod);
34
44
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
@@ -64,7 +74,10 @@ export class CircleLineChainPlugin {
64
74
  }],
65
75
  ["rgba", {
66
76
  'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
67
- 'adaptor': (item) => new Float32Array(item.rgba)
77
+ 'adaptor': (item) => {
78
+ if (item.lineProperties?.rgba) return new Float32Array(item.lineProperties.rgba);
79
+ return new Float32Array(item.chainProperties.rgba);
80
+ }
68
81
  }],
69
82
  ["bigRadius", {
70
83
  'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
@@ -72,16 +85,26 @@ export class CircleLineChainPlugin {
72
85
  }],
73
86
  ["dashRatio", {
74
87
  'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
75
- 'adaptor': (item) => new Float32Array([item.dashRatio])
88
+ 'adaptor': (item) => new Float32Array([item.chainProperties.dashRatio])
76
89
  }],
77
90
 
78
91
  ["dashOpacity", {
79
92
  'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
80
- 'adaptor': (item) => new Float32Array([item.dashOpacity])
93
+ 'adaptor': (item) => new Float32Array([item.chainProperties.dashOpacity])
81
94
  }],
82
95
  ["circleDashAngle", {
83
96
  'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
84
- 'adaptor': (item) => new Float32Array([item.circleDashAngle / 360])
97
+ 'adaptor': (item) => {
98
+ if (item.circleProperties?.circleDashAngle) return new Float32Array([item.circleProperties.circleDashAngle / 360]);
99
+ return new Float32Array([item.chainProperties.circleDashAngle / 360]);
100
+ }
101
+ }],
102
+ ["rgbaCircle", {
103
+ "bufferManager": new BufferManager(gl, 4, { bufferType, initialCapacity }),
104
+ "adaptor": (item) => {
105
+ if (item.circleProperties?.rgba) return new Float32Array(item.circleProperties.rgba);
106
+ return new Float32Array(item.chainProperties.rgba);
107
+ }
85
108
  }]
86
109
  ]
87
110
  );
@@ -92,7 +115,7 @@ export class CircleLineChainPlugin {
92
115
  this.lineVao = this.lineProgram.createVAO(
93
116
  ...['centerCoords', 'targetCoords', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
94
117
  this.circleVao = this.circleProgram.createVAO(
95
- ...["centerCoords", "bigRadius", "rgba", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
118
+ ...["centerCoords", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
96
119
  }
97
120
 
98
121
  }
@@ -127,7 +150,7 @@ export class CircleLineChainPlugin {
127
150
  for (const chain of data) {
128
151
  chainKeys.push(chain.chainKey);
129
152
  chain.nodes.forEach((node) => {
130
- this._chainListMap.updateNode(node, chain.chainKey);
153
+ this._chainListMap.updateCoordsinatesOfNode(node, chain.chainKey);
131
154
  });
132
155
  }
133
156
  this._reconstructChains(chainKeys);
@@ -135,6 +158,18 @@ export class CircleLineChainPlugin {
135
158
  }
136
159
 
137
160
 
161
+ /**
162
+ *
163
+ * @param {*} chainKey
164
+ * @param {Array<{nodeKey, Map[propertyName ,value]}} propertyMap
165
+ */
166
+ updateNodeProperties(chainKey, nodesAndPropertyMap, { textWriterIDs = [] } = {}) {
167
+ this._chainListMap.updateNodeProperties(chainKey, nodesAndPropertyMap)
168
+ this._reconstructChains([chainKey]);
169
+ this._textUpdate(chainKey, textWriterIDs);
170
+ this.globe.DrawRender();
171
+ }
172
+
138
173
  /**
139
174
  *
140
175
  * @param {*} chainKey
@@ -152,16 +187,15 @@ export class CircleLineChainPlugin {
152
187
  * @param {Array<chain>} data
153
188
  * @typedef chain
154
189
  * @property {string} chainKey
155
- * @property {[0-1,0-1,0-1,0-1]} rgba
156
- * @property { 0-1 } dashOpacity
157
- * @property { 0-1 } dashRatio
158
- * @property {0-360} circleDashAngle
159
- * @property {Array<node>} nodes
190
+ * @property {StyleProperties} chainProperties
191
+
192
+ * } chainProperties
160
193
  *
161
194
  * @typedef {Object} node
162
195
  * @property {string} key
163
196
  * @property {number} long
164
197
  * @property {number} lat
198
+ * @property {StyleProperties} circleProperties
165
199
  */
166
200
  insertBulk(data, { textWriterIDs = [] } = []) {
167
201
  // first insert everything to implicit structure,
@@ -169,15 +203,14 @@ export class CircleLineChainPlugin {
169
203
  // let _reconstractChainBufferData method interact with data and bufferOrchestrator.
170
204
  const chainKeysToConstruct = [];
171
205
 
172
- for (const { chainKey, rgba, dashOpacity, dashRatio, circleDashAngle, nodes } of data) {
206
+ for (const { chainKey, chainProperties, nodes } of data) {
173
207
  this._chainListMap.setChain(chainKey, nodes);
174
- this._chainListMap.setChainProperties(chainKey, {
175
- rgba, dashOpacity, dashRatio, circleDashAngle, chainKey
176
- });
208
+ this._chainListMap.setChainProperties(chainKey, chainProperties);
177
209
  chainKeysToConstruct.push(chainKey);
178
210
  }
179
211
  this._reconstructChains(chainKeysToConstruct);
180
212
  if (textWriterIDs) this._updateTexts(chainKeysToConstruct, textWriterIDs);
213
+ this.globe.DrawRender();
181
214
  }
182
215
 
183
216
  /**
@@ -191,6 +224,7 @@ export class CircleLineChainPlugin {
191
224
  this._chainListMap.addNode(node, chainKey, theNodeKeyFront);
192
225
  if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
193
226
  this._reconstructChains([chainKey]);
227
+ this.globe.DrawRender();
194
228
 
195
229
  }
196
230
 
@@ -200,6 +234,7 @@ export class CircleLineChainPlugin {
200
234
  this._chainListMap.updateNode(node, chainKey);
201
235
  if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
202
236
  this._reconstructChains([chainKey]);
237
+ this.globe.DrawRender();
203
238
  }
204
239
 
205
240
 
@@ -230,6 +265,7 @@ export class CircleLineChainPlugin {
230
265
  this._updateTexts(chainKeys, this._textContextWriterInjectionMap.keys());
231
266
  this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
232
267
  this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
268
+ this.globe.DrawRender();
233
269
  }
234
270
 
235
271
 
@@ -246,8 +282,10 @@ export class CircleLineChainPlugin {
246
282
  });
247
283
  this._reconstructChains(chainKeysToReconstuct);
248
284
  this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
249
- if (textWriterIDs) this._updateTexts(chainKeysToReconstuct, textWriterIDs)
285
+ // if (textWriterIDs) this._updateTexts(chainKeysToReconstuct, textWriterIDs)
250
286
  this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
287
+ this.globe.DrawRender();
288
+
251
289
  }
252
290
 
253
291
 
@@ -271,18 +309,17 @@ export class CircleLineChainPlugin {
271
309
  // }
272
310
 
273
311
  const radiusM = radiusMethod(globe);
274
- const callback = (v, i, array, probs) => {
312
+ const callback = (v, i, array, chainProperties) => {
275
313
  if (i == array.length - 1) return null;
276
314
  return {
277
- rgba: probs.rgba,
315
+ chainProperties: chainProperties,
278
316
  bigRadius: radiusM(v, i, array),
279
- circleDashAngle: probs.circleDashAngle,
280
- dashOpacity: probs.dashOpacity,
281
- dashRatio: probs.dashRatio,
282
- long: v.long,
283
- lat: v.lat,
284
317
  targetLong: array[i + 1].long,
285
318
  targetLat: array[i + 1].lat,
319
+ long: v.long,
320
+ lat: v.lat,
321
+ lineProperties: v.lineProperties,
322
+ circleProperties: v.circleProperties,
286
323
  key: v.__identity__
287
324
  }
288
325
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -292,7 +292,7 @@ export default class RangeRingAngleText {
292
292
 
293
293
 
294
294
 
295
- showAllVisiableCircleText() {
295
+ showAllVisibleCircleText() {
296
296
  this._hideAll = false;
297
297
  const addBucket = {
298
298
  coords: [],
@@ -67,12 +67,10 @@ export class BufferManager {
67
67
 
68
68
  const newArray = new Float32Array(newCapacity * itemSize);
69
69
  const bufferData = this._getBufferData(occupiedCapacity);
70
- // console.log("bufferData", bufferData);
71
70
  let newOffset = 0;
72
71
  for (const offset of offsetValues) {
73
72
  const itemOffset = offset * itemSize;
74
73
  newArray.set(bufferData.slice(itemOffset, itemOffset + itemSize), newOffset);
75
- // console.log("oldOffset", itemOffset, "newOffset", newOffset);
76
74
  newOffset += itemSize;
77
75
  }
78
76
 
@@ -87,7 +85,6 @@ export class BufferManager {
87
85
  const { gl, buffer, bufferType } = this;
88
86
  const itemSize = this.itemSize;
89
87
  const bufferData = this._getBufferData(occupiedCapacity);
90
- // console.log("extending buffer from", occupiedCapacity, "to", newCapacity, 'item size', itemSize);
91
88
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
92
89
  gl.bufferData(gl.ARRAY_BUFFER, newCapacity * itemSize * 4, gl[bufferType]);
93
90
  gl.bufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
@@ -96,9 +93,7 @@ export class BufferManager {
96
93
 
97
94
  _getBufferData(occupiedCapacity) {
98
95
  const { gl, buffer } = this;
99
- // console.log(occupiedCapacity, this.itemSize)
100
96
  const size = occupiedCapacity * this.itemSize;
101
- // console.log("size", size);
102
97
  const bufferData = new Float32Array(size);
103
98
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
104
99
  gl.getBufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
@@ -129,23 +129,26 @@ export class BufferOrchestrator {
129
129
  const { offsetMap } = this;
130
130
  const offsets = [];
131
131
  for (const item of items) {
132
- const offset = offsetMap.get(item.key) || this.nextOffset();
132
+ let o = offsetMap.get(item.key);
133
+ const offset = o !== undefined ? o : this.nextOffset();
133
134
  offsetMap.set(item.key, offset);
134
135
  offsets.push(offset);
135
136
  }
136
137
  for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
137
138
  bufferManager.insertBulk(items.map(adaptor), offsets);
138
139
  }
140
+
139
141
  }
140
142
 
141
143
 
142
- // doesnot assign offset to the new items.
144
+ // does not assign offset to the new items.
143
145
  updateBulk(items, bufferManagersMap, bufferKeys) {
144
146
  const { offsetMap } = this;
145
147
  const offsets = [];
146
148
  for (const item of items) {
147
149
  const offset = offsetMap.get(item.key);
148
- offsets.push(offset);
150
+ if (offset !== undefined) { offsets.push(offset); } else { throw new Error("updateBulk item Key does not exist"); }
151
+
149
152
  }
150
153
  if (bufferKeys) {
151
154
  for (const key of bufferKeys) {
@@ -174,7 +177,6 @@ export class BufferOrchestrator {
174
177
  for (const [key, { bufferManager }] of bufferManagersMap) {
175
178
  bufferManager.deleteBulk(offsets);
176
179
  }
177
- //console.log("deleteBulk after item size", this.offsetMap.size);
178
180
  }
179
181
 
180
182
 
@@ -198,9 +200,7 @@ export class BufferOrchestrator {
198
200
  autoExtendBuffers(itemsLength, bufferManagersMap) {
199
201
  if (itemsLength <= this.emptySpace) return;
200
202
  const newCapacity = this.length + itemsLength;
201
- //console.log("autoExtendBuffers", "item L", itemsLength, "E space", this.emptySpace, "cap", this.capacity, "length", this.length, 'new Cap', newCapacity);
202
203
  for (const [key, { bufferManager }] of bufferManagersMap) {
203
- //console.log("length", this.length, "newCapacity", newCapacity);
204
204
  bufferManager.extendBuffer(this.length, newCapacity);
205
205
  }
206
206
  this._capacity = newCapacity;
@@ -235,7 +235,6 @@ export class BufferOrchestrator {
235
235
  const newOffsetMap = new Map();
236
236
  let newOffset = 0;
237
237
  for (const [key, offset] of this.offsetMap) {
238
- //console.log("defrag", key, offset, newOffset);
239
238
  newOffsetMap.set(key, newOffset++);
240
239
  }
241
240
  this.offsetMap = newOffsetMap
@@ -134,7 +134,6 @@ export class ContextTextWriter2 {
134
134
  if (text == null) return;
135
135
  const opacity = this.opacityAdaptor(item, id, container, properties);
136
136
  const angle = this.angleAdaptor(item, id, container, properties);
137
- console.log(angle, "angle")
138
137
  const key = this.keyAdaptor(item, id, container, properties)
139
138
  this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity, angle });
140
139
  }