@pirireis/webglobeplugins 0.6.8 → 0.6.10

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.
@@ -3,6 +3,7 @@ import { LineOnGlobeCache } from '../programs/line-on-globe/naive';
3
3
  import { CircleCache } from '../programs/line-on-globe/circle';
4
4
  import { BufferOrchestrator, BufferManager } from '../util/account';
5
5
  import { AngledLineProgramCache } from '../programs/line-on-globe/angled-line';
6
+ import { mapGetOrThrow } from "../util/check/get";
6
7
  import { ContextTextWriter } from '../write-text/context-text'
7
8
  export const RINGPARTIAL_DRAW_MODE = Object.freeze({
8
9
  LINE_STRIP: "LINE_STRIP",
@@ -235,7 +236,7 @@ export default class Plugin {
235
236
  */
236
237
  insertBulk(items, textWriterInjectionSubSetIDs = []) {
237
238
  const { globe, bufferOrchestrator, bufferManagersCompMap } = this;// angleTextContext, distanceTextContext,
238
- const textWriterInjectionSubSets = this._getTextWriterInjectionSubSet(textWriterInjectionSubSetIDs);
239
+ const textWriterInjectionSubSets = textWriterGetOrThrow(this._textContextInjectionMap, textWriterInjectionSubSetIDs);
239
240
  const data = []
240
241
  for (let item of items) {
241
242
  this._insertTexts(item, textWriterInjectionSubSets);
@@ -269,7 +270,7 @@ export default class Plugin {
269
270
  * @param {Array<string>} textWriterInjectionSubSetIDs | textContextInjectionMap keys to be used for writing text.
270
271
  */
271
272
  updateCoordinatesBulk(items, textWriterInjectionSubSetIDs = []) { //TODO
272
- const injectionsSubSet = this._getTextWriterInjectionSubSet(textWriterInjectionSubSetIDs);
273
+ const injectionsSubSet = textWriterGetOrThrow(this._textContextInjectionMap, textWriterInjectionSubSetIDs);;
273
274
  const { globe, bufferOrchestrator, bufferManagersCompMap, } = this;
274
275
  const data = []
275
276
  for (let item of items) {
@@ -292,7 +293,7 @@ export default class Plugin {
292
293
  updatePartial(items, propertyIDs = [], textWriterInjectionSubSetIDs = []) { // textWriterInjectionSubSetIDs = []
293
294
  if (propertyIDs.length === 0) console.warn("updatePartial is called with no target propertyIDs");
294
295
  const { _textContextInjectionMap, bufferOrchestrator, bufferManagersCompMap } = this;
295
- const writers = this._getTextWriterInjectionSubSet(textWriterInjectionSubSetIDs); // TODO:filter out rgba? this might be a bug
296
+ const writers = textWriterGetOrThrow(this._textContextInjectionMap, textWriterInjectionSubSetIDs);
296
297
  for (let item of items) { this._insertTexts(item, writers) }
297
298
  bufferOrchestrator.updateBulk(items, bufferManagersCompMap, propertyIDs);
298
299
  // patch to update text opacity
@@ -406,17 +407,7 @@ export default class Plugin {
406
407
  });
407
408
  }
408
409
 
409
- textContextInjection
410
- _getTextWriterInjectionSubSet(textWriterIds) {
411
- const { _textContextInjectionMap } = this;
412
- const result = [];
413
- for (const id of textWriterIds) {
414
- const writerAndAdaptors = _textContextInjectionMap.get(id);
415
- if (writerAndAdaptors === undefined) throw new Error("textContextInjection id does not exist in map:" + id);
416
- result.push(writerAndAdaptors)
417
- }
418
- return result;
419
- }
410
+
420
411
  }
421
412
 
422
413
 
@@ -427,6 +418,8 @@ const integralSec = (angle) => {
427
418
  return Math.log(Math.tan(angle / 2 + Math.PI / 4));
428
419
  }
429
420
 
421
+ const textWriterGetOrThrow = mapGetOrThrow("textContextInjection id does not exist in map:")
422
+
430
423
  const calculateStartAngle = (long, lat, endLong, endLat) => {
431
424
  const dLat = (integralSec(endLat) - integralSec(lat)); // Because lines are strectes toward poles.
432
425
  const dLong = endLong - long;
@@ -2,6 +2,7 @@ import { LineOnGlobeCache } from '../programs/line-on-globe/naive';
2
2
  import { CircleCache } from '../programs/line-on-globe/circle';
3
3
  import { BufferOrchestrator, BufferManager } from "../util/account";
4
4
  import { ChainListMap } from "./chain-list-map";
5
+ import { mapGetOrThrow } from "../util/check/get";
5
6
  import { keyMethod } from "./util";
6
7
  import { ContextTextWriter3 } from '../write-text/context-text3';
7
8
  // TODO: Add update buffer and update text mehods on add, delete, update methods
@@ -316,23 +317,12 @@ export class CircleLineChainPlugin {
316
317
 
317
318
  _updateTexts(chainKeys, textWriterIDs) {
318
319
  if (textWriterIDs.length === 0) return;
319
- const textWriters = this._getTextWriterInjectionSubSet(textWriterIDs)
320
+ const textWriters = textWriterGetOrThrow(this._textContextWriterInjectionMap, textWriterIDs)
320
321
  chainKeys.forEach((chainKey) => {
321
322
  this._chainListMap.textUpdate(chainKey, textWriters, this._textDataPreAdaptor);
322
323
  })
323
324
  }
324
325
 
325
- _getTextWriterInjectionSubSet(textWriterIds) {
326
- const { _textContextWriterInjectionMap } = this;
327
- const result = [];
328
- for (const id of textWriterIds) {
329
- const w = _textContextWriterInjectionMap.get(id);
330
- if (w === undefined) throw new Error("textContextInjection id does not exist in map:" + id);
331
- result.push(w)
332
- }
333
- return result;
334
- }
335
-
336
326
 
337
327
  _reconstructChains(chainKeys) {
338
328
  const { globe } = this;
@@ -400,4 +390,6 @@ export class CircleLineChainPlugin {
400
390
 
401
391
  const radiusMethod = (globe) => (v, i, array) => {
402
392
  return globe.Math.GetDist3D(v.long, v.lat, array[i + 1].long, array[i + 1].lat)
403
- }
393
+ }
394
+
395
+ const textWriterGetOrThrow = mapGetOrThrow("textWriterIds is invalid")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -54,7 +54,12 @@ void main() {
54
54
  gl_Position = cartesian3DToGLPosition(position);
55
55
  v_limp = vec2(0.0, 0.0);
56
56
  } else {
57
- vec2 position = circleLimpFromLongLatRadCenterMercatorRealDistance( center_position, radius, angle);
57
+ vec2 position;
58
+ if (radius < 250.0) {
59
+ position = circleLimpFromLongLatRadCenterMercatorCompass( center_position, radius, angle);
60
+ } else {
61
+ position = circleLimpFromLongLatRadCenterMercatorRealDistance( center_position, radius, angle);
62
+ }
58
63
  v_limp = position;
59
64
  gl_Position = mercatorXYToGLPosition( position);
60
65
 
@@ -0,0 +1,12 @@
1
+
2
+ export const mapGetOrThrow = (errorNote) => {
3
+ return (mapInstance, ids) => {
4
+ const result = [];
5
+ for (let i = 0; i < ids.length; i++) {
6
+ const e = mapInstance.get(ids[i]);
7
+ if (e === undefined) throw new Error(errorNote + ":" + ids[i]);
8
+ result.push(e);
9
+ }
10
+ return result;
11
+ }
12
+ }
@@ -1,10 +1,28 @@
1
+ // Generic
1
2
 
3
+ const doesOwnProperties = (properties, errorMessage) => {
4
+ return (object) => {
5
+ properties.forEach(element => {
6
+ if (!Object.hasOwn(object, element)) throw new TypeError(errorMessage + ':' + element);
7
+ });
8
+ }
9
+ }
2
10
 
3
11
  export const isHexColor = (hexColor) => /^#[0-9A-F]{6}$/i.test(hexColor);
4
12
  export const isHexColorWithOpacity = (hexColor) => /^#[0-9A-F]{6}[0-9a-f]{0,2}$/i.test(hexColor);
5
13
 
6
- export const doesOwnProperties = (properties, errorMessage) => (object) => {
7
- properties.array.forEach(element => {
8
- if (!Object.hasOwn(object, element)) throw new TypeError(errorMessage + ' ' + element);
9
- });
14
+ export const opacityCheck = (opacity) => {
15
+ if (typeof opacity !== "number") throw new TypeError("style.opacity must a number");
16
+ if (opacity < 0 || 1 < opacity) throw new RangeError("Opacity Range Must be 0-1");
10
17
  }
18
+ // Text Related
19
+
20
+ const fontCheckTypes = doesOwnProperties(["name", "textColor", "hollowColor", "size", "bold", "italic"], "font does not have");
21
+ const fontCheckColors = (textColor, hollowColor) => isHexColor(textColor) && isHexColor(hollowColor);
22
+ export const isTextFont = (textFont) => {
23
+ fontCheckTypes(textFont);
24
+ fontCheckColors(textFont.textColor, textFont.hollowColor);
25
+ if (typeof textFont.size !== "number") throw new TypeError("textFont size is not a number");
26
+
27
+ }
28
+
@@ -1,4 +1,5 @@
1
1
  import { CSZMode } from "@pirireis/webglobe";
2
+ import { isTextFont, opacityCheck } from "../util/check/typecheck";
2
3
 
3
4
  /**
4
5
  * TODOs:
@@ -39,9 +40,8 @@ export class ContextTextWriter3 {
39
40
  } = {}) {
40
41
  this.globe = globe;
41
42
  this.itemMap = new Map();
42
- this.style = style;
43
+ this.setStyle(style);
43
44
  this.doDraw = doDraw;
44
-
45
45
  this._checkParameterTypes(textAdaptor, coordinatesAdaptor, keyAdaptor, opacityAdaptor, angleAdaptor, xOffset, yOffset);
46
46
 
47
47
  this.textAdaptor = textAdaptor;
@@ -83,6 +83,8 @@ export class ContextTextWriter3 {
83
83
  }
84
84
 
85
85
  setStyle(style) {
86
+ isTextFont(style.textFont);
87
+ opacityCheck(style.opacity);
86
88
  this.style = style;
87
89
  }
88
90
 
@@ -1,12 +0,0 @@
1
- import { doesOwnProperties, isHexColor } from "../util/check/typecheck";
2
-
3
- const fontCheckTypes = doesOwnProperties(["name", "textColor", "hollowColor", "size", "bold", "italic"], "font does not have");
4
- const fontCheckColors = (textColor, hollowColor) => isHexColor(textColor) && isHexColor(hollowColor);
5
-
6
- export const isTextFont = (textFont) => {
7
- fontCheckTypes(textFont);
8
- fontCheckColors(textFont.textColor, textFont.hollowColor);
9
- if (!(textFont.size instanceof Number)) throw new TypeError("textFont size is not a number");
10
-
11
- }
12
-