@pirireis/webglobeplugins 0.6.0 → 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,41 +1,64 @@
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;
48
+
26
49
  }
27
50
 
28
51
  init(globe, gl) {
29
52
  this.globe = globe;
30
53
  this.gl = gl;
31
- if (this.textAngle) {
54
+ if (this.textAngleOn) {
32
55
  this._createTextWriter();
33
56
  }
34
57
  this._initOrchestrations()
35
58
  }
36
59
 
37
60
  insert(key, long, lat, properties = null) {
38
- this.__insertText(key, null, null, properties);
61
+ this.__insertText(key, null, null, { properties, update: true });
39
62
  this.compassMap.insert(key, long, lat, properties);
40
63
  this.globe.DrawRender();
41
64
 
@@ -49,16 +72,23 @@ export class PixelPaddingCompassPlugin {
49
72
 
50
73
 
51
74
 
52
- setTextStyle(textStyle) {
53
- this.writer.setStyle(textStyle);
75
+ setFont({ textFont = null, northFont = null } = {}) {
76
+ if (textFont) this.writer.setFont(textFont);
77
+ if (northFont) this.writer.setNorthFont(northFont);
54
78
  this.globe.DrawRender();
55
79
  }
56
80
 
81
+
57
82
  setOpacity(opacity) {
58
83
  this._opacity = opacity;
84
+ this.writer?.setOpacity(opacity);
59
85
  this.globe.DrawRender();
60
86
  }
61
87
 
88
+ getTextWriter() {
89
+ return this.writer;
90
+ }
91
+
62
92
  _initOrchestrations() {
63
93
  const { gl, globe } = this;
64
94
  this.paddingProgram = PixelPaddingForFlatCompassCache.get(globe);
@@ -96,18 +126,24 @@ export class PixelPaddingCompassPlugin {
96
126
  }
97
127
 
98
128
  _createTextWriter() {
99
- this.writer = new ContextTextWriter2Offsets(this.globe, { angle: PaddingAngle });
129
+ this.writer = new PixelPaddingCompassTextWriter(this.globe, { angle: PaddingAngle, ...this._font_hold });
100
130
  }
101
131
 
102
- __insertText(key, x, y, properties) {
132
+
133
+
134
+ __insertText(key, x, y, { properties, update = false } = {}) {
103
135
  if (!this.writer) return;
104
- let radius;
105
- if (properties != null && properties.pixelRadiusBig) {
106
- radius = properties.pixelRadiusBig
136
+ if (update) {
137
+ let radius;
138
+ if (properties != null && properties.pixelRadiusBig) {
139
+ radius = properties.pixelRadiusBig
140
+ } else {
141
+ radius = this.defaultProperties.pixelRadiusBig;
142
+ }
143
+ this.writer.insertTextItem(key, x, y, radius + textGapFit);
107
144
  } else {
108
- radius = this.defaultProperties.pixelRadiusBig;
145
+ this.writer.insertTextItem(key, x, y)
109
146
  }
110
- this.writer.insertTextItem(key, x, y, radius);
111
147
  }
112
148
 
113
149
  // Globe API interface methods
@@ -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,14 +20,51 @@ 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, doDraw = true, angle = 30, } = {}) {
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 = {
37
+ name: 'Arial',
38
+ textColor: '#BB0000', // beyaz
39
+ hollowColor: '#000000', // siyah
40
+ size: 14, // piksel
41
+ hollow: true,
42
+ bold: true,
43
+ italic: false,
44
+
45
+ }, doDraw = true, angle = 30, } = {}) {
25
46
  this.globe = globe;
26
47
  this.itemMap = new Map();
27
- this.style = style || defaultStyle;
48
+ this.font = font;
49
+ this.northFont = northFont;
28
50
  this.doDraw = doDraw;
29
51
  this.angle = angle;
30
52
 
53
+ this.angles = []
54
+ this.texts = []
55
+ let currentAngle = 0;
56
+ while (currentAngle < 360) {
57
+ this.angles.push(currentAngle);
58
+ if (currentAngle == 0) {
59
+ this.texts.push("K");
60
+ } else {
61
+ this.texts.push(currentAngle.toString());
62
+ }
63
+ currentAngle += this.angle;
64
+ }
65
+ this._lastNorthAngle = globe.api_GetCurrentLookInfo()["NorthAng"] * (Math.PI / 180);
66
+ this.offsets = this.__offset(this._lastNorthAngle);
67
+
31
68
 
32
69
  }
33
70
 
@@ -39,31 +76,48 @@ export class ContextTextWriter2Offsets {
39
76
  this.doDraw = bool;
40
77
  }
41
78
 
42
- setStyle(style) {
43
- this.style = style;
79
+ setFont(font) {
80
+ this.font = font;
81
+ }
82
+
83
+ setNorthFont(font) {
84
+ this.northFont = font;
44
85
  }
45
86
 
46
87
  setOpacity(opacity) {
47
- this.style.opacity = opacity;
88
+ this.opacity = opacity;
48
89
  }
49
90
 
50
91
 
92
+ _checkSetOffsets() {
93
+ const { globe } = this;
94
+ const newAngle = globe.api_GetCurrentLookInfo()["NorthAng"] * (Math.PI / 180);;
95
+ console.log("n angle", newAngle);
96
+ if (newAngle !== this._lastNorthAngle) {
97
+ this._lastNorthAngle = newAngle;
98
+ this.offsets = this.__offset();
99
+ }
100
+ }
101
+
51
102
 
52
103
  draw() {
53
104
  if (!this.doDraw) return;
54
- const { globe, style, itemMap } = this;
55
- const { textFont, opacity: opacity_ } = style;
56
- const is3D = globe.api_GetCurrentGeometry() === 0;
57
- if (is3D) return;
58
- const angleIsOn = is3D ? (this.angleAdaptorIsOn && this.angleOnSphere) : (this.angleAdaptorIsOn)
59
- for (const [key, { center, offsets, texts, opacity = null, angles }] of itemMap) {
105
+ const { globe, font, opacity: opacity_, northFont, itemMap, texts, angles } = this;
106
+ this._checkSetOffsets();// zMode: CSZMode.Z_GROUND_PERVERTEX,
107
+ const offsets = this.offsets;
108
+ for (const [key, { center, radius, opacity = null }] of itemMap) {
60
109
  const o = opacity === null ? opacity_ : opacity * opacity_;
61
110
  if (center.x !== null && center.y !== null) {
62
111
  offsets.forEach(({ offsetX, offsetY }, i) => {
63
112
  const text = texts[i];
64
113
  const angle = angles[i];
65
- console.log("asdfadsf", text, angle, center, offsetX, offsetY);
66
- globe.api_DrawContextTextMultiLine(text, textFont, o, { x: center.x + offsetX, y: center.y + offsetY }, angleIsOn, angle);
114
+ if (angle === 0) {
115
+ globe.api_DrawContextTextMultiLine(text, northFont, o, { x: center.x + offsetX * radius + xGapFit, y: center.y + offsetY * radius + yGapFit });
116
+
117
+ } else {
118
+ globe.api_DrawContextTextMultiLine(text, font, o, { x: center.x + offsetX * radius + xGapFit, y: center.y + offsetY * radius + yGapFit });
119
+
120
+ }
67
121
  });
68
122
  }
69
123
 
@@ -71,15 +125,13 @@ export class ContextTextWriter2Offsets {
71
125
  }
72
126
 
73
127
 
74
- insertTextItem(key, x, y, radius) {
128
+ insertTextItem(key, x, y, radius = undefined) {
75
129
  const item = this.getItem(key);
76
130
  item.center = { x, y };
131
+ if (radius === undefined) return;
77
132
  if (item.radius != undefined && item.radius === radius) return;
78
133
  item.radius = radius;
79
- const { offsets, angles, texts } = this.__offsetAngleText(radius);
80
- item.offsets = offsets;
81
- item.angles = angles;
82
- item.texts = texts;
134
+
83
135
  }
84
136
 
85
137
  getItem(key) {
@@ -87,28 +139,21 @@ export class ContextTextWriter2Offsets {
87
139
  return this.itemMap.get(key);
88
140
  }
89
141
 
90
- __calculateOffset(radius, angle) {
142
+ __calculateOffset(angle) {
91
143
  const rAngle = (angle - 90) * (Math.PI / 180);
92
- return { offsetX: Math.cos(rAngle) * radius, offsetY: Math.sin(rAngle) * radius };
144
+ return { offsetX: Math.cos(rAngle + this._lastNorthAngle), offsetY: Math.sin(rAngle + this._lastNorthAngle) };
93
145
  }
94
146
 
95
- __offsetAngleText(radius) {
147
+ __offset() {
96
148
  const angle = this.angle;
97
149
  const offsets = []
98
- const angles = []
99
- const texts = []
100
150
  let currentAngle = 0;
101
151
  while (currentAngle < 360) {
102
- offsets.push(this.__calculateOffset(radius + 10, currentAngle));
103
- angles.push(currentAngle);
104
- if (currentAngle == 0) {
105
- texts.push("K");
106
- } else {
107
- texts.push(currentAngle.toString());
108
- }
152
+ offsets.push(this.__calculateOffset(currentAngle));
153
+
109
154
  currentAngle += angle;
110
155
  }
111
- return { offsets, angles, texts };
156
+ return offsets;
112
157
  }
113
158
 
114
159
 
@@ -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.0",
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
+