@pirireis/webglobeplugins 0.6.2 → 0.6.3

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.
@@ -27,7 +27,12 @@ const constraintFloat = (x, lowerBound, upperBound) => {
27
27
  */
28
28
 
29
29
  export default class Plugin {
30
-
30
+ /**
31
+ *
32
+ * @param {*} id
33
+ * @param {Map<[K ,ContextTextWriter]} textContextInjectionMap import { ContextTextWriter } from '@pirireis/webglobeplugins/write-text/context-text';
34
+ *
35
+ */
31
36
 
32
37
  constructor(id, { opacity = 1, textContextInjectionMap = new Map(), drawVRM = true, drawBearingLine = true, drawAngleRing = true, drawText = true } = {}) {
33
38
  this.id = id;
@@ -9,6 +9,7 @@ export class ChainListMap {
9
9
  this._chainSideProperties = new Map();
10
10
  this._indexMap = new Map(); // hold list index of lastly updated nodes. on add delete goes empty
11
11
  this.keyMethod = keyMethod;
12
+
12
13
  }
13
14
 
14
15
  getChain(chainKey) {
@@ -171,12 +172,13 @@ export class ChainListMap {
171
172
  * @param {*} textWriterObjs
172
173
  * @param {*} nodeKeys use nodeKeys on updateCoordinatesOnly
173
174
  */
174
- textUpdate(chainKey, textWriterObjs) {
175
+ textUpdate(chainKey, textWriterObjs, dataPreAdaptor) {
175
176
  const chain = this._chainMap.get(chainKey);
177
+ const data = (dataPreAdaptor) ? chain.map(dataPreAdaptor) : chain;
176
178
  if (!chain) return;
177
179
  const properties = this._chainSideProperties.get(chainKey);
178
180
  textWriterObjs.forEach((writer) => {
179
- writer.insertTextBulk(chain, properties);
181
+ writer.insertTextBulk(data, properties);
180
182
  });
181
183
 
182
184
  }
@@ -34,15 +34,24 @@ import { keyMethod } from "./util";
34
34
  const radian = Math.PI / 180;
35
35
 
36
36
  export class CircleLineChainPlugin {
37
-
38
- constructor(id, { drawCircleOn = true, textContextWriterInjectionMap = new Map() } = {}) {
37
+ /**
38
+ *
39
+ * @param {*} id
40
+ * @param {Map<[key, ContextTextWriter3]} textContextWriterInjectionMap //import { ContextTextWriter3 } from "@pirireis/webglobeplugins/write-text/context-text3";
41
+ */
42
+ constructor(id, {
43
+ drawCircleOn = true,
44
+ textContextWriterInjectionMap = new Map(),
45
+ textDataPreAdaptor = null
46
+ } = {}) {
39
47
  this.id = id;
40
48
  this._textContextWriterInjectionMap = textContextWriterInjectionMap;
41
49
  this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, properties) => v.__identity__));
42
50
  this._opacity = 1;
43
51
  this._chainListMap = new ChainListMap(keyMethod);
44
52
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
45
- this._drawCircleOn = drawCircleOn
53
+ this._drawCircleOn = drawCircleOn;
54
+ this._textDataPreAdaptor = textDataPreAdaptor;
46
55
  }
47
56
 
48
57
  // init
@@ -262,8 +271,8 @@ export class CircleLineChainPlugin {
262
271
  for (const chainKey of chainKeys) {
263
272
  bufferKeys.push(...this._chainListMap.deleteChainAndReturnChainKeys(chainKey));
264
273
  }
265
- this._updateTexts(chainKeys, this._textContextWriterInjectionMap.keys());
266
274
  this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
275
+ this._updateTexts(chainKeys, this._textContextWriterInjectionMap.keys());
267
276
  this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
268
277
  this.globe.DrawRender();
269
278
  }
@@ -301,7 +310,7 @@ export class CircleLineChainPlugin {
301
310
  _updateTexts(chainKeys, textWriterIDs) {
302
311
  const textWriters = textWriterIDs.map((v) => this._textContextWriterInjectionMap.get(v));
303
312
  chainKeys.forEach((chainKey) => {
304
- this._chainListMap.textUpdate(chainKey, textWriters);
313
+ this._chainListMap.textUpdate(chainKey, textWriters, this._textDataPreAdaptor);
305
314
  })
306
315
  }
307
316
 
@@ -14,7 +14,7 @@ export class PixelPaddingCompassPlugin {
14
14
  defaultProperties = {
15
15
  rgba: [1, 1, 1, 1],
16
16
  pixelRadiusBig: 250,
17
- pixelRadiusSmall: 220
17
+ pixelRadiusSmall: 200
18
18
  },
19
19
  font = {
20
20
  name: 'Arial',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -18,10 +18,14 @@ vec3 coord_opacity(){
18
18
  float radius;
19
19
  float angle;
20
20
  if( gl_VertexID % 2 == 0){
21
- if ( gl_VertexID % 60 == 0){
22
- radius = pixel_radius_small;
21
+ if( gl_VertexID % 180 == 0){
22
+ radius = pixel_radius_small ;
23
+ }
24
+ else if ( gl_VertexID % 60 == 0){
25
+ float gap = (pixel_radius_big - pixel_radius_small) / 5.0;
26
+ radius = pixel_radius_small + gap;
23
27
  } else if( gl_VertexID % 10 == 0) {
24
- float gap = (pixel_radius_big - pixel_radius_small) / 4.0;
28
+ float gap = (pixel_radius_big - pixel_radius_small) / 2.0;
25
29
  radius = pixel_radius_small + gap;
26
30
  } else {
27
31
  float gap = (pixel_radius_big - pixel_radius_small) * 0.75;
@@ -29,7 +33,7 @@ vec3 coord_opacity(){
29
33
  }
30
34
  angle = (float(gl_VertexID) / (${vertexCount}.0));
31
35
  } else {
32
- if ( gl_VertexID % 60 == 1){
36
+ if ( gl_VertexID % 180 == 1){
33
37
  radius = pixel_radius_big + 10.0;
34
38
 
35
39
  } else {
@@ -1,10 +1,6 @@
1
1
 
2
2
  import {
3
- CSGlobe,
4
- CSObjectTypes,
5
- CSIconTypes,
6
3
  CSObjectArrayUpdateTypes,
7
- GlobeManager
8
4
  } from "@pirireis/webglobe";
9
5
  import { ENUM_HIDE, ENUM_TEXT_HIDE, COMPASS_MODES } from "./enum";
10
6
 
@@ -64,16 +60,7 @@ export default class RangeRingAngleText {
64
60
  label.hAlignment = 2;
65
61
  label.size = 17;
66
62
  label.text = "`${aci}`"
67
- // this.style.filter = [
68
- // {
69
- // rule: ["any", ["===", "aci", "K"]],
70
- // name: "startLODRule",
71
- // style: {
72
- // ...
73
- // }
74
-
75
- // }
76
- // ];
63
+
77
64
  return style;
78
65
  }
79
66
 
@@ -259,9 +246,10 @@ export default class RangeRingAngleText {
259
246
  for (const [centerID, centerMap] of this._centerCollection) {
260
247
  const hide = centerMap.get("hide");
261
248
  const hideText = centerMap.get("textHide");
262
- const isHidden = hide === ENUM_HIDE.HIDE || hideText === ENUM_TEXT_HIDE.HIDE;
249
+ centerMap.set("textHide", ENUM_TEXT_HIDE.HIDE);
250
+ if (hide === ENUM_HIDE.HIDE) continue;
251
+ const isHidden = hideText === ENUM_TEXT_HIDE.HIDE;
263
252
  if (!isHidden) this._fillDeleteBucket(centerID, deleteBucket);
264
- centerMap.set("hide", ENUM_HIDE.HIDE);
265
253
  }
266
254
  this._updateData(deleteBucket, CSObjectArrayUpdateTypes.DELETE);
267
255
  }
@@ -275,8 +263,9 @@ export default class RangeRingAngleText {
275
263
  }
276
264
  for (const [centerID, centerMap] of this._centerCollection) {
277
265
  const hide = centerMap.get("hide");
266
+ if (hide === ENUM_HIDE.HIDE) continue;
278
267
  const hideText = centerMap.get("textHide");
279
- const isHidden = hide === ENUM_HIDE.HIDE || hideText === ENUM_TEXT_HIDE.HIDE;
268
+ const isHidden = hideText === ENUM_TEXT_HIDE.HIDE;
280
269
  if (isHidden) {
281
270
  const x = centerMap.get("x");
282
271
  const y = centerMap.get("y");
@@ -292,29 +281,6 @@ export default class RangeRingAngleText {
292
281
 
293
282
 
294
283
 
295
- showAllVisibleCircleText() {
296
- this._hideAll = false;
297
- const addBucket = {
298
- coords: [],
299
- coordsZ: [],
300
- attribs: []
301
- }
302
- for (const [centerID, centerMap] of this._centerCollection) {
303
- const hide = centerMap.get("hide");
304
- const hideText = centerMap.get("textHide");
305
- if (hide === ENUM_HIDE.HIDE) continue
306
- const isHidden = hideText === ENUM_TEXT_HIDE.HIDE;
307
- if (isHidden) {
308
- const x = centerMap.get("x");
309
- const y = centerMap.get("y");
310
- const maxRadius = centerMap.get("maxRadius");
311
- const stepAngle = centerMap.get("stepAngle");
312
- this._appendCircle(x, y, maxRadius, stepAngle, centerID, addBucket);
313
- centerMap.set("textHide", ENUM_TEXT_HIDE.SHOW);
314
- }
315
- }
316
- if (addBucket.coords.length) this._updateData(addBucket, CSObjectArrayUpdateTypes.ADD);
317
- }
318
284
 
319
285
  flush() {
320
286
  const data = {
@@ -1,19 +1,5 @@
1
1
  import { CSZMode } from "@pirireis/webglobe";
2
2
 
3
- const defaultStyle = {
4
- textFont: {
5
- name: 'Arial',
6
- textColor: '#FFFFFF', // beyaz
7
- hollowColor: '#000000', // siyah
8
- size: 12, // piksel
9
- hollow: true,
10
- bold: true,
11
- italic: false,
12
- },
13
- opacity: 1.0,
14
- zMode: CSZMode.Z_GROUND_PERVERTEX,
15
- }
16
-
17
3
  /**
18
4
  * TODOs:
19
5
  * 1) update all if initials change (propably need a context and a callback to iterate over data)
@@ -21,10 +7,33 @@ const defaultStyle = {
21
7
  * 3) extend the mechanic on 2 to other events
22
8
  */
23
9
  export class ContextTextWriter2 {
24
- constructor(globe, { style = null, doDraw = true, textAdaptor = null, coordinatesAdaptor = null, keyAdaptor = null, opacityAdaptor = null, angleAdaptor = null, angleOnSphere = false } = {}) {
10
+ constructor(globe, {
11
+ style = {
12
+ textFont: {
13
+ name: 'Arial',
14
+ textColor: '#FFFFFF', // beyaz
15
+ hollowColor: '#000000', // siyah
16
+ size: 12, // piksel
17
+ hollow: true,
18
+ bold: true,
19
+ italic: false,
20
+ },
21
+ opacity: 1.0,
22
+ zMode: CSZMode.Z_GROUND_PERVERTEX,
23
+ },
24
+ doDraw = true,
25
+ textAdaptor = null,
26
+ coordinatesAdaptor = null,
27
+ keyAdaptor = null,
28
+ opacityAdaptor = null,
29
+ angleAdaptor = null,
30
+ angleOnSphere = false,
31
+ zoomLevelOpacityAdaptor = null,
32
+ zoomLevelSizeAdaptor = null,
33
+ } = {}) {
25
34
  this.globe = globe;
26
35
  this.itemMap = new Map();
27
- this.style = style || defaultStyle;
36
+ this.style = style;
28
37
  this.doDraw = doDraw;
29
38
 
30
39
 
@@ -32,6 +41,9 @@ export class ContextTextWriter2 {
32
41
  this.coordinatesAdaptor = coordinatesAdaptor;
33
42
  this.keyAdaptor = keyAdaptor;
34
43
 
44
+ this.zoomLevelOpacityAdaptor = zoomLevelOpacityAdaptor;
45
+ this.zoomLevelSizeAdaptor = zoomLevelSizeAdaptor;
46
+
35
47
  this.opacityAdaptor = opacityAdaptor ? opacityAdaptor : () => 1;
36
48
  this.angleOnSphere = angleOnSphere;
37
49
  if (angleAdaptor) {
@@ -141,7 +153,7 @@ export class ContextTextWriter2 {
141
153
  };
142
154
  const opacity = this.opacityAdaptor(item, id, container, properties);
143
155
  const angle = this.angleAdaptor(item, id, container, properties);
144
- this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity, angle });
156
+ this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity, angle, data: item });
145
157
  }
146
158
 
147
159
  clear() {
@@ -0,0 +1,174 @@
1
+ import { CSZMode } from "@pirireis/webglobe";
2
+
3
+ /**
4
+ * TODOs:
5
+ * 1) update all if initials change (propably need a context and a callback to iterate over data)
6
+ * 2) expose a mechanic to update text on zoom change
7
+ * 3) extend the mechanic on 2 to other events
8
+ */
9
+ export class ContextTextWriter3 {
10
+ constructor(globe, {
11
+ style = {
12
+ textFont: {
13
+ name: 'Arial',
14
+ textColor: '#FFFFFF', // beyaz
15
+ hollowColor: '#000000', // siyah
16
+ size: 12, // piksel
17
+ hollow: true,
18
+ bold: true,
19
+ italic: false,
20
+ },
21
+ opacity: 1.0,
22
+ zMode: CSZMode.Z_GROUND_PERVERTEX,
23
+ },
24
+ doDraw = true,
25
+ textAdaptor = null,
26
+ coordinatesAdaptor = null,
27
+ keyAdaptor = null,
28
+ opacityAdaptor = null,
29
+ angleAdaptor = null,
30
+ angleOnSphere = false,
31
+ zoomLevelAdaptor = (zoomLevel) => (item) => {
32
+ return {
33
+ opacityMultiplier: 1,
34
+ sizeMultiplier: 1
35
+ }
36
+ }
37
+ } = {}) {
38
+ this.globe = globe;
39
+ this.itemMap = new Map();
40
+ this.style = style;
41
+ this.doDraw = doDraw;
42
+
43
+
44
+ this.textAdaptor = textAdaptor;
45
+ this.coordinatesAdaptor = coordinatesAdaptor;
46
+ this.keyAdaptor = keyAdaptor;
47
+
48
+ this.zoomLevelAdaptor = zoomLevelAdaptor;
49
+
50
+ this.opacityAdaptor = opacityAdaptor ? opacityAdaptor : () => 1;
51
+ this.angleOnSphere = angleOnSphere;
52
+ if (angleAdaptor) {
53
+ this.angleAdaptor = angleAdaptor
54
+ this.angleAdaptorIsOn = true;
55
+ } else {
56
+ this.angleAdaptor = () => null
57
+ this.angleAdaptorIsOn = false
58
+ }
59
+ }
60
+
61
+ setKeyAdaptor(adaptor) {
62
+ this.keyAdaptor = adaptor;
63
+ }
64
+
65
+ setDoDraw(bool) {
66
+ this.doDraw = bool;
67
+ }
68
+
69
+ setStyle(style) {
70
+ this.style = style;
71
+ }
72
+
73
+ setOpacity(opacity) {
74
+ this.style.opacity = opacity;
75
+ }
76
+
77
+
78
+
79
+ draw() {
80
+ if (!this.doDraw) return;
81
+ const { globe, style, itemMap } = this;
82
+ const { textFont, opacity: opacity_ } = style;
83
+ const textSize = textFont.size;
84
+ const is3D = globe.api_GetCurrentGeometry() === 0;
85
+ const angleIsOn = is3D ? (this.angleAdaptorIsOn && this.angleOnSphere) : (this.angleAdaptorIsOn)
86
+ const zoomLevel = globe.api_GetCurrentLODWithDecimal();
87
+ const zoomAdaptor = this.zoomLevelAdaptor(zoomLevel);
88
+ for (const [key, item] of itemMap) {
89
+ const { lat, long, text, opacity = null, angle = null, data } = item;
90
+ const { x, y } = globe.api_GetScreenPointFromGeo(
91
+ {
92
+ long: long,
93
+ lat: lat,
94
+ z: 0,
95
+ },
96
+ style.zMode === CSZMode.Z_MSL,
97
+ );
98
+ const { opacityMultiplier, sizeMultiplier } = zoomAdaptor(data);
99
+ const o = (opacity === null ? opacity_ : opacity * opacity_) * opacityMultiplier;
100
+ textFont.size = sizeMultiplier * textSize;
101
+
102
+ if (x !== null && y !== null) globe.api_DrawContextTextMultiLine(text, textFont, o, { x, y }, angleIsOn, angle);
103
+ }
104
+ textFont.size = textSize;
105
+ }
106
+
107
+
108
+ updateOpacityOfItem(item, i, container, properties) {
109
+ const opacity = this.opacityAdaptor(item, i, container, properties);
110
+ if (opacity == null) return;
111
+ const key = this.keyAdaptor(item, i, container, properties);
112
+ const data = this.itemMap.get(key)
113
+ data.opacity = opacity;
114
+ }
115
+
116
+ updateOpacityContainer(container, properties) {
117
+ container.forEach((v, i, c) => {
118
+ this.updateOpacityOfItem(v, i, c, properties);
119
+ })
120
+ }
121
+
122
+
123
+ insertTextBulk(container, properties) {
124
+ container.forEach((v, i, c) => {
125
+ this.insertText(v, i, c, properties);
126
+ })
127
+ }
128
+
129
+ updateTextCoords(item, i, container, properties) {
130
+ const coords = this.coordinatesAdaptor(item, i, container, properties);
131
+ if (coords == null) return;
132
+ const key = this.keyAdaptor(item, i, container, properties);
133
+ const data = this.itemMap.get(key)
134
+ data.angle = this.angleAdaptor(item, i, container, properties);
135
+ data.long = coords.long;
136
+ data.lat = coords.lat;
137
+ }
138
+
139
+ updateTextCoordsBulk(container, properties) {
140
+ container.forEach((v, i, c) => {
141
+ this.updateTextCoords(v, i, c, properties)
142
+ })
143
+ }
144
+
145
+ deleteTextBulk(keys) {
146
+ for (const key of keys) {
147
+ this.itemMap.delete(key);
148
+ }
149
+ }
150
+
151
+
152
+ insertText(item, id, container, properties) {
153
+ const key = this.keyAdaptor(item, id, container, properties)
154
+ const coords = this.coordinatesAdaptor(item, id, container, properties)
155
+ if (coords == null) {
156
+ this.itemMap.delete(key);
157
+ return;
158
+ }
159
+ const text = this.textAdaptor(item, id, container, properties)
160
+ if (text == null) {
161
+ this.itemMap.delete(key);
162
+ return
163
+ };
164
+ const opacity = this.opacityAdaptor(item, id, container, properties);
165
+ const angle = this.angleAdaptor(item, id, container, properties);
166
+ this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity, angle, data: item });
167
+ }
168
+
169
+ clear() {
170
+ this.itemMap.clear();
171
+ }
172
+ }
173
+
174
+