@pirireis/webglobeplugins 0.6.7 → 0.6.9
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.
- package/bearing-line/plugin.js +15 -12
- package/circle-line-chain/plugin.js +7 -4
- package/package.json +1 -1
- package/util/check/get.js +12 -0
- package/util/check/index.js +0 -0
- package/util/check/typecheck.js +23 -0
- package/write-text/context-text3.js +11 -0
- package/write-text/util.js +4 -0
package/bearing-line/plugin.js
CHANGED
|
@@ -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",
|
|
@@ -65,12 +66,12 @@ export default class Plugin {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
_checkTextContextInjectionMap(textContextInjectionMap) {
|
|
68
|
-
if (!(textContextInjectionMap instanceof Map)) throw new
|
|
69
|
+
if (!(textContextInjectionMap instanceof Map)) throw new TypeError("textContextInjectionMap is not instance of Map");
|
|
69
70
|
textContextInjectionMap.forEach((v) => {
|
|
70
|
-
if (typeof v !== 'object') throw new
|
|
71
|
-
if (typeof v.coordsAdaptor !== 'function') throw new
|
|
72
|
-
if (typeof v.textAdaptor !== 'function') throw new
|
|
73
|
-
if (!(v.writer instanceof ContextTextWriter)) throw new
|
|
71
|
+
if (typeof v !== 'object') throw new TypeError("textContextInjectionMap format is wrong");
|
|
72
|
+
if (typeof v.coordsAdaptor !== 'function') throw new TypeError("textContextInjectionMap coordsAdaptor format is wrong");
|
|
73
|
+
if (typeof v.textAdaptor !== 'function') throw new TypeError("textContextInjectionMap textAdaptor format is wrong");
|
|
74
|
+
if (!(v.writer instanceof ContextTextWriter)) throw new TypeError("textContextInjectionMap writer is not instance of ContextTextWriter");
|
|
74
75
|
})
|
|
75
76
|
}
|
|
76
77
|
|
|
@@ -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 =
|
|
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 =
|
|
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) {
|
|
@@ -285,24 +286,23 @@ export default class Plugin {
|
|
|
285
286
|
/**
|
|
286
287
|
*
|
|
287
288
|
* @param {*} items some colums EXCEPT positional ones
|
|
288
|
-
* @param {
|
|
289
|
-
* @param {
|
|
289
|
+
* @param {string} propertyIDs
|
|
290
|
+
* @param {string} textWriterInjectionSubSetIDs
|
|
290
291
|
* Do NOT send empty data if property ID of this data is entered or NaN is loaded to the buffer, resulting in an unwanted behaviour.
|
|
291
292
|
*/
|
|
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 = textWriterInjectionSubSetIDs
|
|
296
|
+
const writers = textWriterGetOrThrow(this._textContextInjectionMap, textWriterInjectionSubSetIDs); // TODO:filter out rgba? this might be a bug
|
|
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
|
|
299
300
|
for (const property of propertyIDs) {
|
|
300
301
|
if (property === "rgba") {
|
|
301
|
-
|
|
302
|
+
_textContextInjectionMap.forEach((v) => {
|
|
302
303
|
const { writer } = v;
|
|
303
304
|
writer.updateOpacityBulk(items, (e) => e.key, (e) => e.rgba[3]);
|
|
304
305
|
})
|
|
305
|
-
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
this.globe.DrawRender();
|
|
@@ -407,6 +407,7 @@ export default class Plugin {
|
|
|
407
407
|
});
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
+
|
|
410
411
|
}
|
|
411
412
|
|
|
412
413
|
|
|
@@ -417,6 +418,8 @@ const integralSec = (angle) => {
|
|
|
417
418
|
return Math.log(Math.tan(angle / 2 + Math.PI / 4));
|
|
418
419
|
}
|
|
419
420
|
|
|
421
|
+
const textWriterGetOrThrow = mapGetOrThrow("textContextInjection id does not exist in map:")
|
|
422
|
+
|
|
420
423
|
const calculateStartAngle = (long, lat, endLong, endLat) => {
|
|
421
424
|
const dLat = (integralSec(endLat) - integralSec(lat)); // Because lines are strectes toward poles.
|
|
422
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
|
|
@@ -46,6 +47,7 @@ export class CircleLineChainPlugin {
|
|
|
46
47
|
textDataPreAdaptor = null
|
|
47
48
|
} = {}) {
|
|
48
49
|
this.id = id;
|
|
50
|
+
this._checkTextContextWriterInjectionMap(textContextWriterInjectionMap);
|
|
49
51
|
this._textContextWriterInjectionMap = textContextWriterInjectionMap;
|
|
50
52
|
this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, properties) => v.__identity__));
|
|
51
53
|
this._opacity = 1;
|
|
@@ -297,7 +299,6 @@ export class CircleLineChainPlugin {
|
|
|
297
299
|
chainKeysToReconstuct.push(chainKey);
|
|
298
300
|
});
|
|
299
301
|
this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
|
|
300
|
-
// if (textWriterIDs) this._updateTexts(chainKeysToReconstuct, textWriterIDs)
|
|
301
302
|
this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
|
|
302
303
|
this._reconstructChains(chainKeysToReconstuct);
|
|
303
304
|
this._updateTexts(chainKeysToReconstuct, textWriterIDs);
|
|
@@ -315,14 +316,14 @@ export class CircleLineChainPlugin {
|
|
|
315
316
|
// implicit
|
|
316
317
|
|
|
317
318
|
_updateTexts(chainKeys, textWriterIDs) {
|
|
318
|
-
|
|
319
|
+
if (textWriterIDs.length === 0) return;
|
|
320
|
+
const textWriters = textWriterGetOrThrow(this._textContextWriterInjectionMap, textWriterIDs)
|
|
319
321
|
chainKeys.forEach((chainKey) => {
|
|
320
322
|
this._chainListMap.textUpdate(chainKey, textWriters, this._textDataPreAdaptor);
|
|
321
323
|
})
|
|
322
324
|
}
|
|
323
325
|
|
|
324
326
|
|
|
325
|
-
|
|
326
327
|
_reconstructChains(chainKeys) {
|
|
327
328
|
const { globe } = this;
|
|
328
329
|
// this.lineVao = this.lineProgram.createVAO(
|
|
@@ -389,4 +390,6 @@ export class CircleLineChainPlugin {
|
|
|
389
390
|
|
|
390
391
|
const radiusMethod = (globe) => (v, i, array) => {
|
|
391
392
|
return globe.Math.GetDist3D(v.long, v.lat, array[i + 1].long, array[i + 1].lat)
|
|
392
|
-
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const textWriterGetOrThrow = mapGetOrThrow("textWriterIds is invalid")
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Generic
|
|
2
|
+
|
|
3
|
+
export const doesOwnProperties = (properties, errorMessage) => (object) => {
|
|
4
|
+
properties.array.forEach(element => {
|
|
5
|
+
if (!Object.hasOwn(object, element)) throw new TypeError(errorMessage + ':' + element);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const isHexColor = (hexColor) => /^#[0-9A-F]{6}$/i.test(hexColor);
|
|
10
|
+
export const isHexColorWithOpacity = (hexColor) => /^#[0-9A-F]{6}[0-9a-f]{0,2}$/i.test(hexColor);
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// Text Related
|
|
14
|
+
|
|
15
|
+
const fontCheckTypes = doesOwnProperties(["name", "textColor", "hollowColor", "size", "bold", "italic"], "font does not have");
|
|
16
|
+
const fontCheckColors = (textColor, hollowColor) => isHexColor(textColor) && isHexColor(hollowColor);
|
|
17
|
+
export const isTextFont = (textFont) => {
|
|
18
|
+
fontCheckTypes(textFont);
|
|
19
|
+
fontCheckColors(textFont.textColor, textFont.hollowColor);
|
|
20
|
+
if (!(textFont.size instanceof Number)) throw new TypeError("textFont size is not a number");
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
@@ -42,6 +42,7 @@ export class ContextTextWriter3 {
|
|
|
42
42
|
this.style = style;
|
|
43
43
|
this.doDraw = doDraw;
|
|
44
44
|
|
|
45
|
+
this._checkParameterTypes(textAdaptor, coordinatesAdaptor, keyAdaptor, opacityAdaptor, angleAdaptor, xOffset, yOffset);
|
|
45
46
|
|
|
46
47
|
this.textAdaptor = textAdaptor;
|
|
47
48
|
this.coordinatesAdaptor = coordinatesAdaptor;
|
|
@@ -63,6 +64,16 @@ export class ContextTextWriter3 {
|
|
|
63
64
|
this.yOffset = yOffset;
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
_checkParameterTypes(textAdaptor, coordinatesAdaptor, keyAdaptor, opacityAdaptor, angleAdaptor, xOffset, yOffset) {
|
|
68
|
+
if (textAdaptor !== null) if (!(textAdaptor instanceof Function)) throw new Error("textAdaptor is not an instance of a Function");
|
|
69
|
+
if (coordinatesAdaptor !== null) if (!(coordinatesAdaptor instanceof Function)) throw new Error("coordinatesAdaptor is not an instance of a Function");
|
|
70
|
+
if (keyAdaptor !== null) if (!(keyAdaptor instanceof Function)) throw new Error("keyAdaptor is not an instance of a Function");
|
|
71
|
+
if (opacityAdaptor !== null) if (!(opacityAdaptor instanceof Function)) throw new Error("opacityAdaptor is not an instance of a Function");
|
|
72
|
+
if (angleAdaptor !== null) if (!(angleAdaptor instanceof Function)) throw new Error("angleAdaptor is not an instance of a Function");
|
|
73
|
+
if (typeof xOffset !== "number") throw new Error("xOffset type is not a number");
|
|
74
|
+
if (typeof yOffset !== "number") throw new Error("yOffset type is not a number");
|
|
75
|
+
}
|
|
76
|
+
|
|
66
77
|
setKeyAdaptor(adaptor) {
|
|
67
78
|
this.keyAdaptor = adaptor;
|
|
68
79
|
}
|