@pirireis/webglobeplugins 0.15.22-alpha → 0.15.24

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,140 @@
1
+ // @ts-ignore
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
+ const defaultStyle = {
13
+ textFont: {
14
+ name: 'Arial',
15
+ textColor: '#FFFFFF', // beyaz
16
+ hollowColor: '#000000', // siyah
17
+ size: 12, // piksel
18
+ hollow: true,
19
+ bold: true,
20
+ italic: false,
21
+ },
22
+ opacity: 1.0,
23
+ zMode: CSZMode.Z_GROUND_PERVERTEX,
24
+ };
25
+ // xOffset = 0,
26
+ // yOffset = 0,
27
+ // doDraw = true,
28
+ // textAdaptor = null,
29
+ // coordinatesAdaptor = null,
30
+ // keyAdaptor = null,
31
+ // opacityAdaptor = null,
32
+ // angleAdaptor = null,
33
+ // angleOnSphere = false,
34
+ // positionAdaptor = (item: any, i: number, container: any[], properties?: any): string => "left",
35
+ export class ContextTextWriter4 {
36
+ globe;
37
+ itemMap;
38
+ style;
39
+ doDraw;
40
+ textAdaptor;
41
+ deleteAdaptor;
42
+ zoomLevelAdaptor;
43
+ xOffset;
44
+ yOffset;
45
+ angleOptions;
46
+ constructor(globe, textAdaptor, deleteAdaptor, zoomLevelAdaptor = (zoomLevel) => (item) => {
47
+ return {
48
+ opacityMultiplier: 1,
49
+ sizeMultiplier: 1
50
+ };
51
+ }, style = defaultStyle, angleOptions = {
52
+ angleOnSphere: false,
53
+ angleIsOn: false
54
+ }, doDraw = true, offset = { x: 0, y: 0 }) {
55
+ this.globe = globe;
56
+ this.itemMap = new Map();
57
+ this.setStyle(style);
58
+ this.angleOptions = angleOptions;
59
+ this.doDraw = doDraw;
60
+ this.style = style;
61
+ this.angleOptions = angleOptions;
62
+ this.textAdaptor = textAdaptor;
63
+ this.deleteAdaptor = deleteAdaptor;
64
+ this.zoomLevelAdaptor = zoomLevelAdaptor;
65
+ this.xOffset = offset.x;
66
+ this.yOffset = offset.y;
67
+ }
68
+ setDoDraw(bool) {
69
+ this.doDraw = bool;
70
+ this.globe.DrawRender();
71
+ }
72
+ setStyle(style) {
73
+ isTextFont(style.textFont);
74
+ opacityCheck(style.opacity); //TODO: use shallow copy
75
+ this.style = style;
76
+ this.globe.DrawRender();
77
+ }
78
+ setOpacity(opacity) {
79
+ this.style.opacity = opacity;
80
+ this.globe.DrawRender();
81
+ }
82
+ draw() {
83
+ if (!this.doDraw)
84
+ return;
85
+ const { globe, style, itemMap, xOffset, yOffset } = this;
86
+ const { textFont, opacity: opacity_ } = style;
87
+ const textSize = textFont.size;
88
+ const is3D = globe.api_GetCurrentGeometry() === 0;
89
+ const angleIsOn = is3D ? (this.angleOptions.angleIsOn && this.angleOptions.angleOnSphere) : (this.angleOptions.angleIsOn);
90
+ const zoomLevel = globe.api_GetCurrentLODWithDecimal();
91
+ const zoomAdaptor = this.zoomLevelAdaptor(zoomLevel);
92
+ for (const item of itemMap.values()) {
93
+ const { lat, long, text, opacity = null, angle = null, zPayload, position } = item;
94
+ const { x, y } = globe.api_GetScreenPointFromGeo({
95
+ long: long,
96
+ lat: lat,
97
+ z: 0,
98
+ }, style.zMode === CSZMode.Z_MSL);
99
+ const { opacityMultiplier, sizeMultiplier } = zoomAdaptor(zPayload);
100
+ const o = (opacity === null ? opacity_ : opacity * opacity_) * opacityMultiplier;
101
+ textFont.size = sizeMultiplier * textSize;
102
+ textFont.position = position;
103
+ if (x !== null && y !== null)
104
+ globe.api_DrawContextTextMultiLine(text, textFont, o, { x: x + xOffset, y: y - yOffset }, angleIsOn, angle);
105
+ }
106
+ textFont.size = textSize;
107
+ }
108
+ insertText(data) {
109
+ const textDatas = this.textAdaptor(data);
110
+ for (const textData of textDatas) {
111
+ this.itemMap.set(textData.key, textData);
112
+ }
113
+ }
114
+ insertTextBulk(datas) {
115
+ for (const data of datas) {
116
+ this.insertText(data);
117
+ }
118
+ }
119
+ deleteText(data) {
120
+ const key = this.deleteAdaptor ? this.deleteAdaptor(data) : data;
121
+ if (this.itemMap.has(key)) {
122
+ this.itemMap.delete(key);
123
+ }
124
+ }
125
+ deleteTextBulk(datas) {
126
+ for (const data of datas) {
127
+ this.deleteText(data);
128
+ }
129
+ }
130
+ setOffsets(x, y) {
131
+ this.xOffset = x;
132
+ this.yOffset = y;
133
+ }
134
+ clear() {
135
+ this.itemMap.clear();
136
+ }
137
+ free() {
138
+ this.itemMap = null;
139
+ }
140
+ }