@pirireis/webglobeplugins 0.15.35 → 0.16.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.
@@ -0,0 +1,198 @@
1
+ // @ts-ignore
2
+ import { CSZMode } from "@pirireis/webglobe";
3
+ import { isTextFont, opacityCheck } from "../util/check/typecheck";
4
+ // import { CameraUniformBlockTotem, CameraUniformBlockTotemCache } from "../programs/totems/camerauniformblock";
5
+ // @ts-ignore
6
+ import RBush from 'rbush';
7
+ /**
8
+ * TODOs:
9
+ * 1) update all if initials change (propably need a context and a callback to iterate over zPayload)
10
+ * 2) expose a mechanic to update text on zoom change
11
+ * 3) extend the mechanic on 2 to other events
12
+ *
13
+ * TODO: key check and raise error if doesnt exist
14
+ */
15
+ const defaultStyle = {
16
+ textFont: {
17
+ name: 'Arial',
18
+ textColor: '#FFFFFF', // beyaz
19
+ hollowColor: '#000000', // siyah
20
+ size: 12, // piksel
21
+ hollow: true,
22
+ bold: false,
23
+ italic: false,
24
+ },
25
+ opacity: 1.0,
26
+ zMode: CSZMode.Z_GROUND_PERVERTEX,
27
+ };
28
+ // xOffset = 0,
29
+ // yOffset = 0,
30
+ // doDraw = true,
31
+ // textAdapter = null,
32
+ // coordinatesAdapter = null,
33
+ // keyAdapter = null,
34
+ // opacityAdapter = null,
35
+ // angleAdapter = null,
36
+ // angleOnSphere = false,
37
+ // positionAdapter = (item: any, i: number, container: any[], properties?: any): string => "left",
38
+ class MyRBush extends RBush {
39
+ toBBox({ long, lat, key }) { return { minX: long, minY: lat, maxX: long, maxY: lat }; }
40
+ compareMinX(a, b) { return a.long - b.long; }
41
+ compareMinY(a, b) { return a.lat - b.lat; }
42
+ }
43
+ export class ContextTexBulk {
44
+ globe;
45
+ dataMap;
46
+ style;
47
+ doDraw;
48
+ keyAdapter;
49
+ textAdapter;
50
+ zoomLevelAdapter;
51
+ inputZoomAdapter;
52
+ xOffset;
53
+ yOffset;
54
+ // private cameraTotem: CameraUniformBlockTotem;
55
+ angleOptions;
56
+ constructor(globe, keyAdapter, textAdapter, zoomLevelAdapter = (zoomLevel) => (item) => {
57
+ return {
58
+ opacityMultiplier: 1,
59
+ sizeMultiplier: 1
60
+ };
61
+ }, inputZoomAdapter = (input, zoomLevel) => {
62
+ return {
63
+ opacityMultiplier: 1,
64
+ sizeMultiplier: 1
65
+ };
66
+ }, style = defaultStyle, angleOptions = {
67
+ angleOnSphere: false,
68
+ angleIsOn: false
69
+ }, doDraw = true, offset = { x: 0, y: 0 }) {
70
+ this.globe = globe;
71
+ this.dataMap = new Map();
72
+ isTextFont(style.textFont);
73
+ opacityCheck(style.opacity);
74
+ this.style = { ...style, textFont: { ...style.textFont } };
75
+ this.angleOptions = angleOptions;
76
+ this.doDraw = doDraw;
77
+ this.angleOptions = angleOptions;
78
+ this.keyAdapter = keyAdapter;
79
+ this.textAdapter = textAdapter;
80
+ this.zoomLevelAdapter = zoomLevelAdapter;
81
+ this.inputZoomAdapter = inputZoomAdapter;
82
+ this.xOffset = offset.x;
83
+ this.yOffset = offset.y;
84
+ // this.cameraTotem = CameraUniformBlockTotemCache.get(globe);
85
+ }
86
+ setDoDraw(bool) {
87
+ this.doDraw = bool;
88
+ this.globe.DrawRender();
89
+ }
90
+ setStyle(style) {
91
+ isTextFont(style.textFont);
92
+ opacityCheck(style.opacity);
93
+ this.style = { ...style, textFont: { ...style.textFont } };
94
+ this.globe.DrawRender();
95
+ }
96
+ setOpacity(opacity) {
97
+ this.style.opacity = opacity;
98
+ this.globe.DrawRender();
99
+ }
100
+ draw() {
101
+ if (!this.doDraw)
102
+ return;
103
+ const { globe, style, dataMap, xOffset, yOffset } = this;
104
+ const { textFont, opacity: opacity_ } = style;
105
+ const textSize = textFont.size;
106
+ const is3D = globe.api_GetCurrentGeometry() === 0;
107
+ const angleIsOn = is3D ? (this.angleOptions.angleIsOn && this.angleOptions.angleOnSphere) : (this.angleOptions.angleIsOn);
108
+ const bbox = globe.api_GetCurrentWorldLimit();
109
+ // @ts-ignore
110
+ const data = dataMap.values();
111
+ const zoomLevel = globe.api_GetCurrentLODWithDecimal();
112
+ // const zoomLevel = this.cameraTotem.getApproximatedLOD();
113
+ const zoomAdapter = this.zoomLevelAdapter(zoomLevel);
114
+ for (const { input, tree } of data) {
115
+ const inputZoomResult = this.inputZoomAdapter({ input, tree }.input, zoomLevel);
116
+ if (inputZoomResult.sizeMultiplier === 0 || inputZoomResult.opacityMultiplier === 0)
117
+ continue;
118
+ // @ts-ignore
119
+ const itemsInBBox = tree.search({ minX: bbox.ll.x, minY: bbox.ll.y, maxX: bbox.ur.x, maxY: bbox.ur.y });
120
+ const itemsLen = itemsInBBox.length;
121
+ for (let i = 0; i < itemsLen; i++) {
122
+ const item = itemsInBBox[i];
123
+ const { lat, long, text, opacity = null, angle = null, zPayload, position } = item;
124
+ const { x, y } = globe.api_GetScreenPointFromGeo({
125
+ long: long,
126
+ lat: lat,
127
+ z: 0,
128
+ }, style.zMode === CSZMode.Z_MSL);
129
+ const { opacityMultiplier, sizeMultiplier } = zoomAdapter(zPayload);
130
+ const o = (opacity === null ? opacity_ : opacity * opacity_) * opacityMultiplier * inputZoomResult.opacityMultiplier;
131
+ textFont.size = sizeMultiplier * textSize * inputZoomResult.sizeMultiplier;
132
+ textFont.position = position;
133
+ if (x !== null && y !== null)
134
+ globe.api_DrawContextTextMultiLine(text, textFont, o, { x: x + xOffset, y: y - yOffset }, angleIsOn, angle);
135
+ }
136
+ textFont.size = textSize;
137
+ }
138
+ }
139
+ insertText(data) {
140
+ const key = this.keyAdapter(data);
141
+ const textDatas = this.textAdapter(data);
142
+ const tree = new MyRBush();
143
+ // @ts-ignore
144
+ tree.load(textDatas);
145
+ this.dataMap.set(key, { input: data, tree });
146
+ this.globe.DrawRender();
147
+ }
148
+ insertTextBulk(inputs) {
149
+ for (const input of inputs) {
150
+ const key = this.keyAdapter(input);
151
+ const textDatas = this.textAdapter(input);
152
+ const tree = new MyRBush();
153
+ // @ts-ignore
154
+ tree.load(textDatas);
155
+ this.dataMap.set(key, { input, tree });
156
+ }
157
+ this.globe.DrawRender();
158
+ }
159
+ deleteText(data) {
160
+ const keys = this.keyAdapter(data);
161
+ if (this.dataMap.has(keys)) {
162
+ this.dataMap.delete(keys);
163
+ }
164
+ this.globe.DrawRender();
165
+ }
166
+ deleteTextBulk(inputs) {
167
+ for (const input of inputs) {
168
+ const key = this.keyAdapter(input);
169
+ this.dataMap.delete(key);
170
+ }
171
+ this.globe.DrawRender();
172
+ }
173
+ deleteTextByKey(key) {
174
+ if (this.dataMap.has(key)) {
175
+ this.dataMap.delete(key);
176
+ }
177
+ this.globe.DrawRender();
178
+ }
179
+ deleteTextBulkByKey(keys) {
180
+ for (const key of keys) {
181
+ this.dataMap.delete(key);
182
+ }
183
+ this.globe.DrawRender();
184
+ }
185
+ setOffsets(x, y) {
186
+ this.xOffset = x;
187
+ this.yOffset = y;
188
+ }
189
+ clear() {
190
+ // @ts-ignore
191
+ this.dataMap.clear();
192
+ this.globe.DrawRender();
193
+ }
194
+ free() {
195
+ this.dataMap.clear();
196
+ // CameraUniformBlockTotemCache.release(this.globe)
197
+ }
198
+ }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- // import { WORLD_RADIUS_3D } from '../constants';
3
- // import { Plane } from '../plane';
4
- // import { Vector3D } from '../vector3d';
5
- // import { Quaternion } from '../quaternion';
6
- // function cameraFrustum(
7
- // globe: any,
8
- // out: {
9
- // near: Plane,
10
- // far: Plane,
11
- // left: Plane,
12
- // right: Plane,
13
- // top: Plane,
14
- // bottom: Plane
15
- // },
16
- // fieldOfView: number = 50 // in degrees
17
- // ): void {
18
- // const lookinfo = globe.api_GetCurrentLookInfo();
19
- // lookinfo.CenterLong *= Math.PI / 180; // convert degrees to radians
20
- // lookinfo.CenterLat *= Math.PI / 180; // convert degrees to radians
21
- // const lookAtPosition = Vector3D.fromLongLatRadians(lookinfo.CenterLong, lookinfo.CenterLat);
22
- // const cameraPosition = new Vector3D(globe.Fp.x, globe.Fp.y, globe.Fp.z).divideByScaler(WORLD_RADIUS_3D);
23
- // return
24
- // }
@@ -1,48 +0,0 @@
1
- "use strict";
2
- // import { Plane } from "../plane";
3
- // import { Vector3D } from "../vector3d";
4
- // import { WORLD_RADIUS_3D } from "../constants";
5
- // import { Quaternion } from "../quaternion";
6
- // import { FrustumPlanes } from "./types";
7
- // const _quaternion = new Quaternion();
8
- // export function getFrustum(globe: any, fieldOfView: number = 50 * Math.PI / 180,
9
- // out: FrustumPlanes): void {
10
- // const lookinfo = globe.api_GetCurrentLookInfo();
11
- // lookinfo.CenterLong *= Math.PI / 180; // convert degrees to radians
12
- // lookinfo.CenterLat *= Math.PI / 180; // convert degrees to radians
13
- // lookinfo.NorthAng *= Math.PI / 180; // convert degrees to radians
14
- // const lookAtPosition = Vector3D.fromLongLatRadians(lookinfo.CenterLong, lookinfo.CenterLat);
15
- // const cameraPosition = new Vector3D(globe.Fp.x, globe.Fp.y, globe.Fp.z).divideByScaler(WORLD_RADIUS_3D);
16
- // const lookFromCamera = lookAtPosition.clone().subtract(cameraPosition).normalize();
17
- // const cameraZ = new Vector3D(globe.Fu.x, globe.Fu.y, globe.Fu.z);
18
- // const cameraY = cameraZ.clone().cross(lookFromCamera).normalize();
19
- // const bottomNormal = cameraZ.clone().applyQuaternion(
20
- // _quaternion.setFromAxisAngle(cameraY, -fieldOfView)
21
- // ).normalize();
22
- // const topNormal = cameraZ.clone().applyQuaternion(
23
- // _quaternion.setFromAxisAngle(cameraY, fieldOfView)
24
- // ).negate().normalize();
25
- // const leftNormal = cameraY.clone().applyQuaternion(
26
- // _quaternion.setFromAxisAngle(cameraZ, fieldOfView)
27
- // ).negate().normalize();
28
- // const rightNormal = cameraY.clone().applyQuaternion(
29
- // _quaternion.setFromAxisAngle(cameraZ, -fieldOfView)
30
- // ).normalize();
31
- // out.top.set(topNormal, topNormal.dot(cameraPosition));
32
- // out.bottom.set(bottomNormal, bottomNormal.dot(cameraPosition));
33
- // out.left.set(leftNormal, leftNormal.dot(cameraPosition));
34
- // out.right.set(rightNormal, rightNormal.dot(cameraPosition));
35
- // out.far.set(cameraPosition.normalize(), 0.01);
36
- // out.near = null; // Near plane is not calculated in this function, set to null
37
- // vectorInfo(globe, [out]);
38
- // }
39
- // let interval = 0;
40
- // const vectorInfo = (globe, args: null | Array<any>) => {
41
- // interval++;
42
- // if (interval % 100 === 0) {
43
- // console.log("Fp:", globe.Fp.x / WORLD_RADIUS_3D, globe.Fp.y / WORLD_RADIUS_3D, globe.Fp.z / WORLD_RADIUS_3D);
44
- // console.log("Fu:", globe.Fu.x, globe.Fu.y, globe.Fu.z);
45
- // if (args) console.log(...args)
46
- // interval = 0;
47
- // }
48
- // }
@@ -1 +0,0 @@
1
- export {};