@pirireis/webglobeplugins 0.13.0-alpha → 0.15.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.
- package/Math/arc-cdf-points.js +20 -0
- package/Math/arc-generate-points copy.js +1 -0
- package/Math/arc.js +21 -8
- package/Math/circle.js +35 -16
- package/Math/templete-shapes/grid-visually-equal.js +66 -0
- package/altitude-locator/plugin.js +3 -2
- package/bearing-line/plugin.js +1 -2
- package/circle-line-chain/plugin.js +4 -7
- package/compass-rose/compass-rose-padding-flat.js +12 -0
- package/package.json +1 -1
- package/programs/line-on-globe/degree-padding-around-circle-3d.js +1 -1
- package/programs/line-on-globe/linestrip/linestrip.js +6 -4
- package/programs/line-on-globe/naive-accurate-flexible.js +23 -16
- package/programs/picking/pickable-renderer.js +1 -2
- package/programs/rings/partial-ring/piece-of-pie copy.js +286 -0
- package/programs/rings/partial-ring/piece-of-pie.js +26 -13
- package/programs/totems/camerauniformblock.js +1 -1
- package/programs/totems/index.js +1 -1
- package/range-tools-on-terrain/bearing-line/adapters.js +111 -0
- package/range-tools-on-terrain/bearing-line/plugin.js +360 -0
- package/range-tools-on-terrain/circle-line-chain/adapters.js +83 -0
- package/range-tools-on-terrain/circle-line-chain/chain-list-map.js +351 -0
- package/range-tools-on-terrain/circle-line-chain/plugin.js +388 -0
- package/range-tools-on-terrain/circle-line-chain/types.js +1 -0
- package/range-tools-on-terrain/range-ring/adapters.js +25 -0
- package/range-tools-on-terrain/range-ring/plugin.js +31 -0
- package/range-tools-on-terrain/range-ring/types.js +1 -0
- package/rangerings/plugin.js +7 -11
- package/semiplugins/lightweight/line-plugin.js +195 -0
- package/semiplugins/lightweight/piece-of-pie-plugin.js +175 -0
- package/semiplugins/shape-on-terrain/arc-plugin.js +368 -0
- package/{shape-on-terrain/circle/plugin.js → semiplugins/shape-on-terrain/circle-plugin.js} +67 -38
- package/semiplugins/shape-on-terrain/derived/padding-plugin.js +101 -0
- package/semiplugins/shape-on-terrain/one-degree-padding.js +85 -0
- package/semiplugins/type.js +1 -0
- package/types.js +0 -11
- package/util/account/create-buffermap-orchastration.js +39 -0
- package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +14 -3
- package/util/check/typecheck.js +15 -1
- package/util/geometry/index.js +3 -2
- package/util/gl-util/buffer/attribute-loader.js +2 -5
- package/util/gl-util/draw-options/methods.js +4 -5
- package/util/webglobjectbuilders.js +5 -10
- package/write-text/context-text3.js +17 -0
- package/write-text/context-text3old.js +152 -0
- package/programs/line-on-globe/circle-accurate.js +0 -176
- package/programs/line-on-globe/circle.js +0 -166
- package/programs/line-on-globe/to-the-surface.js +0 -111
- package/programs/totems/canvas-webglobe-info1.js +0 -106
- package/shape-on-terrain/arc/naive/plugin.js +0 -250
- package/util/check/get.js +0 -14
- package/util/gl-util/draw-options/types.js +0 -15
- package/util/webglobjectbuilders1.js +0 -219
- /package/{util/gl-util/buffer/types.js → programs/line-on-globe/paddings/paddings.js} +0 -0
- /package/{shape-on-terrain/type.js → range-tools-on-terrain/bearing-line/types.js} +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ArcOnTerrainPlugin } from "../arc-plugin";
|
|
2
|
+
const EDGE_COUNT = 5;
|
|
3
|
+
const paddingKeys = (padding) => {
|
|
4
|
+
const stepCount = padding.coverAngle / padding.stepAngle;
|
|
5
|
+
const keys = new Array(Math.ceil(stepCount));
|
|
6
|
+
for (let i = 0; i < stepCount; i++) {
|
|
7
|
+
keys[i] = padding.key + i;
|
|
8
|
+
}
|
|
9
|
+
if (keys.length > stepCount) {
|
|
10
|
+
keys[keys.length - 1] = padding.key + stepCount;
|
|
11
|
+
}
|
|
12
|
+
return keys;
|
|
13
|
+
};
|
|
14
|
+
const adapterPadding2Arc = (globe, padding) => {
|
|
15
|
+
const stepCount = padding.coverAngle / padding.stepAngle;
|
|
16
|
+
const result = new Array(Math.ceil(stepCount));
|
|
17
|
+
const fill = (i, angle) => {
|
|
18
|
+
const startPoint = globe.Math.FindPointByPolar(padding.center[0], padding.center[1], padding.outerRadius, angle);
|
|
19
|
+
const endPoint = globe.Math.FindPointByPolar(padding.center[0], padding.center[1], padding.innerRadius, angle);
|
|
20
|
+
result[i] = {
|
|
21
|
+
key: padding.key + i,
|
|
22
|
+
start: [startPoint.long, startPoint.lat],
|
|
23
|
+
end: [endPoint.long, endPoint.lat],
|
|
24
|
+
color: padding.color,
|
|
25
|
+
height: padding.height,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
for (let i = 0; i < stepCount; i++) {
|
|
29
|
+
const angle = padding.startAngle + i * padding.stepAngle;
|
|
30
|
+
fill(i, angle);
|
|
31
|
+
}
|
|
32
|
+
if (result.length > stepCount) {
|
|
33
|
+
const i = result.length - 1;
|
|
34
|
+
const angle = padding.startAngle + padding.coverAngle;
|
|
35
|
+
fill(i, angle);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
export const chargerAdaptor = (chargerInput, plugin, padding) => {
|
|
40
|
+
};
|
|
41
|
+
export class PaddingPlugin {
|
|
42
|
+
id;
|
|
43
|
+
arcPlugin;
|
|
44
|
+
globe = null;
|
|
45
|
+
_memory = new Map();
|
|
46
|
+
isFreed = false;
|
|
47
|
+
constructor(id, { variativeColorsOn = true, defaultColor = [1, 1, 1, 1], defaultHeightFromGroundIn3D = 30.0, vertexCount = EDGE_COUNT } = {}) {
|
|
48
|
+
this.id = id;
|
|
49
|
+
this.arcPlugin = new ArcOnTerrainPlugin(id, {
|
|
50
|
+
cameraAttractionIsOn: false,
|
|
51
|
+
vertexCount: vertexCount,
|
|
52
|
+
variativeColorsOn: variativeColorsOn,
|
|
53
|
+
defaultColor: defaultColor,
|
|
54
|
+
defaultHeightFromGroundIn3D: defaultHeightFromGroundIn3D,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
insertBulk(items) {
|
|
58
|
+
for (const padding of items) {
|
|
59
|
+
this.__delete(padding.key);
|
|
60
|
+
this._memory.set(padding.key, padding);
|
|
61
|
+
}
|
|
62
|
+
const arcInputs = items.flatMap(padding => adapterPadding2Arc(this.globe, padding));
|
|
63
|
+
this.arcPlugin.insertBulk(arcInputs);
|
|
64
|
+
}
|
|
65
|
+
deleteBulk(keys) {
|
|
66
|
+
const arcKeys = keys.flatMap(key => paddingKeys({ key, center: [0, 0], outerRadius: 0, innerRadius: 0, startAngle: 0, coverAngle: 0, stepAngle: 0, color: [0, 0, 0, 1] }));
|
|
67
|
+
this.arcPlugin.deleteBulk(arcKeys);
|
|
68
|
+
}
|
|
69
|
+
updateColor(key, color) {
|
|
70
|
+
// TODO: get all padding keys and update all of them
|
|
71
|
+
if (!this._memory.has(key)) {
|
|
72
|
+
console.warn(`Padding with key ${key} does not exist.`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const keys = paddingKeys(this._memory.get(key));
|
|
76
|
+
for (let i = 0; i < keys.length; i++) {
|
|
77
|
+
this.arcPlugin.updateColor(keys[i], color);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
__delete(key) {
|
|
81
|
+
const padding = this._memory.get(key);
|
|
82
|
+
if (padding) {
|
|
83
|
+
const keys = paddingKeys(padding);
|
|
84
|
+
this.arcPlugin.deleteBulk(keys);
|
|
85
|
+
this._memory.delete(key);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
init(globe, gl) {
|
|
89
|
+
this.globe = globe;
|
|
90
|
+
this.arcPlugin.init(globe, gl);
|
|
91
|
+
}
|
|
92
|
+
draw3D() {
|
|
93
|
+
this.arcPlugin.draw3D();
|
|
94
|
+
}
|
|
95
|
+
free() {
|
|
96
|
+
if (this.isFreed)
|
|
97
|
+
return;
|
|
98
|
+
this.isFreed = true;
|
|
99
|
+
this.arcPlugin.free();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// // One Degree Padding
|
|
3
|
+
// /**
|
|
4
|
+
// * 2d coordinates are loaded ones
|
|
5
|
+
// * 3d coordinates are calculated on the fly.
|
|
6
|
+
// *
|
|
7
|
+
// * 2d paddings are fixed size
|
|
8
|
+
// * 3d paddings gets shortened as lod increases
|
|
9
|
+
// *
|
|
10
|
+
// * color buffer is shared and does not change on unless insert or delete
|
|
11
|
+
// * changing color can be done by re inserting
|
|
12
|
+
// *
|
|
13
|
+
// *
|
|
14
|
+
// *
|
|
15
|
+
// */
|
|
16
|
+
// import { Globe, LongLat, Meter, Color } from '../../types';
|
|
17
|
+
// import { BufferManagersMap } from '../../util/account/single-attribute-buffer-management/types';
|
|
18
|
+
// import { BufferManager } from '../../util/account/single-attribute-buffer-management/buffer-manager';
|
|
19
|
+
// import { BufferOrchestrator } from '../../util/acconut/single-attribute-buffer-management/buffer-orchestrator';
|
|
20
|
+
// import { LineStripProgramCache, LineProgram } from '../../programs/line-on-globe/linestrip/linestrip';
|
|
21
|
+
// import { ProgramInterface } from '../../types';
|
|
22
|
+
// export type OneDegreePaddingInput = {
|
|
23
|
+
// key: string;
|
|
24
|
+
// center: LongLat;
|
|
25
|
+
// outerRadius: Meter;
|
|
26
|
+
// color: Color;
|
|
27
|
+
// };
|
|
28
|
+
// const _float32Array = new Float32Array(360 * 3 * 2).fill(NaN);
|
|
29
|
+
// export class Paddings1Degree implements ProgramInterface {
|
|
30
|
+
// id: string;
|
|
31
|
+
// private globe: Globe | null = null;
|
|
32
|
+
// private bufferOrchestrator: BufferOrchestrator;
|
|
33
|
+
// private bufferManagersMap: BufferManagersMap;
|
|
34
|
+
// private lineProgram: LineProgram | null = null;
|
|
35
|
+
// private _LODCoeffecientForPaddingScale: number = 1;
|
|
36
|
+
// private _PaddingSizeRatio = 0.1; // 0.1 means 10% of the padding size is used for 3d padding
|
|
37
|
+
// private _finalPaddingSizeRatio = 0.1; // this._LODCoefficientForPaddingScale * this._PaddingSizeRatio; // final padding size ratio is the product of LOD coefficient and padding size ratio
|
|
38
|
+
// constructor(id: string, { capacity = 1000 } = {}) {
|
|
39
|
+
// this.id = id;
|
|
40
|
+
// this.bufferOrchestrator = new BufferOrchestrator({ capacity });
|
|
41
|
+
// this.bufferManagersMap = new Map();
|
|
42
|
+
// this.lineProgram = null;
|
|
43
|
+
// }
|
|
44
|
+
// init(globe: Globe): void {
|
|
45
|
+
// this.globe = globe;
|
|
46
|
+
// this.lineProgram = LineStripProgramCache.get(globe);
|
|
47
|
+
// }
|
|
48
|
+
// __updateLODCoefficientForPaddingScale(): void {
|
|
49
|
+
// // TODO: call this ones when lod changes or each frame // maybe only on 3d geometry
|
|
50
|
+
// }
|
|
51
|
+
// __fillBufferManagersMap() {
|
|
52
|
+
// const globe = this.globe as Globe;
|
|
53
|
+
// const gl = globe.gl as WebGL2RenderingContext;
|
|
54
|
+
// this.bufferManagersMap.set("position2d", {
|
|
55
|
+
// bufferManager: new BufferManager(gl,
|
|
56
|
+
// 360 * (2 + 1), // plus 1 to cut
|
|
57
|
+
// { bufferType: "STATIC_DRAW", initialCapacity: 10 }),
|
|
58
|
+
// adaptor: (PaddingInput: OneDegreePaddingInput) => {
|
|
59
|
+
// for (let i = 0; i < 360; i++) {
|
|
60
|
+
// let { long, lat } = globe.Math.FindPointByPolar(
|
|
61
|
+
// PaddingInput.center[0], // center long
|
|
62
|
+
// PaddingInput.center[1], // center lat
|
|
63
|
+
// PaddingInput.outerRadius, // outer radius
|
|
64
|
+
// i, // angle
|
|
65
|
+
// )
|
|
66
|
+
// let corrds = globe.api_GetMercator2DPoint(long, lat);
|
|
67
|
+
// // fill the second coordinate with 0
|
|
68
|
+
// _float32Array[i * 3] = corrds[0];
|
|
69
|
+
// _float32Array[i * 3 + 1] = corrds[1];
|
|
70
|
+
// ({ long, lat } = globe.Math.FindPointByPolar(
|
|
71
|
+
// PaddingInput.center[0], // center long
|
|
72
|
+
// PaddingInput.center[1], // center lat
|
|
73
|
+
// PaddingInput.outerRadius * this._finalPaddingSizeRatio, // inner radius
|
|
74
|
+
// i, // angle
|
|
75
|
+
// ));
|
|
76
|
+
// let innerCorrds = globe.api_GetMercator2DPoint(long, lat);
|
|
77
|
+
// // fill the second coordinate with 0
|
|
78
|
+
// _float32Array[i * 3 + 2] = innerCorrds[0];
|
|
79
|
+
// _float32Array[i * 3 + 3] = innerCorrds[1];
|
|
80
|
+
// }
|
|
81
|
+
// return _float32Array;
|
|
82
|
+
// }
|
|
83
|
+
// });
|
|
84
|
+
// // Other methods like draw, insertBulk, deleteBulk, etc. would go here
|
|
85
|
+
// }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types.js
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef DrawRange
|
|
3
|
-
* @type {Object}
|
|
4
|
-
* @property {int} first
|
|
5
|
-
* @property {int} count
|
|
6
|
-
*
|
|
7
|
-
* @typedef DrawRangeIndexParamsClient
|
|
8
|
-
* @type {Object}
|
|
9
|
-
* @property {null|DrawRange} drawRange
|
|
10
|
-
* @property {null|Int32List} indexes
|
|
11
|
-
*/
|
|
12
1
|
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// IN construction
|
|
2
|
+
import { BufferManager } from "./single-attribute-buffer-management/buffer-manager";
|
|
3
|
+
import { BufferOrchestrator } from "./single-attribute-buffer-management/buffer-orchestrator";
|
|
4
|
+
export class BufferMapOrchestrator {
|
|
5
|
+
gl;
|
|
6
|
+
bufferManagersMap;
|
|
7
|
+
bufferOrchestrator;
|
|
8
|
+
constructor(gl, bufferDetailsMap, initialCapacity = 10) {
|
|
9
|
+
this.gl = gl;
|
|
10
|
+
this.bufferManagersMap = new Map();
|
|
11
|
+
this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
|
|
12
|
+
for (const [key, details] of bufferDetailsMap) {
|
|
13
|
+
const { itemSize, bufferType, adaptor } = details;
|
|
14
|
+
const bufferManager = new BufferManager(gl, itemSize, { bufferType, initialCapacity });
|
|
15
|
+
this.bufferManagersMap.set(key, { bufferManager, adaptor });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
insertBulk(items) {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
this.bufferOrchestrator.insertBulk(items, this.bufferManagersMap);
|
|
21
|
+
}
|
|
22
|
+
updateBulk(items, bufferKeys = []) {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
this.bufferOrchestrator.updateBulk(items, this.bufferManagersMap, bufferKeys);
|
|
25
|
+
}
|
|
26
|
+
deleteBulk(keys) {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
this.bufferOrchestrator.deleteBulk(keys, this.bufferManagersMap);
|
|
29
|
+
}
|
|
30
|
+
resetWithCapacity(capacity) {
|
|
31
|
+
this.bufferOrchestrator.resetWithCapacity(this.bufferManagersMap, capacity);
|
|
32
|
+
}
|
|
33
|
+
free() {
|
|
34
|
+
for (const [key, { bufferManager }] of this.bufferManagersMap) {
|
|
35
|
+
bufferManager.free();
|
|
36
|
+
}
|
|
37
|
+
this.bufferManagersMap.clear();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -19,7 +19,7 @@ export class BufferOrchestrator {
|
|
|
19
19
|
this.tombstoneOffsets = [];
|
|
20
20
|
this._length = 0;
|
|
21
21
|
}
|
|
22
|
-
insertBulk(items, bufferManagersMap) {
|
|
22
|
+
insertBulk(items, bufferManagersMap, bufferKeys = null) {
|
|
23
23
|
this.ensureSpace(items.length, bufferManagersMap);
|
|
24
24
|
const { offsetMap } = this;
|
|
25
25
|
const offsets = [];
|
|
@@ -29,8 +29,19 @@ export class BufferOrchestrator {
|
|
|
29
29
|
offsetMap.set(item.key, offset);
|
|
30
30
|
offsets.push(offset);
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (bufferKeys) {
|
|
33
|
+
for (const key of bufferKeys) {
|
|
34
|
+
const bufferManagerComp = bufferManagersMap.get(key);
|
|
35
|
+
if (bufferManagerComp === undefined)
|
|
36
|
+
throw new Error("insertBulk bufferKey does not exist");
|
|
37
|
+
const { bufferManager, adaptor } = bufferManagerComp;
|
|
38
|
+
bufferManager.insertBulk(items.map(adaptor), offsets);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
|
|
43
|
+
bufferManager.insertBulk(items.map(adaptor), offsets);
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
46
|
}
|
|
36
47
|
// does not assign offset to the new items.
|
package/util/check/typecheck.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const doesOwnProperties = (properties, errorMessage) => {
|
|
3
3
|
return (object) => {
|
|
4
4
|
properties.forEach(element => {
|
|
5
|
-
if (!
|
|
5
|
+
if (!object.hasOwnProperty(element))
|
|
6
6
|
throw new TypeError(errorMessage + ':' + element);
|
|
7
7
|
});
|
|
8
8
|
};
|
|
@@ -38,3 +38,17 @@ export const isBoolean = (x) => {
|
|
|
38
38
|
if (typeof x !== "boolean")
|
|
39
39
|
throw new TypeError("type must be boolean");
|
|
40
40
|
};
|
|
41
|
+
export const mapGetOrThrow = (errorNote) => {
|
|
42
|
+
return (mapInstance, ids) => {
|
|
43
|
+
if (!ids)
|
|
44
|
+
throw new Error("There is no map keys to get");
|
|
45
|
+
const result = [];
|
|
46
|
+
for (let i = 0; i < ids.length; i++) {
|
|
47
|
+
const e = mapInstance.get(ids[i]);
|
|
48
|
+
if (e === undefined)
|
|
49
|
+
throw new Error(errorNote + " " + ids[i]);
|
|
50
|
+
result.push(e);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
};
|
package/util/geometry/index.js
CHANGED
|
@@ -24,8 +24,9 @@ function latLongBboxtoPixelXYBbox(minX, minY, maxX, maxY) {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
*
|
|
27
|
-
* @param
|
|
28
|
-
* @
|
|
27
|
+
* @param array - The array to normalize
|
|
28
|
+
* @param newLength - The target length for the normalized array
|
|
29
|
+
* @returns Normalized Float32Array
|
|
29
30
|
*/
|
|
30
31
|
function normalize(array, newLength = 1) {
|
|
31
32
|
let total = 0;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import './types';
|
|
2
1
|
/**
|
|
3
2
|
* @typedef BufferAndReadInfo Buffers can be intertwined or interleaved.
|
|
4
3
|
* This object forces user to adapt generic convention of buffer and read information.
|
|
@@ -20,10 +19,8 @@ import './types';
|
|
|
20
19
|
* @returns
|
|
21
20
|
*/
|
|
22
21
|
const attributeLoader = (gl, bufferAndReadInfo, index, size, { divisor = null, type = null, escapeValues = null, normalized = false } = {}) => {
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
if (bufferAndReadInfo == null) {
|
|
26
|
-
if (escapeValues !== null)
|
|
22
|
+
if (bufferAndReadInfo == null || bufferAndReadInfo.buffer == null) {
|
|
23
|
+
if (escapeValues)
|
|
27
24
|
constantFunction(gl, index, size, escapeValues);
|
|
28
25
|
return;
|
|
29
26
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import './types';
|
|
2
1
|
/**
|
|
3
2
|
* Draws instanced geometry using WebGL2.
|
|
4
3
|
*/
|
|
5
4
|
const drawInstanced = (gl, mode, drawOptions, vertexCount) => {
|
|
6
5
|
const { drawRange, elementBufferIndexType = gl.UNSIGNED_INT } = drawOptions;
|
|
7
|
-
const { first = 0, count
|
|
8
|
-
if (
|
|
6
|
+
const { first = 0, count } = drawRange;
|
|
7
|
+
if (drawOptions.elementBuffer) {
|
|
9
8
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, drawOptions.elementBuffer ?? null);
|
|
10
|
-
gl.drawElementsInstanced(mode, vertexCount, elementBufferIndexType, first,
|
|
9
|
+
gl.drawElementsInstanced(mode, vertexCount, elementBufferIndexType, first, count);
|
|
11
10
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
12
11
|
}
|
|
13
12
|
else {
|
|
14
|
-
gl.drawArraysInstanced(mode, first, vertexCount,
|
|
13
|
+
gl.drawArraysInstanced(mode, first, vertexCount, count);
|
|
15
14
|
}
|
|
16
15
|
};
|
|
17
16
|
/**
|
|
@@ -34,8 +34,7 @@ export function createShader(gl, type, source) {
|
|
|
34
34
|
export function createProgram(gl, vertexSource, fragmentSource) {
|
|
35
35
|
const program = gl.createProgram();
|
|
36
36
|
if (!program) {
|
|
37
|
-
|
|
38
|
-
return undefined;
|
|
37
|
+
throw new Error("Failed to create WebGLProgram.");
|
|
39
38
|
}
|
|
40
39
|
let vertexShader;
|
|
41
40
|
let fragmentShader;
|
|
@@ -45,18 +44,14 @@ export function createProgram(gl, vertexSource, fragmentSource) {
|
|
|
45
44
|
}
|
|
46
45
|
catch (e) { // Catching errors from createShader
|
|
47
46
|
console.error(e.message);
|
|
48
|
-
|
|
49
|
-
return undefined;
|
|
47
|
+
throw new Error(`Shader creation failed: ${e.message}`);
|
|
50
48
|
}
|
|
51
49
|
gl.attachShader(program, vertexShader);
|
|
52
50
|
gl.attachShader(program, fragmentShader);
|
|
53
51
|
gl.linkProgram(program);
|
|
54
52
|
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
55
|
-
console.error("Failed to link WebGL program:", gl.getProgramInfoLog(program));
|
|
56
|
-
gl.
|
|
57
|
-
gl.deleteShader(vertexShader);
|
|
58
|
-
gl.deleteShader(fragmentShader);
|
|
59
|
-
return undefined;
|
|
53
|
+
// console.error("Failed to link WebGL program:", gl.getProgramInfoLog(program));
|
|
54
|
+
throw new Error(`Error linking program:\n${gl.getProgramInfoLog(program)}`);
|
|
60
55
|
}
|
|
61
56
|
// Detach and delete shaders after linking to free up resources
|
|
62
57
|
gl.detachShader(program, vertexShader);
|
|
@@ -217,7 +212,7 @@ export function decodeBase64(data) {
|
|
|
217
212
|
*/
|
|
218
213
|
export function createImageFromBase64(encodedData) {
|
|
219
214
|
const bytes = decodeBase64(encodedData);
|
|
220
|
-
const blob = new Blob([bytes
|
|
215
|
+
const blob = new Blob([bytes], { type: "image/png" });
|
|
221
216
|
const urlCreator = window.URL || window.webkitURL;
|
|
222
217
|
const imageUrl = urlCreator.createObjectURL(blob);
|
|
223
218
|
const image = new Image();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import { CSZMode } from "@pirireis/webglobe";
|
|
2
3
|
import { isTextFont, opacityCheck } from "../util/check/typecheck";
|
|
3
4
|
/**
|
|
@@ -9,6 +10,22 @@ import { isTextFont, opacityCheck } from "../util/check/typecheck";
|
|
|
9
10
|
* TODO: key check and raise error if doesnt exist
|
|
10
11
|
*/
|
|
11
12
|
export class ContextTextWriter3 {
|
|
13
|
+
globe;
|
|
14
|
+
itemMap;
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
style;
|
|
17
|
+
doDraw;
|
|
18
|
+
textAdaptor;
|
|
19
|
+
coordinatesAdaptor;
|
|
20
|
+
keyAdaptor;
|
|
21
|
+
zoomLevelAdaptor;
|
|
22
|
+
positionAdaptor;
|
|
23
|
+
opacityAdaptor;
|
|
24
|
+
angleOnSphere;
|
|
25
|
+
angleAdaptor;
|
|
26
|
+
angleAdaptorIsOn;
|
|
27
|
+
xOffset;
|
|
28
|
+
yOffset;
|
|
12
29
|
constructor(globe, { style = {
|
|
13
30
|
textFont: {
|
|
14
31
|
name: 'Arial',
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { CSZMode } from "@pirireis/webglobe";
|
|
3
|
+
// import { isTextFont, opacityCheck } from "../util/check/typecheck";
|
|
4
|
+
// /**
|
|
5
|
+
// * TODOs:
|
|
6
|
+
// * 1) update all if initials change (propably need a context and a callback to iterate over zPayload)
|
|
7
|
+
// * 2) expose a mechanic to update text on zoom change
|
|
8
|
+
// * 3) extend the mechanic on 2 to other events
|
|
9
|
+
// *
|
|
10
|
+
// * TODO: key check and raise error if doesnt exist
|
|
11
|
+
// */
|
|
12
|
+
// export class ContextTextWriter3 {
|
|
13
|
+
// constructor(globe, {
|
|
14
|
+
// style = {
|
|
15
|
+
// textFont: {
|
|
16
|
+
// name: 'Arial',
|
|
17
|
+
// textColor: '#FFFFFF', // beyaz
|
|
18
|
+
// hollowColor: '#000000', // siyah
|
|
19
|
+
// size: 12, // piksel
|
|
20
|
+
// hollow: true,
|
|
21
|
+
// bold: true,
|
|
22
|
+
// italic: false,
|
|
23
|
+
// },
|
|
24
|
+
// opacity: 1.0,
|
|
25
|
+
// zMode: CSZMode.Z_GROUND_PERVERTEX,
|
|
26
|
+
// },
|
|
27
|
+
// xOffset = 0,
|
|
28
|
+
// yOffset = 0,
|
|
29
|
+
// doDraw = true,
|
|
30
|
+
// textAdaptor = null,
|
|
31
|
+
// coordinatesAdaptor = null,
|
|
32
|
+
// keyAdaptor = null,
|
|
33
|
+
// opacityAdaptor = null,
|
|
34
|
+
// angleAdaptor = null,
|
|
35
|
+
// angleOnSphere = false,
|
|
36
|
+
// positionAdaptor = (item, i, container, properties) => "left",
|
|
37
|
+
// zoomLevelAdaptor = (zoomLevel) => (item) => {
|
|
38
|
+
// return {
|
|
39
|
+
// opacityMultiplier: 1,
|
|
40
|
+
// sizeMultiplier: 1
|
|
41
|
+
// }
|
|
42
|
+
// }
|
|
43
|
+
// } = {}) {
|
|
44
|
+
// this.globe = globe;
|
|
45
|
+
// this.itemMap = new Map();
|
|
46
|
+
// this.setStyle(style);
|
|
47
|
+
// this.doDraw = doDraw;
|
|
48
|
+
// this._checkParameterTypes(textAdaptor, coordinatesAdaptor, keyAdaptor, opacityAdaptor, angleAdaptor, xOffset, yOffset);
|
|
49
|
+
// this.textAdaptor = textAdaptor;
|
|
50
|
+
// this.coordinatesAdaptor = coordinatesAdaptor;
|
|
51
|
+
// this.keyAdaptor = keyAdaptor;
|
|
52
|
+
// this.zoomLevelAdaptor = zoomLevelAdaptor;
|
|
53
|
+
// this.positionAdaptor = positionAdaptor;
|
|
54
|
+
// this.opacityAdaptor = opacityAdaptor ? opacityAdaptor : () => 1;
|
|
55
|
+
// this.angleOnSphere = angleOnSphere;
|
|
56
|
+
// if (angleAdaptor) {
|
|
57
|
+
// this.angleAdaptor = angleAdaptor
|
|
58
|
+
// this.angleAdaptorIsOn = true;
|
|
59
|
+
// } else {
|
|
60
|
+
// this.angleAdaptor = () => null
|
|
61
|
+
// this.angleAdaptorIsOn = false
|
|
62
|
+
// }
|
|
63
|
+
// this.xOffset = xOffset;
|
|
64
|
+
// this.yOffset = yOffset;
|
|
65
|
+
// }
|
|
66
|
+
// _checkParameterTypes(textAdaptor, coordinatesAdaptor, keyAdaptor, opacityAdaptor, angleAdaptor, xOffset, yOffset) {
|
|
67
|
+
// if (textAdaptor !== null) if (!(textAdaptor instanceof Function)) throw new Error("textAdaptor is not an instance of a Function");
|
|
68
|
+
// if (coordinatesAdaptor !== null) if (!(coordinatesAdaptor instanceof Function)) throw new Error("coordinatesAdaptor is not an instance of a Function");
|
|
69
|
+
// if (keyAdaptor !== null) if (!(keyAdaptor instanceof Function)) throw new Error("keyAdaptor is not an instance of a Function");
|
|
70
|
+
// if (opacityAdaptor !== null) if (!(opacityAdaptor instanceof Function)) throw new Error("opacityAdaptor is not an instance of a Function");
|
|
71
|
+
// if (angleAdaptor !== null) if (!(angleAdaptor instanceof Function)) throw new Error("angleAdaptor is not an instance of a Function");
|
|
72
|
+
// if (typeof xOffset !== "number") throw new Error("xOffset type is not a number");
|
|
73
|
+
// if (typeof yOffset !== "number") throw new Error("yOffset type is not a number");
|
|
74
|
+
// }
|
|
75
|
+
// setKeyAdaptor(adaptor) {
|
|
76
|
+
// this.keyAdaptor = adaptor;
|
|
77
|
+
// }
|
|
78
|
+
// setDoDraw(bool) {
|
|
79
|
+
// this.doDraw = bool;
|
|
80
|
+
// this.globe.DrawRender();
|
|
81
|
+
// }
|
|
82
|
+
// setStyle(style) {
|
|
83
|
+
// isTextFont(style.textFont);
|
|
84
|
+
// opacityCheck(style.opacity); //TODO: use shallow copy
|
|
85
|
+
// this.style = style;
|
|
86
|
+
// this.globe.DrawRender();
|
|
87
|
+
// }
|
|
88
|
+
// setOpacity(opacity) {
|
|
89
|
+
// this.style.opacity = opacity;
|
|
90
|
+
// this.globe.DrawRender();
|
|
91
|
+
// }
|
|
92
|
+
// draw() {
|
|
93
|
+
// if (!this.doDraw) return;
|
|
94
|
+
// const { globe, style, itemMap, xOffset, yOffset } = this;
|
|
95
|
+
// const { textFont, opacity: opacity_ } = style;
|
|
96
|
+
// const textSize = textFont.size;
|
|
97
|
+
// const is3D = globe.api_GetCurrentGeometry() === 0;
|
|
98
|
+
// const angleIsOn = is3D ? (this.angleAdaptorIsOn && this.angleOnSphere) : (this.angleAdaptorIsOn)
|
|
99
|
+
// const zoomLevel = globe.api_GetCurrentLODWithDecimal();
|
|
100
|
+
// const zoomAdaptor = this.zoomLevelAdaptor(zoomLevel);
|
|
101
|
+
// for (const item of itemMap.values()) {
|
|
102
|
+
// const { lat, long, text, opacity = null, angle = null, zPayload, position } = item;
|
|
103
|
+
// const { x, y } = globe.api_GetScreenPointFromGeo(
|
|
104
|
+
// {
|
|
105
|
+
// long: long,
|
|
106
|
+
// lat: lat,
|
|
107
|
+
// z: 0,
|
|
108
|
+
// },
|
|
109
|
+
// style.zMode === CSZMode.Z_MSL,
|
|
110
|
+
// );
|
|
111
|
+
// const { opacityMultiplier, sizeMultiplier } = zoomAdaptor(zPayload);
|
|
112
|
+
// const o = (opacity === null ? opacity_ : opacity * opacity_) * opacityMultiplier;
|
|
113
|
+
// textFont.size = sizeMultiplier * textSize;
|
|
114
|
+
// textFont.position = position;
|
|
115
|
+
// if (x !== null && y !== null) globe.api_DrawContextTextMultiLine(text, textFont, o, { x: x + xOffset, y: y - yOffset }, angleIsOn, angle);
|
|
116
|
+
// }
|
|
117
|
+
// textFont.size = textSize;
|
|
118
|
+
// }
|
|
119
|
+
// insertTextBulk(container, properties) {
|
|
120
|
+
// container.forEach((v, i, c) => {
|
|
121
|
+
// this.insertText(v, i, c, properties);
|
|
122
|
+
// });
|
|
123
|
+
// }
|
|
124
|
+
// deleteTextBulk(keys) {
|
|
125
|
+
// for (const key of keys) {
|
|
126
|
+
// this.itemMap.delete(key);
|
|
127
|
+
// }
|
|
128
|
+
// }
|
|
129
|
+
// insertText(item, id, container, properties) {
|
|
130
|
+
// const key = this.keyAdaptor(item, id, container, properties)
|
|
131
|
+
// const coords = this.coordinatesAdaptor(item, id, container, properties)
|
|
132
|
+
// if (coords == null) {
|
|
133
|
+
// this.itemMap.delete(key);
|
|
134
|
+
// return;
|
|
135
|
+
// }
|
|
136
|
+
// const text = this.textAdaptor(item, id, container, properties)
|
|
137
|
+
// if (text == null) {
|
|
138
|
+
// this.itemMap.delete(key);
|
|
139
|
+
// return
|
|
140
|
+
// };
|
|
141
|
+
// const opacity = this.opacityAdaptor(item, id, container, properties);
|
|
142
|
+
// const angle = this.angleAdaptor(item, id, container, properties);
|
|
143
|
+
// const position = this.positionAdaptor(item, id, container, properties);
|
|
144
|
+
// this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity, angle, zPayload: item, position });
|
|
145
|
+
// }
|
|
146
|
+
// clear() {
|
|
147
|
+
// this.itemMap.clear();
|
|
148
|
+
// }
|
|
149
|
+
// free() {
|
|
150
|
+
// this.itemMap = null;
|
|
151
|
+
// }
|
|
152
|
+
// }
|