@pirireis/webglobeplugins 0.13.0-alpha → 0.14.0-alpha

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.
Files changed (54) hide show
  1. package/Math/arc-cdf-points.js +20 -0
  2. package/Math/arc-generate-points copy.js +1 -0
  3. package/Math/arc.js +21 -8
  4. package/Math/circle.js +35 -16
  5. package/Math/templete-shapes/grid-visually-equal.js +66 -0
  6. package/altitude-locator/plugin.js +3 -2
  7. package/bearing-line/plugin.js +1 -2
  8. package/circle-line-chain/plugin.js +4 -7
  9. package/compass-rose/compass-rose-padding-flat.js +12 -0
  10. package/package.json +1 -1
  11. package/programs/line-on-globe/degree-padding-around-circle-3d.js +1 -1
  12. package/programs/line-on-globe/linestrip/linestrip.js +5 -3
  13. package/programs/line-on-globe/naive-accurate-flexible.js +23 -16
  14. package/programs/picking/pickable-renderer.js +1 -2
  15. package/programs/rings/partial-ring/piece-of-pie copy.js +286 -0
  16. package/programs/rings/partial-ring/piece-of-pie.js +26 -13
  17. package/programs/totems/camerauniformblock.js +1 -1
  18. package/programs/totems/index.js +1 -1
  19. package/range-tools-on-terrain/bearing-line/adapters.js +111 -0
  20. package/range-tools-on-terrain/bearing-line/plugin.js +360 -0
  21. package/range-tools-on-terrain/circle-line-chain/adapters.js +83 -0
  22. package/range-tools-on-terrain/circle-line-chain/chain-list-map.js +351 -0
  23. package/range-tools-on-terrain/circle-line-chain/plugin.js +389 -0
  24. package/range-tools-on-terrain/circle-line-chain/types.js +1 -0
  25. package/range-tools-on-terrain/range-ring/adapters.js +25 -0
  26. package/range-tools-on-terrain/range-ring/plugin.js +31 -0
  27. package/range-tools-on-terrain/range-ring/types.js +1 -0
  28. package/rangerings/plugin.js +7 -11
  29. package/semiplugins/lightweight/line-plugin.js +195 -0
  30. package/semiplugins/lightweight/piece-of-pie-plugin.js +175 -0
  31. package/semiplugins/shape-on-terrain/arc-plugin.js +368 -0
  32. package/{shape-on-terrain/circle/plugin.js → semiplugins/shape-on-terrain/circle-plugin.js} +67 -38
  33. package/semiplugins/shape-on-terrain/derived/padding-plugin.js +96 -0
  34. package/semiplugins/type.js +1 -0
  35. package/types.js +0 -11
  36. package/util/account/create-buffermap-orchastration.js +39 -0
  37. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +14 -3
  38. package/util/check/typecheck.js +15 -1
  39. package/util/geometry/index.js +3 -2
  40. package/util/gl-util/buffer/attribute-loader.js +2 -5
  41. package/util/gl-util/draw-options/methods.js +4 -5
  42. package/util/webglobjectbuilders.js +4 -9
  43. package/write-text/context-text3.js +17 -0
  44. package/write-text/context-text3old.js +152 -0
  45. package/programs/line-on-globe/circle-accurate.js +0 -176
  46. package/programs/line-on-globe/circle.js +0 -166
  47. package/programs/line-on-globe/to-the-surface.js +0 -111
  48. package/programs/totems/canvas-webglobe-info1.js +0 -106
  49. package/shape-on-terrain/arc/naive/plugin.js +0 -250
  50. package/util/check/get.js +0 -14
  51. package/util/gl-util/buffer/types.js +0 -1
  52. package/util/gl-util/draw-options/types.js +0 -15
  53. package/util/webglobjectbuilders1.js +0 -219
  54. /package/{shape-on-terrain/type.js → range-tools-on-terrain/bearing-line/types.js} +0 -0
@@ -0,0 +1,360 @@
1
+ import { ContextTextWriter3 } from "../../write-text/context-text3";
2
+ import { flatLinesInputAdapter, flatLinesBearingInputAdapter, bearingLineToCircleInputAdapter, bearingLineToArcInputAdapter, bearingLineToBearingArcInputAdapter, bearingLineToPieceOfPieInputAdapter, pieceOfPieOpacityAdaptor } from "./adapters";
3
+ import { CircleOnTerrainPlugin } from "../../semiplugins/shape-on-terrain/circle-plugin";
4
+ import { PieceOfPiePlugin } from "../../semiplugins/lightweight/piece-of-pie-plugin";
5
+ import { ArcOnTerrainPlugin } from "../../semiplugins/shape-on-terrain/arc-plugin";
6
+ import { LinePlugin } from "../../semiplugins/lightweight/line-plugin";
7
+ export class BearingLinePlugin {
8
+ id;
9
+ globe = null;
10
+ circlePlugin;
11
+ arcPlugin;
12
+ arcPluginBL;
13
+ pieceOfPiePlugin;
14
+ linePlugin;
15
+ linePluginBL;
16
+ _freed = false;
17
+ _opacities = {
18
+ general: 1,
19
+ circle: 1,
20
+ arc: 1,
21
+ pie: 1,
22
+ bearing: 1
23
+ };
24
+ _textWritersMap = new Map();
25
+ _textDataPreAdaptor = (item) => item;
26
+ drawOptions = {
27
+ drawVRM: true,
28
+ drawBearingLine: true,
29
+ drawAngleRing: true,
30
+ drawText: true,
31
+ flatRealLineOn: true, // This is a new option to control flat real line drawing
32
+ flatStraightLineOn: true // This is a new option to control flat straight line drawing
33
+ };
34
+ _memory = new Map();
35
+ constructor(id, { textWritersMap, textDataPreAdaptor, opacities, drawOptions, } = {}) {
36
+ this.id = id;
37
+ if (!(textWritersMap instanceof Map))
38
+ throw new Error("textWritersMap is not an instance of Map");
39
+ textWritersMap.forEach((v) => {
40
+ if (!(v instanceof ContextTextWriter3))
41
+ throw new Error("textWritersMap element is not an instance of ContextTextWriter3");
42
+ });
43
+ this._textWritersMap = textWritersMap || new Map();
44
+ this._textWritersMap.forEach((writer) => writer.setKeyAdaptor((item) => item.key));
45
+ this._textDataPreAdaptor = textDataPreAdaptor || ((item) => item);
46
+ this.circlePlugin = new CircleOnTerrainPlugin(id + "_circle", {
47
+ variativeColorsOn: true,
48
+ });
49
+ this.arcPlugin = new ArcOnTerrainPlugin(id + "_arc", {
50
+ variativeColorsOn: true,
51
+ });
52
+ this.arcPluginBL = new ArcOnTerrainPlugin(id + "_arcBL", {
53
+ variativeColorsOn: true,
54
+ });
55
+ this.pieceOfPiePlugin = new PieceOfPiePlugin(id + "_pieceOfPie", {
56
+ bufferType: "DYNAMIC_DRAW",
57
+ });
58
+ this.linePlugin = new LinePlugin(id + "_line", {
59
+ variativeColorsOn: true,
60
+ bufferType: "DYNAMIC_DRAW",
61
+ });
62
+ this.linePluginBL = new LinePlugin(id + "_lineBL", {
63
+ variativeColorsOn: true,
64
+ bufferType: "DYNAMIC_DRAW",
65
+ });
66
+ if (opacities) {
67
+ this._opacities = {
68
+ ...this._opacities,
69
+ ...opacities,
70
+ };
71
+ }
72
+ if (drawOptions) {
73
+ this.drawOptions = {
74
+ ...this.drawOptions,
75
+ ...drawOptions
76
+ };
77
+ }
78
+ }
79
+ setDoDrawVRM(drawVRM) {
80
+ if (this._freed) {
81
+ throw new Error("Plugin has been freed, cannot set draw VRM.");
82
+ }
83
+ if (!this.globe) {
84
+ throw new Error("Globe is not set, cannot set draw VRM.");
85
+ }
86
+ this.drawOptions.drawVRM = drawVRM;
87
+ this.globe.DrawRender();
88
+ }
89
+ setDoDrawText(drawText) {
90
+ if (this._freed) {
91
+ throw new Error("Plugin has been freed, cannot set draw text.");
92
+ }
93
+ if (!this.globe) {
94
+ throw new Error("Globe is not set, cannot set draw text.");
95
+ }
96
+ this.drawOptions.drawText = drawText;
97
+ this.globe.DrawRender();
98
+ }
99
+ setDoDrawBearingLine(drawBearingLine) {
100
+ if (this._freed) {
101
+ throw new Error("Plugin has been freed, cannot set draw bearing line.");
102
+ }
103
+ if (!this.globe) {
104
+ throw new Error("Globe is not set, cannot set draw bearing line.");
105
+ }
106
+ this.drawOptions.drawBearingLine = drawBearingLine;
107
+ this.globe.DrawRender();
108
+ }
109
+ setDoDrawAngleRing(drawAngleRing) {
110
+ if (this._freed) {
111
+ throw new Error("Plugin has been freed, cannot set draw angle ring.");
112
+ }
113
+ if (!this.globe) {
114
+ throw new Error("Globe is not set, cannot set draw angle ring.");
115
+ }
116
+ this.drawOptions.drawAngleRing = drawAngleRing;
117
+ this.globe.DrawRender();
118
+ }
119
+ // TODO:
120
+ updatePartial(items, { textWriterIDs } = {}) {
121
+ if (this._freed) {
122
+ throw new Error("Plugin has been freed, cannot update item.");
123
+ }
124
+ if (!this.globe) {
125
+ throw new Error("Globe is not set, cannot update item.");
126
+ }
127
+ const fixedItems = [];
128
+ for (const item of items) {
129
+ if (!this._memory.has(item.key)) {
130
+ throw new Error(`Item with key ${item.key} not found in memory.`);
131
+ }
132
+ fixedItems.push(this.__memorizeItem(item));
133
+ }
134
+ this._build(fixedItems, { textWriterIDs });
135
+ }
136
+ setDrawOptions(drawOptions) {
137
+ if (this._freed) {
138
+ throw new Error("Plugin has been freed, cannot set draw options.");
139
+ }
140
+ if (!this.globe) {
141
+ throw new Error("Globe is not set, cannot set draw options.");
142
+ }
143
+ this.drawOptions = {
144
+ ...this.drawOptions,
145
+ ...drawOptions
146
+ };
147
+ this.globe.DrawRender();
148
+ }
149
+ updateCoordinatesBulk(items, { textWriterIDs } = {}) {
150
+ if (this._freed) {
151
+ throw new Error("Plugin has been freed, cannot update coordinates.");
152
+ }
153
+ if (!this.globe) {
154
+ throw new Error("Globe is not set, cannot update coordinates.");
155
+ }
156
+ const fixedItems = [];
157
+ for (const item of items) {
158
+ if (!this._memory.has(item.key)) {
159
+ throw new Error(`Item with key ${item.key} not found in memory.`);
160
+ }
161
+ else {
162
+ fixedItems.push(this.__memorizeItem(item));
163
+ }
164
+ }
165
+ this._build(fixedItems, { textWriterIDs });
166
+ }
167
+ setOpacities(opacities) {
168
+ if (this._freed) {
169
+ throw new Error("Plugin has been freed, cannot set opacities.");
170
+ }
171
+ if (!this.globe) {
172
+ throw new Error("Globe is not set, cannot set opacities.");
173
+ }
174
+ this._opacities = {
175
+ ...this._opacities,
176
+ ...opacities,
177
+ };
178
+ this.globe.DrawRender();
179
+ }
180
+ insertBulk(items, { textWriterIDs } = {}) {
181
+ this._build(items, { textWriterIDs });
182
+ }
183
+ deleteBulk(keys) {
184
+ if (this._freed) {
185
+ throw new Error("Plugin has been freed, cannot delete items.");
186
+ }
187
+ if (!this.globe) {
188
+ throw new Error("Globe is not set, cannot delete items.");
189
+ }
190
+ if (!this.circlePlugin || !this.arcPlugin) {
191
+ throw new Error("Circle and Arc plugins are not initialized.");
192
+ }
193
+ this.circlePlugin.deleteBulk(keys);
194
+ this.arcPlugin.deleteBulk(keys);
195
+ this.arcPluginBL.deleteBulk(keys);
196
+ this.pieceOfPiePlugin.deleteBulk(keys);
197
+ this.linePlugin.deleteBulk(keys);
198
+ this.linePluginBL.deleteBulk(keys);
199
+ this.__deleteTexts(keys);
200
+ this.globe.DrawRender();
201
+ }
202
+ updateText(textWriterIDs, itemKeys = null) {
203
+ if (this._freed) {
204
+ throw new Error("Plugin has been freed, cannot update text.");
205
+ }
206
+ const items = itemKeys ? itemKeys.map(key => this._memory.get(key)).filter(Boolean) : Array.from(this._memory.values());
207
+ this.__insertTexts(items, textWriterIDs);
208
+ }
209
+ _calculateRadiusFromBearingLine(bearingLine) {
210
+ const { long, lat, endLong, endLat } = bearingLine;
211
+ // @ts-ignore
212
+ bearingLine.radius = this.globe.Math.GetDist2D(long, lat, endLong, endLat);
213
+ }
214
+ __deleteTexts(keys) {
215
+ if (this._freed) {
216
+ throw new Error("Plugin has been freed, cannot delete texts.");
217
+ }
218
+ if (!this.globe) {
219
+ throw new Error("Globe is not set, cannot delete texts.");
220
+ }
221
+ for (const textWriter of this._textWritersMap.values()) {
222
+ textWriter.deleteTextBulk(keys);
223
+ }
224
+ keys.forEach(key => {
225
+ this._memory.delete(key);
226
+ });
227
+ }
228
+ __insertTexts(items, textWriterIDs = []) {
229
+ if (this._freed) {
230
+ throw new Error("Plugin has been freed, cannot insert texts.");
231
+ }
232
+ if (!this.globe) {
233
+ throw new Error("Globe is not set, cannot insert texts.");
234
+ }
235
+ if (textWriterIDs.length === 0) {
236
+ textWriterIDs = Array.from(this._textWritersMap.keys());
237
+ }
238
+ // check textWriterIDs
239
+ for (const textWriterID of textWriterIDs) {
240
+ const textWriter = this._textWritersMap.get(textWriterID);
241
+ if (!textWriter) {
242
+ throw new Error(`Text writer with ID ${textWriterID} not found.`);
243
+ }
244
+ }
245
+ for (const textWriterID of textWriterIDs) {
246
+ const textWriter = this._textWritersMap.get(textWriterID);
247
+ if (textWriter) {
248
+ textWriter.insertTextBulk(items.map(x => this._textDataPreAdaptor(x)), textWriterID);
249
+ }
250
+ }
251
+ }
252
+ __memorizeItem(item) {
253
+ const oldItem = this._memory.get(item.key);
254
+ let newItem = oldItem ? { ...oldItem, ...item } : item;
255
+ this._memory.set(item.key, newItem);
256
+ return newItem;
257
+ }
258
+ _build(items, { textWriterIDs } = {}) {
259
+ if (this._freed) {
260
+ throw new Error("Plugin has been freed, cannot update coordinates.");
261
+ }
262
+ if (!this.globe) {
263
+ throw new Error("Globe is not set, cannot update coordinates.");
264
+ }
265
+ if (!this.circlePlugin || !this.arcPlugin) {
266
+ throw new Error("Circle and Arc plugins are not initialized.");
267
+ }
268
+ items.forEach(item => {
269
+ this._calculateRadiusFromBearingLine(item);
270
+ });
271
+ const processedItems = items.map((item) => this.__memorizeItem(item));
272
+ // @ts-ignore
273
+ const circleInputs = processedItems.map(bearingLineToCircleInputAdapter(this.globe));
274
+ this.circlePlugin.insertBulk(circleInputs);
275
+ const arcInputs = processedItems.map(bearingLineToArcInputAdapter);
276
+ this.arcPlugin.insertBulk(arcInputs);
277
+ // @ts-ignore
278
+ const bearingArcInputs = processedItems.map((x) => bearingLineToBearingArcInputAdapter(this.globe, x));
279
+ this.arcPluginBL.insertBulk(bearingArcInputs);
280
+ this.__insertTexts(processedItems, textWriterIDs);
281
+ // @ts-ignore
282
+ const pieceOfPieInputs = processedItems.map((x) => bearingLineToPieceOfPieInputAdapter(this.globe, x));
283
+ this.pieceOfPiePlugin.insertBulk(pieceOfPieInputs);
284
+ // line inputs
285
+ const lineInputs = processedItems.map(flatLinesInputAdapter);
286
+ this.linePlugin.insertBulk(lineInputs);
287
+ const lineInputsBL = processedItems.map(flatLinesBearingInputAdapter);
288
+ this.linePluginBL.insertBulk(lineInputsBL);
289
+ // @ts-ignore
290
+ this.globe.DrawRender();
291
+ }
292
+ // globe API
293
+ init(globe, gl) {
294
+ if (this._freed) {
295
+ throw new Error("Plugin has been freed, cannot initialize.");
296
+ }
297
+ this.globe = globe;
298
+ this.circlePlugin.init(globe, gl);
299
+ this.arcPlugin.init(globe, gl);
300
+ this.arcPluginBL.init(globe, gl);
301
+ this.linePlugin.init(globe, gl);
302
+ this.linePluginBL.init(globe, gl);
303
+ this.pieceOfPiePlugin.init(globe, gl);
304
+ }
305
+ draw3D() {
306
+ if (this._freed) {
307
+ throw new Error("Plugin has been freed, cannot draw.");
308
+ }
309
+ if (!this.globe) {
310
+ throw new Error("Globe is not set, cannot draw.");
311
+ }
312
+ if (!this.circlePlugin || !this.arcPlugin) {
313
+ throw new Error("Circle and Arc plugins are not initialized.");
314
+ }
315
+ if (this.drawOptions.drawVRM) {
316
+ this.circlePlugin.setPluginOpacity(this._opacities.circle ?? this._opacities.general);
317
+ this.circlePlugin.draw3D();
318
+ }
319
+ if (this.drawOptions.drawBearingLine) {
320
+ this.arcPluginBL.setPluginOpacity(this._opacities.arc ?? this._opacities.general);
321
+ this.arcPluginBL.draw3D();
322
+ }
323
+ if (this.drawOptions.drawAngleRing) {
324
+ const currentLOD = this.globe.api_GetCurrentLODWithDecimal();
325
+ const tiltAngle = this.globe.api_GetCurrentLookInfo().Tilt;
326
+ const opacity = pieceOfPieOpacityAdaptor(currentLOD, tiltAngle) * (this._opacities.general ?? 1);
327
+ if (opacity > 0) {
328
+ this.pieceOfPiePlugin.setPluginOpacity(opacity);
329
+ this.pieceOfPiePlugin.draw3D();
330
+ }
331
+ }
332
+ const currentGeometry = this.globe.api_GetCurrentGeometry();
333
+ this.arcPlugin.setPluginOpacity(this._opacities.arc ?? this._opacities.general);
334
+ this.arcPlugin.draw3D();
335
+ if (currentGeometry === 1) {
336
+ this.linePlugin.draw3D();
337
+ this.linePluginBL.draw3D();
338
+ }
339
+ if (this.drawOptions.drawAngleRing) {
340
+ for (const textWriter of this._textWritersMap.values()) {
341
+ textWriter.draw();
342
+ }
343
+ }
344
+ }
345
+ free() {
346
+ if (this._freed) {
347
+ throw new Error("Plugin has already been freed.");
348
+ }
349
+ this._freed = true;
350
+ this.globe = null;
351
+ this._memory.clear();
352
+ this._textWritersMap.clear();
353
+ this.circlePlugin.free();
354
+ this.arcPlugin.free();
355
+ this.arcPluginBL.free();
356
+ this.pieceOfPiePlugin.free();
357
+ this.linePlugin.free();
358
+ this.linePluginBL.free();
359
+ }
360
+ }
@@ -0,0 +1,83 @@
1
+ export const keyMethod = (chainKey, nodeKey) => `${chainKey}_${nodeKey}`;
2
+ const distance = (node1, node2) => {
3
+ const dx = node1.long - node2.long;
4
+ const dy = node1.lat - node2.lat;
5
+ return Math.sqrt(dx * dx + dy * dy);
6
+ };
7
+ export const circleDataAdaptor = (globe, chain) => {
8
+ const circleInputs = [];
9
+ const { chainKey, chainProperties, nodes } = chain;
10
+ for (let i = 0; i < nodes.length - 1; i++) {
11
+ const node = nodes[i];
12
+ const { key, long, lat, circleProperties } = node;
13
+ const color = circleProperties?.rgba ?? chainProperties.rgba ?? [1, 1, 1, 1]; // Default color if not specified
14
+ if (key === "Sakarya") {
15
+ console.log("circleProperties", circleProperties, "chainProperties", chainProperties);
16
+ console.log("Sakarya color", color);
17
+ }
18
+ const radius = globe.Math.GetDist2D(long, lat, nodes[i + 1].long, nodes[i + 1].lat);
19
+ const nodeKey = keyMethod(chainKey, key);
20
+ circleInputs.push({
21
+ key: nodeKey,
22
+ center: [long, lat],
23
+ radius,
24
+ height: chainProperties.altitude ?? 0,
25
+ color: color,
26
+ });
27
+ }
28
+ return circleInputs;
29
+ };
30
+ export function arcDataAdaptor(chain) {
31
+ const arcInputs = [];
32
+ const { chainKey, chainProperties, nodes } = chain;
33
+ for (let i = 0; i < nodes.length - 1; i++) {
34
+ const node = nodes[i];
35
+ const nextNode = nodes[i + 1];
36
+ const { key, long, lat, lineProperties } = node;
37
+ const nodeKey = keyMethod(chainKey, key);
38
+ const { long: nextLong, lat: nextLat } = nextNode;
39
+ const color = lineProperties?.rgba ?? chainProperties.rgba ?? [1, 1, 1, 1]; // Default color if not specified
40
+ arcInputs.push({
41
+ key: nodeKey,
42
+ start: [long, lat],
43
+ end: [nextLong, nextLat],
44
+ height: chainProperties.altitude ?? 0,
45
+ color: color,
46
+ });
47
+ }
48
+ return arcInputs;
49
+ }
50
+ export function lineDataAdaptor(chain) {
51
+ const lineInputs = [];
52
+ const { chainKey, chainProperties, nodes } = chain;
53
+ for (let i = 0; i < nodes.length - 1; i++) {
54
+ const node = nodes[i];
55
+ const nextNode = nodes[i + 1];
56
+ const { key, long, lat, lineProperties } = node;
57
+ const nodeKey = keyMethod(chainKey, key);
58
+ const { long: nextLong, lat: nextLat } = nextNode;
59
+ const color = lineProperties?.rgba ?? chainProperties.rgba ?? [1, 1, 1, 1]; // Default color if not specified
60
+ lineInputs.push({
61
+ key: nodeKey,
62
+ start: [long, lat],
63
+ end: [nextLong, nextLat],
64
+ start_altitude: chainProperties.altitude ?? 0,
65
+ end_altitude: chainProperties.altitude ?? 0,
66
+ color: color,
67
+ });
68
+ }
69
+ return lineInputs;
70
+ }
71
+ export function getOpacity(opacities, key) {
72
+ return opacities[key] ?? opacities.general ?? 1;
73
+ }
74
+ export function nodeKeysFromChain(chainKey, nodes) {
75
+ return nodes.map((node) => keyMethod(chainKey, node.key));
76
+ }
77
+ export function clipANodeReturnIndex(nodes, nodeKey) {
78
+ const index = nodes.findIndex(node => node.key === nodeKey);
79
+ if (index === -1) {
80
+ throw new Error(`Node with key ${nodeKey} not found in the chain.`);
81
+ }
82
+ nodes.splice(index, 1); // Remove the node from the array
83
+ }