@pirireis/webglobeplugins 0.6.6 → 0.6.8
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 +28 -8
- package/circle-line-chain/plugin.js +20 -2
- package/package.json +1 -1
- package/util/check/index.js +0 -0
- package/util/check/typecheck.js +10 -0
- package/write-text/context-text3.js +11 -0
- package/write-text/util.js +12 -0
package/bearing-line/plugin.js
CHANGED
|
@@ -30,7 +30,7 @@ export default class Plugin {
|
|
|
30
30
|
/**
|
|
31
31
|
*
|
|
32
32
|
* @param {*} id
|
|
33
|
-
* @param {Map<[K ,ContextTextWriter]} textContextInjectionMap import { ContextTextWriter } from '@pirireis/webglobeplugins/write-text/context-text';
|
|
33
|
+
* @param {Map<[K ,{writer:ContextTextWriter, coordsAdaptor, textAdaptor}]} textContextInjectionMap import { ContextTextWriter } from '@pirireis/webglobeplugins/write-text/context-text';
|
|
34
34
|
*
|
|
35
35
|
*/
|
|
36
36
|
|
|
@@ -38,6 +38,7 @@ export default class Plugin {
|
|
|
38
38
|
this.id = id;
|
|
39
39
|
this._opacity = opacity;
|
|
40
40
|
this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
|
|
41
|
+
this._checkTextContextInjectionMap(textContextInjectionMap);
|
|
41
42
|
this._textContextInjectionMap = textContextInjectionMap;
|
|
42
43
|
this.drawVRM = drawVRM;
|
|
43
44
|
this.drawBearingLine = drawBearingLine;
|
|
@@ -63,6 +64,15 @@ export default class Plugin {
|
|
|
63
64
|
this.globe.DrawRender();
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
_checkTextContextInjectionMap(textContextInjectionMap) {
|
|
68
|
+
if (!(textContextInjectionMap instanceof Map)) throw new TypeError("textContextInjectionMap is not instance of Map");
|
|
69
|
+
textContextInjectionMap.forEach((v) => {
|
|
70
|
+
if (typeof v !== 'object') throw new TypeError("textContextInjectionMap format is wrong");
|
|
71
|
+
if (typeof v.coordsAdaptor !== 'function') throw new TypeError("textContextInjectionMap coordsAdaptor format is wrong");
|
|
72
|
+
if (typeof v.textAdaptor !== 'function') throw new TypeError("textContextInjectionMap textAdaptor format is wrong");
|
|
73
|
+
if (!(v.writer instanceof ContextTextWriter)) throw new TypeError("textContextInjectionMap writer is not instance of ContextTextWriter");
|
|
74
|
+
})
|
|
75
|
+
}
|
|
66
76
|
|
|
67
77
|
setDoDrawAngleRing(bool) {
|
|
68
78
|
if (bool === this.drawAngleRing) return;
|
|
@@ -225,7 +235,7 @@ export default class Plugin {
|
|
|
225
235
|
*/
|
|
226
236
|
insertBulk(items, textWriterInjectionSubSetIDs = []) {
|
|
227
237
|
const { globe, bufferOrchestrator, bufferManagersCompMap } = this;// angleTextContext, distanceTextContext,
|
|
228
|
-
const textWriterInjectionSubSets =
|
|
238
|
+
const textWriterInjectionSubSets = this._getTextWriterInjectionSubSet(textWriterInjectionSubSetIDs);
|
|
229
239
|
const data = []
|
|
230
240
|
for (let item of items) {
|
|
231
241
|
this._insertTexts(item, textWriterInjectionSubSets);
|
|
@@ -259,7 +269,7 @@ export default class Plugin {
|
|
|
259
269
|
* @param {Array<string>} textWriterInjectionSubSetIDs | textContextInjectionMap keys to be used for writing text.
|
|
260
270
|
*/
|
|
261
271
|
updateCoordinatesBulk(items, textWriterInjectionSubSetIDs = []) { //TODO
|
|
262
|
-
const injectionsSubSet =
|
|
272
|
+
const injectionsSubSet = this._getTextWriterInjectionSubSet(textWriterInjectionSubSetIDs);
|
|
263
273
|
const { globe, bufferOrchestrator, bufferManagersCompMap, } = this;
|
|
264
274
|
const data = []
|
|
265
275
|
for (let item of items) {
|
|
@@ -275,24 +285,23 @@ export default class Plugin {
|
|
|
275
285
|
/**
|
|
276
286
|
*
|
|
277
287
|
* @param {*} items some colums EXCEPT positional ones
|
|
278
|
-
* @param {
|
|
279
|
-
* @param {
|
|
288
|
+
* @param {string} propertyIDs
|
|
289
|
+
* @param {string} textWriterInjectionSubSetIDs
|
|
280
290
|
* 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.
|
|
281
291
|
*/
|
|
282
292
|
updatePartial(items, propertyIDs = [], textWriterInjectionSubSetIDs = []) { // textWriterInjectionSubSetIDs = []
|
|
283
293
|
if (propertyIDs.length === 0) console.warn("updatePartial is called with no target propertyIDs");
|
|
284
294
|
const { _textContextInjectionMap, bufferOrchestrator, bufferManagersCompMap } = this;
|
|
285
|
-
const writers =
|
|
295
|
+
const writers = this._getTextWriterInjectionSubSet(textWriterInjectionSubSetIDs); // TODO:filter out rgba? this might be a bug
|
|
286
296
|
for (let item of items) { this._insertTexts(item, writers) }
|
|
287
297
|
bufferOrchestrator.updateBulk(items, bufferManagersCompMap, propertyIDs);
|
|
288
298
|
// patch to update text opacity
|
|
289
299
|
for (const property of propertyIDs) {
|
|
290
300
|
if (property === "rgba") {
|
|
291
|
-
|
|
301
|
+
_textContextInjectionMap.forEach((v) => {
|
|
292
302
|
const { writer } = v;
|
|
293
303
|
writer.updateOpacityBulk(items, (e) => e.key, (e) => e.rgba[3]);
|
|
294
304
|
})
|
|
295
|
-
|
|
296
305
|
}
|
|
297
306
|
}
|
|
298
307
|
this.globe.DrawRender();
|
|
@@ -397,6 +406,17 @@ export default class Plugin {
|
|
|
397
406
|
});
|
|
398
407
|
}
|
|
399
408
|
|
|
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
|
+
}
|
|
400
420
|
}
|
|
401
421
|
|
|
402
422
|
|
|
@@ -3,6 +3,7 @@ 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
5
|
import { keyMethod } from "./util";
|
|
6
|
+
import { ContextTextWriter3 } from '../write-text/context-text3';
|
|
6
7
|
// TODO: Add update buffer and update text mehods on add, delete, update methods
|
|
7
8
|
|
|
8
9
|
|
|
@@ -45,6 +46,7 @@ export class CircleLineChainPlugin {
|
|
|
45
46
|
textDataPreAdaptor = null
|
|
46
47
|
} = {}) {
|
|
47
48
|
this.id = id;
|
|
49
|
+
this._checkTextContextWriterInjectionMap(textContextWriterInjectionMap);
|
|
48
50
|
this._textContextWriterInjectionMap = textContextWriterInjectionMap;
|
|
49
51
|
this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, properties) => v.__identity__));
|
|
50
52
|
this._opacity = 1;
|
|
@@ -62,6 +64,12 @@ export class CircleLineChainPlugin {
|
|
|
62
64
|
this._initOrchestrations()
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
_checkTextContextWriterInjectionMap(textContextWriterInjectionMap) {
|
|
68
|
+
if (!(textContextWriterInjectionMap instanceof Map)) throw new Error("textContextWriterInjectionMap is not an instance of Map");
|
|
69
|
+
textContextWriterInjectionMap.forEach((v) => {
|
|
70
|
+
if (!(v instanceof ContextTextWriter3)) throw new Error("textContextWriterInjectionMap element is not an instance of ContextTextWriter3");
|
|
71
|
+
});
|
|
72
|
+
}
|
|
65
73
|
|
|
66
74
|
_initOrchestrations() {
|
|
67
75
|
const { gl, globe } = this;
|
|
@@ -290,7 +298,6 @@ export class CircleLineChainPlugin {
|
|
|
290
298
|
chainKeysToReconstuct.push(chainKey);
|
|
291
299
|
});
|
|
292
300
|
this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
|
|
293
|
-
// if (textWriterIDs) this._updateTexts(chainKeysToReconstuct, textWriterIDs)
|
|
294
301
|
this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
|
|
295
302
|
this._reconstructChains(chainKeysToReconstuct);
|
|
296
303
|
this._updateTexts(chainKeysToReconstuct, textWriterIDs);
|
|
@@ -308,12 +315,23 @@ export class CircleLineChainPlugin {
|
|
|
308
315
|
// implicit
|
|
309
316
|
|
|
310
317
|
_updateTexts(chainKeys, textWriterIDs) {
|
|
311
|
-
|
|
318
|
+
if (textWriterIDs.length === 0) return;
|
|
319
|
+
const textWriters = this._getTextWriterInjectionSubSet(textWriterIDs)
|
|
312
320
|
chainKeys.forEach((chainKey) => {
|
|
313
321
|
this._chainListMap.textUpdate(chainKey, textWriters, this._textDataPreAdaptor);
|
|
314
322
|
})
|
|
315
323
|
}
|
|
316
324
|
|
|
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
|
+
}
|
|
317
335
|
|
|
318
336
|
|
|
319
337
|
_reconstructChains(chainKeys) {
|
package/package.json
CHANGED
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export const isHexColor = (hexColor) => /^#[0-9A-F]{6}$/i.test(hexColor);
|
|
4
|
+
export const isHexColorWithOpacity = (hexColor) => /^#[0-9A-F]{6}[0-9a-f]{0,2}$/i.test(hexColor);
|
|
5
|
+
|
|
6
|
+
export const doesOwnProperties = (properties, errorMessage) => (object) => {
|
|
7
|
+
properties.array.forEach(element => {
|
|
8
|
+
if (!Object.hasOwn(object, element)) throw new TypeError(errorMessage + ' ' + element);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
|