@pirireis/webglobeplugins 0.5.12 → 0.6.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.
@@ -1,38 +1,45 @@
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 "../write-text/context-text-2d-offsets"
4
+ import { ContextTextWriter2Offsets } from "./compass-text-writer"
5
+
6
+ const PaddingAngle = 30;
5
7
 
6
8
  export class PixelPaddingCompassPlugin {
7
9
  constructor(id, {
8
10
  opacity = 1,
9
- textAngle = null, defaultProperties = {
11
+ textAngle = true,
12
+ defaultProperties = {
10
13
  rgba: [1, 1, 1, 1],
11
14
  pixelRadiusBig: 350,
12
15
  pixelRadiusSmall: 270
13
16
  }
14
17
  } = {}) {
15
18
  this.id = id;
16
- this._textAngle = textAngle;
17
19
  this.textWriters = null
18
- if (textAngle == null) {
19
- this._createTextWriters();
20
- }
20
+ this.textAngle = textAngle
21
+ this.defaultProperties = defaultProperties
21
22
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
22
- this.compassMap = new CompassMap({ defaultProperties });
23
+
24
+ this.compassMap = new CompassMap(this);
23
25
  this._opacity = opacity;
26
+
24
27
  }
25
28
 
26
29
  init(globe, gl) {
27
30
  this.globe = globe;
28
31
  this.gl = gl;
29
-
32
+ if (this.textAngle) {
33
+ this._createTextWriter();
34
+ }
30
35
  this._initOrchestrations()
31
36
  }
32
37
 
33
38
  insert(key, long, lat, properties = null) {
39
+ this.__insertText(key, null, null, { properties, update: true });
34
40
  this.compassMap.insert(key, long, lat, properties);
35
41
  this.globe.DrawRender();
42
+
36
43
  }
37
44
 
38
45
 
@@ -42,14 +49,9 @@ export class PixelPaddingCompassPlugin {
42
49
  }
43
50
 
44
51
 
45
- setTextAngle(textAngle) {
46
- this._textAngle = textAngle;
47
- this._createTextWriters();
48
- this.globe.DrawRender();
49
- }
50
52
 
51
53
  setTextStyle(textStyle) {
52
- this.textWriters?.forEach((writer) => writer.setStyle(textStyle));
54
+ this.writer.setStyle(textStyle);
53
55
  this.globe.DrawRender();
54
56
  }
55
57
 
@@ -94,48 +96,57 @@ export class PixelPaddingCompassPlugin {
94
96
  }
95
97
  }
96
98
 
97
- _createTextWriters() {
98
- this.writer = new ContextTextWriter2Offsets(this.globe);
99
+ _createTextWriter() {
100
+ this.writer = new ContextTextWriter2Offsets(this.globe, { angle: PaddingAngle });
101
+ }
102
+
103
+ __insertText(key, x, y, { properties, update = false } = {}) {
104
+ if (!this.writer) return;
105
+ if (update) {
106
+ let radius;
107
+ if (properties != null && properties.pixelRadiusBig) {
108
+ radius = properties.pixelRadiusBig
109
+ } else {
110
+ radius = this.defaultProperties.pixelRadiusBig;
111
+ }
112
+ this.writer.insertTextItem(key, x, y, radius);
113
+ } else {
114
+ this.writer.insertTextItem(key, x, y)
115
+ }
99
116
  }
100
117
 
101
118
  // Globe API interface methods
102
119
 
103
120
  draw2D() {
104
-
105
121
  const { gl, globe, paddingProgram, paddingVao, bufferOrchestrator, bufferManagersCompMap } = this;
106
- const items = this.compassMap.query(globe);
122
+ const is3D = globe.api_GetCurrentGeometry() === 0;
123
+ if (is3D) return;
124
+ const items = this.compassMap.query(globe, this.writer);
107
125
  if (items.length === 0) return;
108
- const { x, y, properties } = items[0];
109
- console.log(x, y, properties);
110
126
  bufferOrchestrator.flush();
111
127
  bufferOrchestrator.insertBulk(items, bufferManagersCompMap);
128
+ items.forEach((v) => {
129
+ this.__insertText(v.key, v.x, v.y)
130
+ });
112
131
  gl.disable(gl.DEPTH_TEST);
113
132
  paddingProgram.draw(paddingVao, bufferOrchestrator.length, this._opacity)
114
133
  gl.enable(gl.DEPTH_TEST);
134
+ this.writer?.draw();
115
135
  }
116
136
 
117
137
  free() {
118
138
 
139
+
119
140
  }
120
141
  }
121
142
 
122
143
 
123
144
 
124
145
  class CompassMap {
125
- constructor({ defaultProperties = null } = {}) {
146
+ constructor(parent) {
126
147
  this.coordsMemory = new Map();
127
148
  this.propertyMemory = new Map();
128
- if (defaultProperties !== null) {
129
-
130
- this.defaultProperties = defaultProperties
131
- } else {
132
-
133
- this.defaultProperties = {
134
- rgba: [1, 1, 1, 1],
135
- pixelRadiusBig: 350,
136
- pixelRadiusSmall: 270
137
- }
138
- }
149
+ this.parent = parent;
139
150
  }
140
151
 
141
152
  insert(key, long, lat, properties = null) {
@@ -148,8 +159,9 @@ class CompassMap {
148
159
  this.propertyMemory.delete(key);
149
160
  }
150
161
 
151
- query(globe) {
152
- const { coordsMemory, propertyMemory, defaultProperties } = this;
162
+ query(globe, writer) {
163
+ const { coordsMemory, propertyMemory } = this;
164
+ const defaultProperties = this.parent.defaultProperties;
153
165
  const result = [];
154
166
  coordsMemory.forEach((v, k, c) => {
155
167
  const { x, y } = globe.api_GetScreenPointFromGeo(
@@ -160,6 +172,8 @@ class CompassMap {
160
172
  },
161
173
 
162
174
  );
175
+ writer?.insertTextItem(k, x, y);
176
+
163
177
  if (x !== null) {
164
178
  const properties = { ...defaultProperties, ...propertyMemory.get(k) };
165
179
  result.push({ key: k, x, y, properties })
@@ -0,0 +1,154 @@
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
+
17
+ /**
18
+ * TODOs:
19
+ * 1) update all if initials change (propably need a context and a callback to iterate over data)
20
+ * 2) expose a mechanic to update text on zoom change
21
+ * 3) extend the mechanic on 2 to other events
22
+ */
23
+ export class ContextTextWriter2Offsets {
24
+ constructor(globe, { style = null, northStyle = {
25
+ textFont: {
26
+ name: 'Arial',
27
+ textColor: '#BB0000', // beyaz
28
+ hollowColor: '#000000', // siyah
29
+ size: 14, // piksel
30
+ hollow: true,
31
+ bold: true,
32
+ italic: false,
33
+ },
34
+ opacity: 1.0,
35
+ zMode: CSZMode.Z_GROUND_PERVERTEX,
36
+ }, doDraw = true, angle = 30, } = {}) {
37
+ this.globe = globe;
38
+ this.itemMap = new Map();
39
+ this.style = style || defaultStyle;
40
+ this.northStyle = northStyle || defaultStyle;
41
+ this.doDraw = doDraw;
42
+ this.angle = angle;
43
+
44
+ this.angles = []
45
+ this.texts = []
46
+ let currentAngle = 0;
47
+ while (currentAngle < 360) {
48
+ this.angles.push(currentAngle);
49
+ if (currentAngle == 0) {
50
+ this.texts.push("K");
51
+ } else {
52
+ this.texts.push(currentAngle.toString());
53
+ }
54
+ currentAngle += this.angle;
55
+ }
56
+ this._lastNorthAngle = globe.api_GetCurrentLookInfo()["NorthAng"] * (Math.PI / 180);
57
+ this.offsets = this.__offset(this._lastNorthAngle);
58
+
59
+
60
+ }
61
+
62
+ setKeyAdaptor(adaptor) {
63
+ this.keyAdaptor = adaptor;
64
+ }
65
+
66
+ setDoDraw(bool) {
67
+ this.doDraw = bool;
68
+ }
69
+
70
+ setStyle(style) {
71
+ this.style = style;
72
+ }
73
+
74
+ setOpacity(opacity) {
75
+ this.style.opacity = opacity;
76
+ }
77
+
78
+
79
+ _checkSetOffsets() {
80
+ const { globe } = this;
81
+ const newAngle = globe.api_GetCurrentLookInfo()["NorthAng"] * (Math.PI / 180);;
82
+ console.log("n angle", newAngle);
83
+ if (newAngle !== this._lastNorthAngle) {
84
+ this._lastNorthAngle = newAngle;
85
+ this.offsets = this.__offset();
86
+ }
87
+ }
88
+
89
+
90
+ draw() {
91
+ 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();
96
+ const offsets = this.offsets;
97
+ for (const [key, { center, radius, opacity = null }] of itemMap) {
98
+ const o = opacity === null ? opacity_ : opacity * opacity_;
99
+ if (center.x !== null && center.y !== null) {
100
+ offsets.forEach(({ offsetX, offsetY }, i) => {
101
+ const text = texts[i];
102
+ const angle = angles[i];
103
+ if (angle === 0) {
104
+ globe.api_DrawContextTextMultiLine(text, nFont, o, { x: center.x + offsetX * radius, y: center.y + offsetY * radius });
105
+
106
+ } else {
107
+ globe.api_DrawContextTextMultiLine(text, textFont, o, { x: center.x + offsetX * radius, y: center.y + offsetY * radius });
108
+
109
+ }
110
+ });
111
+ }
112
+
113
+ }
114
+ }
115
+
116
+
117
+ insertTextItem(key, x, y, radius = undefined) {
118
+ const item = this.getItem(key);
119
+ item.center = { x, y };
120
+ if (radius === undefined) return;
121
+ if (item.radius != undefined && item.radius === radius) return;
122
+ item.radius = radius;
123
+
124
+ }
125
+
126
+ getItem(key) {
127
+ if (!this.itemMap.has(key)) this.itemMap.set(key, {});
128
+ return this.itemMap.get(key);
129
+ }
130
+
131
+ __calculateOffset(angle) {
132
+ const rAngle = (angle - 90) * (Math.PI / 180);
133
+ return { offsetX: Math.cos(rAngle + this._lastNorthAngle), offsetY: Math.sin(rAngle + this._lastNorthAngle) };
134
+ }
135
+
136
+ __offset() {
137
+ const angle = this.angle;
138
+ const offsets = []
139
+ let currentAngle = 0;
140
+ while (currentAngle < 360) {
141
+ offsets.push(this.__calculateOffset(currentAngle));
142
+
143
+ currentAngle += angle;
144
+ }
145
+ return offsets;
146
+ }
147
+
148
+
149
+ clear() {
150
+ this.itemMap.clear();
151
+ }
152
+ }
153
+
154
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.5.12",
3
+ "version": "0.6.1",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -20,15 +20,24 @@ vec3 coord_opacity(){
20
20
  if( gl_VertexID % 2 == 0){
21
21
  if ( gl_VertexID % 60 == 0){
22
22
  radius = pixel_radius_small;
23
+ } else if( gl_VertexID % 10 == 0) {
24
+ float gap = (pixel_radius_big - pixel_radius_small) / 4.0;
25
+ radius = pixel_radius_small + gap;
23
26
  } else {
24
- radius = (pixel_radius_big + pixel_radius_small) / 2.0;
27
+ float gap = (pixel_radius_big - pixel_radius_small) * 0.75;
28
+ radius = pixel_radius_small + gap;
25
29
  }
26
30
  angle = (float(gl_VertexID) / (${vertexCount}.0));
27
31
  } else {
28
- radius = pixel_radius_big;
32
+ if ( gl_VertexID % 60 == 1){
33
+ radius = pixel_radius_big + 10.0;
34
+
35
+ } else {
36
+ radius = pixel_radius_big;
37
+ }
29
38
  angle = (float(gl_VertexID - 1) / (${vertexCount}.0));
30
39
  }
31
- float opacity = fract(angle + 0.2475) / 1.5 + 0.25;
40
+ float opacity = fract(angle + 0.2475) / 1.5 + 0.33;
32
41
  angle = angle * ${Math.PI * 2.0} + world_north_angle;
33
42
 
34
43
  return vec3( screen_coordinate + vec2( cos(angle), sin(angle)) * radius, opacity);
@@ -1,149 +0,0 @@
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
-
17
- /**
18
- * TODOs:
19
- * 1) update all if initials change (propably need a context and a callback to iterate over data)
20
- * 2) expose a mechanic to update text on zoom change
21
- * 3) extend the mechanic on 2 to other events
22
- */
23
- export class ContextTextWriter2Offsets {
24
- constructor(globe, { style = null, doDraw = true, textAdaptor = null, coordinatesAdaptor = null, keyAdaptor = null, opacityAdaptor = null, angleAdaptor = null, angleOnSphere = false } = {}) {
25
- this.globe = globe;
26
- this.itemMap = new Map();
27
- this.style = style || defaultStyle;
28
- this.doDraw = doDraw;
29
-
30
-
31
- this.textAdaptor = textAdaptor;
32
- this.coordinatesAdaptor = coordinatesAdaptor;
33
- this.keyAdaptor = keyAdaptor;
34
-
35
- this.opacityAdaptor = opacityAdaptor ? opacityAdaptor : () => 1;
36
- this.angleOnSphere = angleOnSphere;
37
- if (angleAdaptor) {
38
- this.angleAdaptor = angleAdaptor
39
- this.angleAdaptorIsOn = true;
40
- } else {
41
- this.angleAdaptor = () => null
42
- this.angleAdaptorIsOn = false
43
- }
44
- }
45
-
46
- setKeyAdaptor(adaptor) {
47
- this.keyAdaptor = adaptor;
48
- }
49
-
50
- setDoDraw(bool) {
51
- this.doDraw = bool;
52
- }
53
-
54
- setStyle(style) {
55
- this.style = style;
56
- }
57
-
58
- setOpacity(opacity) {
59
- this.style.opacity = opacity;
60
- }
61
-
62
-
63
-
64
- draw() {
65
- if (!this.doDraw) return;
66
- const { globe, style, itemMap } = this;
67
- const { textFont, opacity: opacity_ } = style;
68
- const is3D = globe.api_GetCurrentGeometry() === 0;
69
- const angleIsOn = is3D ? (this.angleAdaptorIsOn && this.angleOnSphere) : (this.angleAdaptorIsOn)
70
- for (const [key, { center, offsets, texts, opacity = null, angle = null }] of itemMap) {
71
- const o = opacity === null ? opacity_ : opacity * opacity_;
72
- if (center.x !== null && center.y !== null) {
73
- offsets.forEach(({ offsetX, offsetY }, i) => {
74
- const text = texts[i];
75
- globe.api_DrawContextTextMultiLine(text, textFont, o, { x: center.x + offsetX, y: center.y + offsetY }, angleIsOn, angle);
76
- });
77
- }
78
-
79
- }
80
- }
81
-
82
-
83
- updateOpacityOfItem(item, i, container, properties) {
84
- const opacity = this.opacityAdaptor(item, i, container, properties);
85
- if (opacity == null) return;
86
- const key = this.keyAdaptor(item, i, container, properties);
87
- const data = this.itemMap.get(key)
88
- data.opacity = opacity;
89
- }
90
-
91
- updateOpacityContainer(container, properties) {
92
- container.forEach((v, i, c) => {
93
- this.updateOpacityOfItem(v, i, c, properties);
94
- })
95
- }
96
-
97
-
98
- insertTextBulk(container, properties) {
99
- container.forEach((v, i, c) => {
100
- this.insertText(v, i, c, properties);
101
- })
102
- }
103
-
104
- updateTextCoords(item, i, container, properties) {
105
- const coords = this.coordinatesAdaptor(item, i, container, properties);
106
- if (coords == null) return;
107
- const key = this.keyAdaptor(item, i, container, properties);
108
- const data = this.itemMap.get(key)
109
- data.angle = this.angleAdaptor(item, i, container, properties);
110
- data.long = coords.long;
111
- data.lat = coords.lat;
112
- }
113
-
114
- updateTextCoordsBulk(container, properties) {
115
- container.forEach((v, i, c) => {
116
- this.updateTextCoords(v, i, c, properties)
117
- })
118
- }
119
-
120
- deleteTextBulk(keys) {
121
- for (const key of keys) {
122
- this.itemMap.delete(key);
123
- }
124
- }
125
-
126
-
127
- insertText(item, id, container, properties) {
128
- const key = this.keyAdaptor(item, id, container, properties)
129
- const coords = this.coordinatesAdaptor(item, id, container, properties)
130
- if (coords == null) {
131
- this.itemMap.delete(key);
132
- return;
133
- }
134
- const text = this.textAdaptor(item, id, container, properties)
135
- if (text == null) {
136
- this.itemMap.delete(key);
137
- return
138
- };
139
- const opacity = this.opacityAdaptor(item, id, container, properties);
140
- const angle = this.angleAdaptor(item, id, container, properties);
141
- this.itemMap.set(key, { long: coords.long, lat: coords.lat, text, opacity, angle });
142
- }
143
-
144
- clear() {
145
- this.itemMap.clear();
146
- }
147
- }
148
-
149
-