@pirireis/webglobeplugins 0.6.1 → 0.6.2-a

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.
@@ -1,26 +1,48 @@
1
1
  import { PixelPaddingForFlatCompassCache } from "../programs/two-d/pixel-padding-for-compass";
2
2
  import { BufferManager, BufferOrchestrator } from "../util/account";
3
3
  // import { ContextTextWriter2 } from "../write-text/context-text2";
4
- import { ContextTextWriter2Offsets } from "./compass-text-writer"
4
+ import { PixelPaddingCompassTextWriter } from "./compass-text-writer"
5
5
 
6
6
  const PaddingAngle = 30;
7
+ const textGapFit = 10;
7
8
 
8
9
  export class PixelPaddingCompassPlugin {
9
10
  constructor(id, {
10
11
  opacity = 1,
11
- textAngle = true,
12
+ textAngleOn = true,
13
+
12
14
  defaultProperties = {
13
15
  rgba: [1, 1, 1, 1],
14
- pixelRadiusBig: 350,
15
- pixelRadiusSmall: 270
16
+ pixelRadiusBig: 250,
17
+ pixelRadiusSmall: 220
18
+ },
19
+ font = {
20
+ name: 'Arial',
21
+ textColor: '#FFFFFF',
22
+ hollowColor: '#000000',
23
+ size: 12, // piksel
24
+ hollow: true,
25
+ bold: true,
26
+ italic: false,
27
+ },
28
+ northFont = {
29
+ name: 'Arial',
30
+ textColor: '#BBAA00',
31
+ hollowColor: '#000000',
32
+ size: 14, // piksel
33
+ hollow: true,
34
+ bold: true,
35
+ italic: false,
36
+
37
+
16
38
  }
17
39
  } = {}) {
18
40
  this.id = id;
19
- this.textWriters = null
20
- this.textAngle = textAngle
41
+ this.textAngleOn = textAngleOn
21
42
  this.defaultProperties = defaultProperties
22
43
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
23
44
 
45
+ this._font_hold = { font, northFont };
24
46
  this.compassMap = new CompassMap(this);
25
47
  this._opacity = opacity;
26
48
 
@@ -29,7 +51,7 @@ export class PixelPaddingCompassPlugin {
29
51
  init(globe, gl) {
30
52
  this.globe = globe;
31
53
  this.gl = gl;
32
- if (this.textAngle) {
54
+ if (this.textAngleOn) {
33
55
  this._createTextWriter();
34
56
  }
35
57
  this._initOrchestrations()
@@ -50,16 +72,23 @@ export class PixelPaddingCompassPlugin {
50
72
 
51
73
 
52
74
 
53
- setTextStyle(textStyle) {
54
- this.writer.setStyle(textStyle);
75
+ setFont({ textFont = null, northFont = null } = {}) {
76
+ if (textFont) this.writer.setFont(textFont);
77
+ if (northFont) this.writer.setNorthFont(northFont);
55
78
  this.globe.DrawRender();
56
79
  }
57
80
 
81
+
58
82
  setOpacity(opacity) {
59
83
  this._opacity = opacity;
84
+ this.writer?.setOpacity(opacity);
60
85
  this.globe.DrawRender();
61
86
  }
62
87
 
88
+ getTextWriter() {
89
+ return this.writer;
90
+ }
91
+
63
92
  _initOrchestrations() {
64
93
  const { gl, globe } = this;
65
94
  this.paddingProgram = PixelPaddingForFlatCompassCache.get(globe);
@@ -97,9 +126,11 @@ export class PixelPaddingCompassPlugin {
97
126
  }
98
127
 
99
128
  _createTextWriter() {
100
- this.writer = new ContextTextWriter2Offsets(this.globe, { angle: PaddingAngle });
129
+ this.writer = new PixelPaddingCompassTextWriter(this.globe, { angle: PaddingAngle, ...this._font_hold });
101
130
  }
102
131
 
132
+
133
+
103
134
  __insertText(key, x, y, { properties, update = false } = {}) {
104
135
  if (!this.writer) return;
105
136
  if (update) {
@@ -109,7 +140,7 @@ export class PixelPaddingCompassPlugin {
109
140
  } else {
110
141
  radius = this.defaultProperties.pixelRadiusBig;
111
142
  }
112
- this.writer.insertTextItem(key, x, y, radius);
143
+ this.writer.insertTextItem(key, x, y, radius + textGapFit);
113
144
  } else {
114
145
  this.writer.insertTextItem(key, x, y)
115
146
  }
@@ -1,18 +1,18 @@
1
- import { CSZMode } from "@pirireis/webglobe";
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
- }
1
+ // import { CSZMode } from "@pirireis/webglobe";
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
16
 
17
17
  /**
18
18
  * TODOs:
@@ -20,9 +20,20 @@ const defaultStyle = {
20
20
  * 2) expose a mechanic to update text on zoom change
21
21
  * 3) extend the mechanic on 2 to other events
22
22
  */
23
- export class ContextTextWriter2Offsets {
24
- constructor(globe, { style = null, northStyle = {
25
- textFont: {
23
+ const yGapFit = -2
24
+ const xGapFit = -5
25
+
26
+ export class PixelPaddingCompassTextWriter {
27
+ constructor(globe, {
28
+ font = {
29
+ name: 'Arial',
30
+ textColor: '#FFFFFF', // beyaz
31
+ hollowColor: '#000000', // siyah
32
+ size: 12, // piksel
33
+ hollow: true,
34
+ bold: true,
35
+ italic: false,
36
+ }, northFont = {
26
37
  name: 'Arial',
27
38
  textColor: '#BB0000', // beyaz
28
39
  hollowColor: '#000000', // siyah
@@ -30,14 +41,12 @@ export class ContextTextWriter2Offsets {
30
41
  hollow: true,
31
42
  bold: true,
32
43
  italic: false,
33
- },
34
- opacity: 1.0,
35
- zMode: CSZMode.Z_GROUND_PERVERTEX,
36
- }, doDraw = true, angle = 30, } = {}) {
44
+
45
+ }, doDraw = true, angle = 30, } = {}) {
37
46
  this.globe = globe;
38
47
  this.itemMap = new Map();
39
- this.style = style || defaultStyle;
40
- this.northStyle = northStyle || defaultStyle;
48
+ this.font = font;
49
+ this.northFont = northFont;
41
50
  this.doDraw = doDraw;
42
51
  this.angle = angle;
43
52
 
@@ -67,12 +76,16 @@ export class ContextTextWriter2Offsets {
67
76
  this.doDraw = bool;
68
77
  }
69
78
 
70
- setStyle(style) {
71
- this.style = style;
79
+ setFont(font) {
80
+ this.font = font;
81
+ }
82
+
83
+ setNorthFont(font) {
84
+ this.northFont = font;
72
85
  }
73
86
 
74
87
  setOpacity(opacity) {
75
- this.style.opacity = opacity;
88
+ this.opacity = opacity;
76
89
  }
77
90
 
78
91
 
@@ -89,10 +102,8 @@ export class ContextTextWriter2Offsets {
89
102
 
90
103
  draw() {
91
104
  if (!this.doDraw) return;
92
- const { globe, style, itemMap, texts, angles } = this;
93
- const { textFont, opacity: opacity_ } = style;
94
- const { textFont: nFont } = this.northStyle;
95
- this._checkSetOffsets();
105
+ const { globe, font, opacity: opacity_, northFont, itemMap, texts, angles } = this;
106
+ this._checkSetOffsets();// zMode: CSZMode.Z_GROUND_PERVERTEX,
96
107
  const offsets = this.offsets;
97
108
  for (const [key, { center, radius, opacity = null }] of itemMap) {
98
109
  const o = opacity === null ? opacity_ : opacity * opacity_;
@@ -101,10 +112,10 @@ export class ContextTextWriter2Offsets {
101
112
  const text = texts[i];
102
113
  const angle = angles[i];
103
114
  if (angle === 0) {
104
- globe.api_DrawContextTextMultiLine(text, nFont, o, { x: center.x + offsetX * radius, y: center.y + offsetY * radius });
115
+ globe.api_DrawContextTextMultiLine(text, northFont, o, { x: center.x + offsetX * radius + xGapFit, y: center.y + offsetY * radius + yGapFit });
105
116
 
106
117
  } else {
107
- globe.api_DrawContextTextMultiLine(text, textFont, o, { x: center.x + offsetX * radius, y: center.y + offsetY * radius });
118
+ globe.api_DrawContextTextMultiLine(text, font, o, { x: center.x + offsetX * radius + xGapFit, y: center.y + offsetY * radius + yGapFit });
108
119
 
109
120
  }
110
121
  });
@@ -0,0 +1,3 @@
1
+ import { PixelPaddingCompassTextWriter } from "./compass-text-writer";
2
+ import { PixelPaddingCompassPlugin } from "./compass-rose-padding-flat";
3
+ export { PixelPaddingCompassPlugin, PixelPaddingCompassTextWriter }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.6.1",
3
+ "version": "0.6.2-a",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -261,7 +261,7 @@ export default class RangeRingAngleText {
261
261
  const hideText = centerMap.get("textHide");
262
262
  const isHidden = hide === ENUM_HIDE.HIDE || hideText === ENUM_TEXT_HIDE.HIDE;
263
263
  if (!isHidden) this._fillDeleteBucket(centerID, deleteBucket);
264
- centerMap.set("hide", ENUM_HIDE.HIDE);
264
+ centerMap.set("hideText", ENUM_HIDE.HIDE);
265
265
  }
266
266
  this._updateData(deleteBucket, CSObjectArrayUpdateTypes.DELETE);
267
267
  }
@@ -302,7 +302,7 @@ export default class RangeRingAngleText {
302
302
  for (const [centerID, centerMap] of this._centerCollection) {
303
303
  const hide = centerMap.get("hide");
304
304
  const hideText = centerMap.get("textHide");
305
- if (hide === ENUM_HIDE) continue
305
+ if (hide === ENUM_HIDE.HIDE) continue
306
306
  const isHidden = hideText === ENUM_TEXT_HIDE.HIDE;
307
307
  if (isHidden) {
308
308
  const x = centerMap.get("x");
@@ -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) {
@@ -0,0 +1,169 @@
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 ContextTextWriter2 {
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 = (zoomLevel, item) => 1,
32
+ zoomLevelSizeAdaptor = (zoomLevel, item) => 1,
33
+ } = {}) {
34
+ this.globe = globe;
35
+ this.itemMap = new Map();
36
+ this.style = style;
37
+ this.doDraw = doDraw;
38
+
39
+
40
+ this.textAdaptor = textAdaptor;
41
+ this.coordinatesAdaptor = coordinatesAdaptor;
42
+ this.keyAdaptor = keyAdaptor;
43
+
44
+ this.zoomLevelOpacityAdaptor = zoomLevelOpacityAdaptor;
45
+ this.zoomLevelSizeAdaptor = zoomLevelSizeAdaptor;
46
+
47
+ this.opacityAdaptor = opacityAdaptor ? opacityAdaptor : () => 1;
48
+ this.angleOnSphere = angleOnSphere;
49
+ if (angleAdaptor) {
50
+ this.angleAdaptor = angleAdaptor
51
+ this.angleAdaptorIsOn = true;
52
+ } else {
53
+ this.angleAdaptor = () => null
54
+ this.angleAdaptorIsOn = false
55
+ }
56
+ }
57
+
58
+ setKeyAdaptor(adaptor) {
59
+ this.keyAdaptor = adaptor;
60
+ }
61
+
62
+ setDoDraw(bool) {
63
+ this.doDraw = bool;
64
+ }
65
+
66
+ setStyle(style) {
67
+ this.style = style;
68
+ }
69
+
70
+ setOpacity(opacity) {
71
+ this.style.opacity = opacity;
72
+ }
73
+
74
+
75
+
76
+ draw() {
77
+ if (!this.doDraw) return;
78
+ const { globe, style, itemMap } = this;
79
+ const { textFont, opacity: opacity_ } = style;
80
+ const textSize = textFont.size;
81
+ const is3D = globe.api_GetCurrentGeometry() === 0;
82
+ const angleIsOn = is3D ? (this.angleAdaptorIsOn && this.angleOnSphere) : (this.angleAdaptorIsOn)
83
+ const zoomLevel = globe.api_GetCurrentLODWithDecimal()
84
+ for (const [key, item] of itemMap) {
85
+ const { lat, long, text, opacity = null, angle = null } = item;
86
+ const { x, y } = globe.api_GetScreenPointFromGeo(
87
+ {
88
+ long: long,
89
+ lat: lat,
90
+ z: 0,
91
+ },
92
+ style.zMode === CSZMode.Z_MSL,
93
+ );
94
+ const o = (opacity === null ? opacity_ : opacity * opacity_) * this.zoomLevelOpacityAdaptor(zoomLevel, item);
95
+ textFont.size = this.zoomLevelSizeAdaptor(zoomLevel) * textSize;
96
+
97
+ if (x !== null && y !== null) globe.api_DrawContextTextMultiLine(text, textFont, o, { x, y }, angleIsOn, angle);
98
+ }
99
+ textFont.size = textSize;
100
+ }
101
+
102
+
103
+ updateOpacityOfItem(item, i, container, properties) {
104
+ const opacity = this.opacityAdaptor(item, i, container, properties);
105
+ if (opacity == null) return;
106
+ const key = this.keyAdaptor(item, i, container, properties);
107
+ const data = this.itemMap.get(key)
108
+ data.opacity = opacity;
109
+ }
110
+
111
+ updateOpacityContainer(container, properties) {
112
+ container.forEach((v, i, c) => {
113
+ this.updateOpacityOfItem(v, i, c, properties);
114
+ })
115
+ }
116
+
117
+
118
+ insertTextBulk(container, properties) {
119
+ container.forEach((v, i, c) => {
120
+ this.insertText(v, i, c, properties);
121
+ })
122
+ }
123
+
124
+ updateTextCoords(item, i, container, properties) {
125
+ const coords = this.coordinatesAdaptor(item, i, container, properties);
126
+ if (coords == null) return;
127
+ const key = this.keyAdaptor(item, i, container, properties);
128
+ const data = this.itemMap.get(key)
129
+ data.angle = this.angleAdaptor(item, i, container, properties);
130
+ data.long = coords.long;
131
+ data.lat = coords.lat;
132
+ }
133
+
134
+ updateTextCoordsBulk(container, properties) {
135
+ container.forEach((v, i, c) => {
136
+ this.updateTextCoords(v, i, c, properties)
137
+ })
138
+ }
139
+
140
+ deleteTextBulk(keys) {
141
+ for (const key of keys) {
142
+ this.itemMap.delete(key);
143
+ }
144
+ }
145
+
146
+
147
+ insertText(item, id, container, properties) {
148
+ const key = this.keyAdaptor(item, id, container, properties)
149
+ const coords = this.coordinatesAdaptor(item, id, container, properties)
150
+ if (coords == null) {
151
+ this.itemMap.delete(key);
152
+ return;
153
+ }
154
+ const text = this.textAdaptor(item, id, container, properties)
155
+ if (text == null) {
156
+ this.itemMap.delete(key);
157
+ return
158
+ };
159
+ const opacity = this.opacityAdaptor(item, id, container, properties);
160
+ const angle = this.angleAdaptor(item, id, container, properties);
161
+ this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity, angle });
162
+ }
163
+
164
+ clear() {
165
+ this.itemMap.clear();
166
+ }
167
+ }
168
+
169
+