bruce-cesium 7.8.0 → 7.8.2
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/dist/bruce-cesium.es5.js +760 -346
- package/dist/bruce-cesium.es5.js.map +1 -1
- package/dist/bruce-cesium.umd.js +758 -344
- package/dist/bruce-cesium.umd.js.map +1 -1
- package/dist/lib/bruce-cesium.js +1 -1
- package/dist/lib/rendering/render-managers/common/entity-label.js +736 -342
- package/dist/lib/rendering/render-managers/common/entity-label.js.map +1 -1
- package/dist/lib/rendering/render-managers/common/point-clustering-core.js +24 -3
- package/dist/lib/rendering/render-managers/common/point-clustering-core.js.map +1 -1
- package/dist/types/bruce-cesium.d.ts +1 -1
- package/dist/types/rendering/render-managers/common/entity-label.d.ts +28 -3
- package/dist/types/rendering/render-managers/common/point-clustering-core.d.ts +8 -3
- package/package.json +1 -1
|
@@ -44,6 +44,14 @@ var EntityLabel;
|
|
|
44
44
|
const ICON_STACK_SCALE = 0.6;
|
|
45
45
|
// How far an angled leader runs sideways before the label starts.
|
|
46
46
|
const ANGLED_LEADER_RUN = 28;
|
|
47
|
+
// While labels move on screen, clusters are worked out afresh at most this often, and again once they settle.
|
|
48
|
+
const CLUSTER_MOVING_INTERVAL = 400;
|
|
49
|
+
// Milliseconds of each frame a fresh clustering may take; the rest of it runs on the next frames.
|
|
50
|
+
const CLUSTER_STEP_BUDGET = 4;
|
|
51
|
+
// How far a pin's white body reaches past the icon it wraps, before its tip.
|
|
52
|
+
const PIN_RIM = 7;
|
|
53
|
+
// A pin is drawn in one fixed look for now: a white body with a faint edge and a soft shadow.
|
|
54
|
+
const PIN_COLOR = "#ffffff";
|
|
47
55
|
// Clearance between a point or billboard glyph and the ring drawn around it.
|
|
48
56
|
const ICON_RING_PADDING = 4;
|
|
49
57
|
// Small points still get a ring as large as the default near ring.
|
|
@@ -362,6 +370,8 @@ var EntityLabel;
|
|
|
362
370
|
*/
|
|
363
371
|
class PlacementMemory {
|
|
364
372
|
constructor() {
|
|
373
|
+
// The last clusters worked out from scratch, by label id, for frames that may reuse them.
|
|
374
|
+
this.clusters = null;
|
|
365
375
|
this.previous = new Map();
|
|
366
376
|
this.nextOrder = 0;
|
|
367
377
|
}
|
|
@@ -477,6 +487,22 @@ var EntityLabel;
|
|
|
477
487
|
color.brighten(ICON_BACKGROUND_BLEND, new Cesium.Color());
|
|
478
488
|
return shade.withAlpha(alpha).toCssColorString();
|
|
479
489
|
}
|
|
490
|
+
/*
|
|
491
|
+
* An icon's look on a pin: one with no chip of its own takes the pin's colour, which its glyph then contrasts with.
|
|
492
|
+
*/
|
|
493
|
+
function pinLook(look) {
|
|
494
|
+
return look.iconBackground ? look : { ...look, iconBackground: PIN_COLOR };
|
|
495
|
+
}
|
|
496
|
+
/*
|
|
497
|
+
* Whether a label draws a pin: it needs an icon to wrap, and a photo keeps its own shape.
|
|
498
|
+
*/
|
|
499
|
+
function HasPin(options) {
|
|
500
|
+
return ((options === null || options === void 0 ? void 0 : options.leaderStyle) === "pin" &&
|
|
501
|
+
options.leader !== false &&
|
|
502
|
+
(options.presentation || "text") !== "text" &&
|
|
503
|
+
!options.iconPhoto);
|
|
504
|
+
}
|
|
505
|
+
EntityLabel.HasPin = HasPin;
|
|
480
506
|
function iconLook(options) {
|
|
481
507
|
return {
|
|
482
508
|
icon: options.icon || undefined,
|
|
@@ -499,20 +525,80 @@ var EntityLabel;
|
|
|
499
525
|
presentation === "text" ? null : iconLook(options)
|
|
500
526
|
]);
|
|
501
527
|
}
|
|
528
|
+
function summariseCluster(cluster) {
|
|
529
|
+
var _a, _b, _c;
|
|
530
|
+
let chosen = cluster.representative;
|
|
531
|
+
const iconic = (chosen.options.presentation || "text") !== "text";
|
|
532
|
+
// Members in the order they would win representation; the seed is the nearest.
|
|
533
|
+
let ordered = [chosen, ...cluster.members.filter(member => member !== chosen)];
|
|
534
|
+
if (iconic && chosen.options.cluster.representative !== "nearest") {
|
|
535
|
+
ordered = ordered.map((member, i) => ({ member, i, priority: EntityLabel.IconPriority(member.options) }))
|
|
536
|
+
.sort((a, b) => b.priority - a.priority || a.i - b.i).map(entry => entry.member);
|
|
537
|
+
chosen = ordered[0];
|
|
538
|
+
}
|
|
539
|
+
const summary = {
|
|
540
|
+
chosen: chosen.id,
|
|
541
|
+
members: cluster.members.map(frame => frame.id),
|
|
542
|
+
entityIds: Array.from(new Set(cluster.members.map(frame => frame.entityId).filter(Boolean)))
|
|
543
|
+
};
|
|
544
|
+
if (iconic && chosen.options.iconScale !== 0) {
|
|
545
|
+
const seen = new Set();
|
|
546
|
+
const icons = [];
|
|
547
|
+
for (const member of ordered) {
|
|
548
|
+
const look = iconLook(member.options);
|
|
549
|
+
const key = JSON.stringify(look);
|
|
550
|
+
if (seen.has(key)) {
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
seen.add(key);
|
|
554
|
+
if (member !== ordered[0])
|
|
555
|
+
icons.push(look);
|
|
556
|
+
if (seen.size >= ICON_STACK_LIMIT) {
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (icons.length)
|
|
561
|
+
summary.icons = icons;
|
|
562
|
+
}
|
|
563
|
+
if (chosen.options.presentation !== "icon") {
|
|
564
|
+
const values = new Set();
|
|
565
|
+
const stableMembers = [...cluster.members].sort((a, b) => (a.entityKey || a.entityId || a.id).localeCompare(b.entityKey || b.entityId || b.id));
|
|
566
|
+
for (const member of stableMembers) {
|
|
567
|
+
const value = ((_c = (_a = member.text) !== null && _a !== void 0 ? _a : (_b = member.options) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : "").replace(/\s+/g, " ").trim();
|
|
568
|
+
if (value) {
|
|
569
|
+
values.add(value);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (values.size > 1) {
|
|
573
|
+
// A value long enough to wrap fills the box on its own, so only one is listed.
|
|
574
|
+
const wrapped = stableMembers.some(member => { var _a, _b; return member.textWrapped && ((_b = (member.text || ((_a = member.options) === null || _a === void 0 ? void 0 : _a.text))) === null || _b === void 0 ? void 0 : _b.trim()); });
|
|
575
|
+
const limit = wrapped ? 1 : 2;
|
|
576
|
+
const rows = Array.from(values).slice(0, limit);
|
|
577
|
+
if (values.size > limit)
|
|
578
|
+
rows.push(`+${values.size - limit} more…`);
|
|
579
|
+
summary.text = rows.join("\n");
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return summary;
|
|
583
|
+
}
|
|
502
584
|
/*
|
|
503
|
-
*
|
|
585
|
+
* Frames in the order they win: priority first, then nearest, with every coordinate known.
|
|
504
586
|
*/
|
|
505
|
-
function
|
|
506
|
-
|
|
507
|
-
const frames = input.filter(frame => [frame.x, frame.y, frame.width, frame.height, frame.depth].every(Number.isFinite))
|
|
587
|
+
function sortFrames(input) {
|
|
588
|
+
return input.filter(frame => [frame.x, frame.y, frame.width, frame.height, frame.depth].every(Number.isFinite))
|
|
508
589
|
.sort((a, b) => (b.priority || 0) - (a.priority || 0) || a.depth - b.depth || a.id.localeCompare(b.id));
|
|
509
|
-
|
|
590
|
+
}
|
|
591
|
+
/*
|
|
592
|
+
* The frames clustering considers, by presentation, and the ones hidden as another label of the same entity.
|
|
593
|
+
*/
|
|
594
|
+
function clusterGroups(frames) {
|
|
595
|
+
var _a, _b;
|
|
510
596
|
const entityKeys = new Set();
|
|
511
597
|
const groups = new Map();
|
|
598
|
+
const duplicates = new Set();
|
|
512
599
|
for (const frame of frames) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
if (duplicate) {
|
|
600
|
+
if (frame.entityKey && entityKeys.has(frame.entityKey)) {
|
|
601
|
+
duplicates.add(frame.id);
|
|
516
602
|
continue;
|
|
517
603
|
}
|
|
518
604
|
if (frame.entityKey)
|
|
@@ -527,6 +613,13 @@ var EntityLabel;
|
|
|
527
613
|
}
|
|
528
614
|
groups.get(key).push(frame);
|
|
529
615
|
}
|
|
616
|
+
return { groups, duplicates };
|
|
617
|
+
}
|
|
618
|
+
/*
|
|
619
|
+
* Works clusters out from scratch, as steps a caller can spread over frames or run straight through.
|
|
620
|
+
*/
|
|
621
|
+
function* clusterInSteps(groups, every = 32) {
|
|
622
|
+
const clustered = [];
|
|
530
623
|
for (const group of groups.values()) {
|
|
531
624
|
// Summary and badge dimensions are output, never the next frame's membership input.
|
|
532
625
|
const candidates = group.map(frame => frame.extendedGeometry && frame.canFlip &&
|
|
@@ -540,70 +633,76 @@ var EntityLabel;
|
|
|
540
633
|
rank.set(frame.id, i);
|
|
541
634
|
looks.set(frame.id, clusterLook(frame.options));
|
|
542
635
|
});
|
|
543
|
-
const clusters = (0, point_clustering_core_1.
|
|
636
|
+
const clusters = yield* (0, point_clustering_core_1.ClusterItemsInSteps)({
|
|
544
637
|
items: candidates,
|
|
545
638
|
id: frame => frame.id,
|
|
546
639
|
minSize: group[0].options.cluster.minSize,
|
|
547
|
-
neighbours: frame => {
|
|
640
|
+
neighbours: (frame, free) => {
|
|
548
641
|
var _a;
|
|
549
|
-
|
|
550
|
-
|
|
642
|
+
// Labels an earlier cluster took cannot join, so they are dropped before the pairwise checks.
|
|
643
|
+
const nearby = index.Query(frame, (_a = frame.options.cluster.pixelRange) !== null && _a !== void 0 ? _a : (frame.options.presentation === "icon" ? 24 : 8))
|
|
644
|
+
.filter(other => other === frame || free(other))
|
|
645
|
+
.sort((a, b) => rank.get(a.id) - rank.get(b.id));
|
|
646
|
+
// A pin stands for one thing, so it clusters only with pins that look the same.
|
|
647
|
+
const group = (other) => HasPin(other.options) ? `look:${looks.get(other.id)}` : other.group || "";
|
|
648
|
+
return compatibleMembers(frame, nearby, group, other => looks.get(other.id));
|
|
649
|
+
}
|
|
650
|
+
}, every);
|
|
651
|
+
clusters.forEach(cluster => clustered.push({ representative: cluster.representative.id, members: cluster.members.map(member => member.id) }));
|
|
652
|
+
}
|
|
653
|
+
return clustered;
|
|
654
|
+
}
|
|
655
|
+
/*
|
|
656
|
+
* Runs a clustering job to the end at once.
|
|
657
|
+
*/
|
|
658
|
+
function finishClustering(steps) {
|
|
659
|
+
let next = steps.next();
|
|
660
|
+
while (!next.done) {
|
|
661
|
+
next = steps.next();
|
|
662
|
+
}
|
|
663
|
+
return next.value;
|
|
664
|
+
}
|
|
665
|
+
function Layout(input, memory = new PlacementMemory(), reuseClusters = false) {
|
|
666
|
+
var _a, _b, _c;
|
|
667
|
+
const frames = sortFrames(input);
|
|
668
|
+
const { groups, duplicates } = clusterGroups(frames);
|
|
669
|
+
const result = new Map();
|
|
670
|
+
for (const frame of frames) {
|
|
671
|
+
result.set(frame.id, { frame, visible: !duplicates.has(frame.id), opacity: frame.opacity, zIndex: 0, members: [], entityIds: frame.entityId ? [frame.entityId] : [] });
|
|
672
|
+
}
|
|
673
|
+
if (!reuseClusters || !memory.clusters) {
|
|
674
|
+
memory.clusters = finishClustering(clusterInSteps(groups, Infinity));
|
|
675
|
+
}
|
|
676
|
+
for (const group of groups.values()) {
|
|
677
|
+
// The kept membership, less anything gone, hovered or moved out of the group since.
|
|
678
|
+
const byId = new Map(group.map(frame => [frame.id, frame]));
|
|
679
|
+
const minSize = Math.max(2, (_a = group[0].options.cluster.minSize) !== null && _a !== void 0 ? _a : 2);
|
|
680
|
+
const clusters = memory.clusters.map(entry => {
|
|
681
|
+
var _a;
|
|
682
|
+
const members = entry.members.map(id => byId.get(id)).filter(Boolean);
|
|
683
|
+
if (members.length < minSize) {
|
|
684
|
+
return null;
|
|
551
685
|
}
|
|
552
|
-
|
|
686
|
+
return { entry, whole: members.length === entry.members.length, representative: (_a = byId.get(entry.representative)) !== null && _a !== void 0 ? _a : members[0], members };
|
|
687
|
+
}).filter(Boolean);
|
|
553
688
|
for (const cluster of clusters) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
if (seen.has(key)) {
|
|
572
|
-
continue;
|
|
573
|
-
}
|
|
574
|
-
seen.add(key);
|
|
575
|
-
if (member !== ordered[0])
|
|
576
|
-
icons.push(look);
|
|
577
|
-
if (seen.size >= ICON_STACK_LIMIT) {
|
|
578
|
-
break;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
if (icons.length)
|
|
582
|
-
representative.icons = icons;
|
|
583
|
-
}
|
|
584
|
-
representative.entityIds = Array.from(new Set(cluster.members.map(frame => frame.entityId).filter(Boolean)));
|
|
585
|
-
if (chosen.options.presentation !== "icon") {
|
|
586
|
-
const values = new Set();
|
|
587
|
-
const stableMembers = [...cluster.members].sort((a, b) => (a.entityKey || a.entityId || a.id).localeCompare(b.entityKey || b.entityId || b.id));
|
|
588
|
-
for (const member of stableMembers) {
|
|
589
|
-
const value = ((_e = (_c = member.text) !== null && _c !== void 0 ? _c : (_d = member.options) === null || _d === void 0 ? void 0 : _d.text) !== null && _e !== void 0 ? _e : "").replace(/\s+/g, " ").trim();
|
|
590
|
-
if (value) {
|
|
591
|
-
values.add(value);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
if (values.size > 1) {
|
|
595
|
-
// A value long enough to wrap fills the box on its own, so only one is listed.
|
|
596
|
-
const wrapped = stableMembers.some(member => { var _a, _b; return member.textWrapped && ((_b = (member.text || ((_a = member.options) === null || _a === void 0 ? void 0 : _a.text))) === null || _b === void 0 ? void 0 : _b.trim()); });
|
|
597
|
-
const limit = wrapped ? 1 : 2;
|
|
598
|
-
const rows = Array.from(values).slice(0, limit);
|
|
599
|
-
if (values.size > limit)
|
|
600
|
-
rows.push(`+${values.size - limit} more…`);
|
|
601
|
-
representative.text = rows.join("\n");
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
for (const frame of cluster.members) {
|
|
605
|
-
if (frame !== chosen)
|
|
606
|
-
result.get(frame.id).visible = false;
|
|
689
|
+
// A cluster that kept every member keeps its summary, worked out once, sparing a pass over its members.
|
|
690
|
+
let summary = cluster.whole ? cluster.entry.summary : undefined;
|
|
691
|
+
if (!summary) {
|
|
692
|
+
summary = summariseCluster(cluster);
|
|
693
|
+
if (cluster.whole)
|
|
694
|
+
cluster.entry.summary = summary;
|
|
695
|
+
}
|
|
696
|
+
const representative = result.get(summary.chosen);
|
|
697
|
+
representative.members = summary.members;
|
|
698
|
+
if (summary.icons)
|
|
699
|
+
representative.icons = summary.icons;
|
|
700
|
+
representative.entityIds = summary.entityIds;
|
|
701
|
+
if (summary.text != null)
|
|
702
|
+
representative.text = summary.text;
|
|
703
|
+
for (const id of summary.members) {
|
|
704
|
+
if (id !== summary.chosen)
|
|
705
|
+
result.get(id).visible = false;
|
|
607
706
|
}
|
|
608
707
|
}
|
|
609
708
|
}
|
|
@@ -622,7 +721,7 @@ var EntityLabel;
|
|
|
622
721
|
const box = { ...frame, x: frame.x + .01, y: frame.y + .01, width: Math.max(0, frame.width - .02), height: Math.max(0, frame.height - .02) };
|
|
623
722
|
const overlap = foreground.HasOverlap(box) || foregroundLeaders.HasOverlap(box) || Boolean(stem && foreground.HasOverlap(stem));
|
|
624
723
|
if (overlap) {
|
|
625
|
-
placement.opacity *= Math.max(0, Math.min(1, (
|
|
724
|
+
placement.opacity *= Math.max(0, Math.min(1, (_c = (_b = frame.options) === null || _b === void 0 ? void 0 : _b.overlapOpacity) !== null && _c !== void 0 ? _c : 0.25));
|
|
626
725
|
}
|
|
627
726
|
;
|
|
628
727
|
placement.zIndex = zIndex--;
|
|
@@ -643,21 +742,23 @@ var EntityLabel;
|
|
|
643
742
|
const accepted = [seed];
|
|
644
743
|
const byGroup = new Map([[group(seed), 1]]);
|
|
645
744
|
const byLook = new Map([[look(seed), 1]]);
|
|
646
|
-
|
|
745
|
+
// Joined with a character no group id or look holds, not serialised, since this runs per neighbour.
|
|
746
|
+
const both = (itemGroup, itemLook) => `${itemGroup}\u0000${itemLook}`;
|
|
747
|
+
const byBoth = new Map([[both(group(seed), look(seed)), 1]]);
|
|
647
748
|
for (const item of nearby) {
|
|
648
749
|
if (item === seed) {
|
|
649
750
|
continue;
|
|
650
751
|
}
|
|
651
|
-
const itemGroup = group(item), itemLook = look(item),
|
|
752
|
+
const itemGroup = group(item), itemLook = look(item), key = both(itemGroup, itemLook);
|
|
652
753
|
// Accepted members in another group with another look are the ones this item may not sit beside.
|
|
653
|
-
const conflicting = accepted.length - (byGroup.get(itemGroup) || 0) - (byLook.get(itemLook) || 0) + (byBoth.get(
|
|
754
|
+
const conflicting = accepted.length - (byGroup.get(itemGroup) || 0) - (byLook.get(itemLook) || 0) + (byBoth.get(key) || 0);
|
|
654
755
|
if (conflicting > 0) {
|
|
655
756
|
continue;
|
|
656
757
|
}
|
|
657
758
|
accepted.push(item);
|
|
658
759
|
byGroup.set(itemGroup, (byGroup.get(itemGroup) || 0) + 1);
|
|
659
760
|
byLook.set(itemLook, (byLook.get(itemLook) || 0) + 1);
|
|
660
|
-
byBoth.set(
|
|
761
|
+
byBoth.set(key, (byBoth.get(key) || 0) + 1);
|
|
661
762
|
}
|
|
662
763
|
return accepted;
|
|
663
764
|
}
|
|
@@ -688,10 +789,20 @@ var EntityLabel;
|
|
|
688
789
|
this.viewer = viewer;
|
|
689
790
|
this.element = document.createElement("div");
|
|
690
791
|
this.coordinates = { x: 0, y: 0, scaleX: 1, scaleY: 1 };
|
|
792
|
+
// The canvas size, read once a frame: reading the canvas after placing a label lays the page out again.
|
|
793
|
+
this.viewport = { width: 0, height: 0 };
|
|
691
794
|
this.participants = new Set();
|
|
692
795
|
// Participants whose failure has been logged, so a label that throws every frame logs once.
|
|
693
796
|
this.failed = new WeakSet();
|
|
694
797
|
this.placementMemory = new PlacementMemory();
|
|
798
|
+
// What the clusters were last worked out from: the labels taking part and where they sat, and when.
|
|
799
|
+
this.clustered = null;
|
|
800
|
+
// Labels added or removed, which can change any cluster's look or membership.
|
|
801
|
+
this.clustersDirty = true;
|
|
802
|
+
// A fresh clustering spread over frames, while the last one stays on show.
|
|
803
|
+
this.clusterJob = null;
|
|
804
|
+
// Labels hidden in a cluster last frame, with the frame they were laid out from, for reused clusters to skip.
|
|
805
|
+
this.sleeping = new Map();
|
|
695
806
|
this.modelBoxes = new ModelBoxes();
|
|
696
807
|
this.forwardingWheel = false;
|
|
697
808
|
this.pendingDrag = null;
|
|
@@ -868,9 +979,12 @@ var EntityLabel;
|
|
|
868
979
|
}
|
|
869
980
|
Add(participant) {
|
|
870
981
|
this.participants.add(participant);
|
|
982
|
+
this.clustersDirty = true;
|
|
871
983
|
this.viewer.scene.requestRender();
|
|
872
984
|
return () => {
|
|
873
985
|
this.participants.delete(participant);
|
|
986
|
+
this.sleeping.delete(participant);
|
|
987
|
+
this.clustersDirty = true;
|
|
874
988
|
if (!this.participants.size) {
|
|
875
989
|
this.remove();
|
|
876
990
|
this.element.removeEventListener("wheel", this.ForwardWheel);
|
|
@@ -921,8 +1035,9 @@ var EntityLabel;
|
|
|
921
1035
|
}
|
|
922
1036
|
}
|
|
923
1037
|
Update() {
|
|
924
|
-
var _a, _b;
|
|
1038
|
+
var _a, _b, _c;
|
|
925
1039
|
this.coordinates = this.MeasureCoordinates();
|
|
1040
|
+
this.viewport = { width: this.viewer.canvas.clientWidth, height: this.viewer.canvas.clientHeight };
|
|
926
1041
|
this.UpdateHorizon();
|
|
927
1042
|
const rect = (_b = (_a = this.viewer.canvas).getBoundingClientRect) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
928
1043
|
const pointer = this.pointerClient;
|
|
@@ -938,21 +1053,77 @@ var EntityLabel;
|
|
|
938
1053
|
console.error("EntityLabel: model boxes failed to resolve.", e);
|
|
939
1054
|
}
|
|
940
1055
|
// This runs inside Cesium's frame, where one throwing label would stop rendering for the whole scene.
|
|
1056
|
+
const project = (participant) => {
|
|
1057
|
+
try {
|
|
1058
|
+
return participant.project();
|
|
1059
|
+
}
|
|
1060
|
+
catch (e) {
|
|
1061
|
+
this.logFailure(participant, e);
|
|
1062
|
+
return null;
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
// A label hidden in a cluster needs no position while its cluster is reused, which is most frames.
|
|
1066
|
+
const mayReuse = Boolean(this.clustered) && !this.clustersDirty && Date.now() - this.clustered.at < CLUSTER_MOVING_INTERVAL;
|
|
941
1067
|
const projected = new Map();
|
|
942
1068
|
for (const participant of this.participants) {
|
|
943
|
-
|
|
1069
|
+
const asleep = mayReuse && !((_c = participant.wake) === null || _c === void 0 ? void 0 : _c.call(participant)) ? this.sleeping.get(participant) : undefined;
|
|
1070
|
+
projected.set(participant, asleep !== null && asleep !== void 0 ? asleep : project(participant));
|
|
1071
|
+
}
|
|
1072
|
+
let frames = Array.from(projected.values()).filter(Boolean);
|
|
1073
|
+
const decision = this.DecideClusters(frames);
|
|
1074
|
+
if (decision !== "reuse" && mayReuse) {
|
|
1075
|
+
// Clusters are worked out from where every label is now, sleepers included.
|
|
1076
|
+
for (const participant of this.participants) {
|
|
1077
|
+
if (this.sleeping.has(participant))
|
|
1078
|
+
projected.set(participant, project(participant));
|
|
1079
|
+
}
|
|
1080
|
+
frames = Array.from(projected.values()).filter(Boolean);
|
|
1081
|
+
}
|
|
1082
|
+
if (decision === "refresh") {
|
|
1083
|
+
this.clusterJob = clusterInSteps(clusterGroups(sortFrames(frames)).groups);
|
|
1084
|
+
}
|
|
1085
|
+
this.StepClusters();
|
|
1086
|
+
const layout = Layout(frames, this.placementMemory, decision !== "now");
|
|
1087
|
+
const placements = new Map(layout.map(item => [item.frame.id, item]));
|
|
1088
|
+
const participantsById = new Map();
|
|
1089
|
+
for (const [participant, frame] of projected) {
|
|
1090
|
+
if (frame)
|
|
1091
|
+
participantsById.set(frame.id, participant);
|
|
1092
|
+
}
|
|
1093
|
+
this.sleeping = new Map();
|
|
1094
|
+
for (const placement of layout) {
|
|
1095
|
+
for (const id of placement.members) {
|
|
1096
|
+
const participant = id !== placement.frame.id ? participantsById.get(id) : undefined;
|
|
1097
|
+
if (participant)
|
|
1098
|
+
this.sleeping.set(participant, projected.get(participant));
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
// Writes, then reads, then writes, each across all labels; interleaved, each read lays them out again.
|
|
1102
|
+
const measures = [];
|
|
1103
|
+
for (const [participant, frame] of projected) {
|
|
944
1104
|
try {
|
|
945
|
-
|
|
1105
|
+
const measure = participant.apply(frame ? placements.get(frame.id) : undefined);
|
|
1106
|
+
if (measure)
|
|
1107
|
+
measures.push([participant, measure]);
|
|
946
1108
|
}
|
|
947
1109
|
catch (e) {
|
|
948
1110
|
this.logFailure(participant, e);
|
|
949
1111
|
}
|
|
950
|
-
projected.set(participant, frame);
|
|
951
1112
|
}
|
|
952
|
-
const
|
|
953
|
-
for (const [participant,
|
|
1113
|
+
const places = [];
|
|
1114
|
+
for (const [participant, measure] of measures) {
|
|
954
1115
|
try {
|
|
955
|
-
|
|
1116
|
+
const place = measure();
|
|
1117
|
+
if (place)
|
|
1118
|
+
places.push([participant, place]);
|
|
1119
|
+
}
|
|
1120
|
+
catch (e) {
|
|
1121
|
+
this.logFailure(participant, e);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
for (const [participant, place] of places) {
|
|
1125
|
+
try {
|
|
1126
|
+
place();
|
|
956
1127
|
}
|
|
957
1128
|
catch (e) {
|
|
958
1129
|
this.logFailure(participant, e);
|
|
@@ -965,6 +1136,55 @@ var EntityLabel;
|
|
|
965
1136
|
console.error("EntityLabel: model boxes failed to draw.", e);
|
|
966
1137
|
}
|
|
967
1138
|
}
|
|
1139
|
+
/*
|
|
1140
|
+
* How this frame gets its clusters: kept from last time, refreshed by a job over frames, or worked out now.
|
|
1141
|
+
* They are kept while no clustering label has moved, and while labels move (camera or entities) until a moment
|
|
1142
|
+
* old or while a refresh is under way. Labels coming or going, or none clustered yet, work them out now.
|
|
1143
|
+
*/
|
|
1144
|
+
DecideClusters(frames) {
|
|
1145
|
+
// Where each clustering label sits, to a few pixels, so drawing alone never counts as movement.
|
|
1146
|
+
const signature = frames
|
|
1147
|
+
.filter(frame => { var _a, _b; return ((_b = (_a = frame.options) === null || _a === void 0 ? void 0 : _a.cluster) === null || _b === void 0 ? void 0 : _b.enabled) && !(frame.priority > 0); })
|
|
1148
|
+
.map(frame => `${frame.id}@${Math.round(frame.x / 4)},${Math.round(frame.y / 4)}`)
|
|
1149
|
+
.join("|");
|
|
1150
|
+
const now = Date.now();
|
|
1151
|
+
if (!this.clustered || this.clustersDirty) {
|
|
1152
|
+
this.clusterJob = null;
|
|
1153
|
+
this.clustered = { signature, at: now };
|
|
1154
|
+
this.clustersDirty = false;
|
|
1155
|
+
return "now";
|
|
1156
|
+
}
|
|
1157
|
+
if (this.clustered.signature === signature) {
|
|
1158
|
+
return "reuse";
|
|
1159
|
+
}
|
|
1160
|
+
if (this.clusterJob || now - this.clustered.at < CLUSTER_MOVING_INTERVAL) {
|
|
1161
|
+
// Another frame is due either way, so the scene gets its fresh clusters once it settles.
|
|
1162
|
+
this.viewer.scene.requestRender();
|
|
1163
|
+
return "reuse";
|
|
1164
|
+
}
|
|
1165
|
+
this.clustered = { signature, at: now };
|
|
1166
|
+
return "refresh";
|
|
1167
|
+
}
|
|
1168
|
+
/*
|
|
1169
|
+
* Advances a spread clustering for this frame's share of time, handing its result over once it finishes.
|
|
1170
|
+
*/
|
|
1171
|
+
StepClusters() {
|
|
1172
|
+
if (!this.clusterJob) {
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
const deadline = performance.now() + CLUSTER_STEP_BUDGET;
|
|
1176
|
+
let next = this.clusterJob.next();
|
|
1177
|
+
while (!next.done && performance.now() < deadline) {
|
|
1178
|
+
next = this.clusterJob.next();
|
|
1179
|
+
}
|
|
1180
|
+
if (next.done) {
|
|
1181
|
+
this.placementMemory.clusters = next.value;
|
|
1182
|
+
this.clusterJob = null;
|
|
1183
|
+
}
|
|
1184
|
+
else {
|
|
1185
|
+
this.viewer.scene.requestRender();
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
968
1188
|
logFailure(participant, error) {
|
|
969
1189
|
if (this.failed.has(participant)) {
|
|
970
1190
|
return;
|
|
@@ -2269,7 +2489,8 @@ var EntityLabel;
|
|
|
2269
2489
|
target.addEventListener(type, event => event.stopPropagation());
|
|
2270
2490
|
}
|
|
2271
2491
|
};
|
|
2272
|
-
const
|
|
2492
|
+
const pin = HasPin(look);
|
|
2493
|
+
const normalLeader = (_m = look.leader) !== null && _m !== void 0 ? _m : (presentation === "text" || pin);
|
|
2273
2494
|
const angled = this.options.leaderStyle === "angled";
|
|
2274
2495
|
let leader = normalLeader;
|
|
2275
2496
|
const content = document.createElement("span");
|
|
@@ -2280,6 +2501,8 @@ var EntityLabel;
|
|
|
2280
2501
|
let iconElement;
|
|
2281
2502
|
let iconContainer;
|
|
2282
2503
|
let fitIconBackground;
|
|
2504
|
+
let pinHolder;
|
|
2505
|
+
let pinBody;
|
|
2283
2506
|
let iconStack;
|
|
2284
2507
|
let stackedFits = [];
|
|
2285
2508
|
let displayedStack = "[]";
|
|
@@ -2300,7 +2523,8 @@ var EntityLabel;
|
|
|
2300
2523
|
content.style.flexDirection = shape === "rect" ? "column-reverse" : "";
|
|
2301
2524
|
};
|
|
2302
2525
|
if (presentation !== "text") {
|
|
2303
|
-
|
|
2526
|
+
// Without a chip of its own the icon sits on the pin's white body, so its colour is inferred from that.
|
|
2527
|
+
const built = this.buildIcon(pin ? pinLook(look) : look, counter, placePhoto);
|
|
2304
2528
|
startPhoto = built.start;
|
|
2305
2529
|
const icon = iconElement = built.icon;
|
|
2306
2530
|
fitIconBackground = built.fit;
|
|
@@ -2325,6 +2549,18 @@ var EntityLabel;
|
|
|
2325
2549
|
iconStack.style.cssText = "display:none;gap:2px;align-items:center;justify-items:center;flex:none;";
|
|
2326
2550
|
makeClickable(iconStack);
|
|
2327
2551
|
iconContainer.append(iconStack, icon);
|
|
2552
|
+
if (pin) {
|
|
2553
|
+
pinHolder = document.createElement("span");
|
|
2554
|
+
pinHolder.className = "entity-label-pin";
|
|
2555
|
+
pinHolder.style.cssText = "position:absolute;left:50%;top:50%;z-index:-1;pointer-events:none;";
|
|
2556
|
+
pinBody = document.createElement("span");
|
|
2557
|
+
pinBody.style.cssText = `position:absolute;inset:0;background:${PIN_COLOR};border:1px solid rgba(0, 0, 0, 0.14);` +
|
|
2558
|
+
"box-sizing:border-box;border-radius:50% 50% 0 50%;";
|
|
2559
|
+
pinHolder.appendChild(pinBody);
|
|
2560
|
+
iconContainer.prepend(pinHolder);
|
|
2561
|
+
// Text beside or above keeps its usual gap from the body rather than from the icon inside it.
|
|
2562
|
+
content.style.gap = `${6 + PIN_RIM}px`;
|
|
2563
|
+
}
|
|
2328
2564
|
content.appendChild(iconContainer);
|
|
2329
2565
|
}
|
|
2330
2566
|
if (presentation !== "icon") {
|
|
@@ -2398,7 +2634,10 @@ var EntityLabel;
|
|
|
2398
2634
|
border-radius: 9px;
|
|
2399
2635
|
color: #ffffff;
|
|
2400
2636
|
text-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
|
|
2637
|
+
will-change: transform;
|
|
2401
2638
|
`);
|
|
2639
|
+
// Each label, leader and ring gets its own compositor layer: in one shared layer, moving any of them
|
|
2640
|
+
// repainted all of them, shadows included, on every camera move.
|
|
2402
2641
|
this.label = ele;
|
|
2403
2642
|
ele.style.width = "max-content";
|
|
2404
2643
|
layer.element.appendChild(ele);
|
|
@@ -2417,6 +2656,7 @@ var EntityLabel;
|
|
|
2417
2656
|
width: 2px;
|
|
2418
2657
|
background: rgba(255, 255, 255, 0.8);
|
|
2419
2658
|
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
|
|
2659
|
+
will-change: transform;
|
|
2420
2660
|
`);
|
|
2421
2661
|
this.line = lineEle;
|
|
2422
2662
|
lineEle.className = "entity-label-leader";
|
|
@@ -2434,6 +2674,7 @@ var EntityLabel;
|
|
|
2434
2674
|
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
|
|
2435
2675
|
top: -2px;
|
|
2436
2676
|
left: -2px;
|
|
2677
|
+
will-change: transform;
|
|
2437
2678
|
`);
|
|
2438
2679
|
lineEleNode.className = "entity-label-anchor";
|
|
2439
2680
|
// SVG preserves fractional strokes in scaled containers where CSS borders round to pixels.
|
|
@@ -2466,13 +2707,13 @@ var EntityLabel;
|
|
|
2466
2707
|
}
|
|
2467
2708
|
const fitLeader = (anchorX, anchorY, desired, width, height, radius = 0) => {
|
|
2468
2709
|
const above = Math.max(0, anchorY - height);
|
|
2469
|
-
const below = Math.max(0,
|
|
2710
|
+
const below = Math.max(0, layer.viewport.height - anchorY - height);
|
|
2470
2711
|
// Keep a short visible stem before switching sides; never aim it at the cursor or a box corner.
|
|
2471
2712
|
const upwards = above >= Math.max(radius ? radius + 4 : 0, Math.min(8, desired)) || above >= below;
|
|
2472
2713
|
const length = Math.min(desired, upwards ? above : below);
|
|
2473
2714
|
const endY = anchorY + (upwards ? -length : length);
|
|
2474
2715
|
return {
|
|
2475
|
-
x: Math.max(0, Math.min(anchorX,
|
|
2716
|
+
x: Math.max(0, Math.min(anchorX, layer.viewport.width - width)),
|
|
2476
2717
|
y: upwards ? endY - height : endY, endY
|
|
2477
2718
|
};
|
|
2478
2719
|
};
|
|
@@ -2481,20 +2722,50 @@ var EntityLabel;
|
|
|
2481
2722
|
* so the stem rises to the label's middle and then runs out to whichever side has the room.
|
|
2482
2723
|
*/
|
|
2483
2724
|
const fitAngledLeader = (anchorX, anchorY, desired, width, height, radius = 0) => {
|
|
2484
|
-
const canvas =
|
|
2725
|
+
const canvas = layer.viewport;
|
|
2485
2726
|
const above = Math.max(0, anchorY - height / 2);
|
|
2486
|
-
const below = Math.max(0, canvas.
|
|
2727
|
+
const below = Math.max(0, canvas.height - anchorY - height / 2);
|
|
2487
2728
|
const upwards = above >= Math.max(radius ? radius + 4 : 0, Math.min(8, desired)) || above >= below;
|
|
2488
2729
|
const length = Math.min(desired, upwards ? above : below);
|
|
2489
2730
|
const endY = anchorY + (upwards ? -length : length);
|
|
2490
2731
|
const run = Math.max(ANGLED_LEADER_RUN, radius + 4);
|
|
2491
|
-
const rightwards = anchorX + run + width <= canvas.
|
|
2732
|
+
const rightwards = anchorX + run + width <= canvas.width || anchorX - run - width < 0;
|
|
2492
2733
|
return {
|
|
2493
|
-
x: Math.max(0, Math.min(rightwards ? anchorX + run : anchorX - run - width, canvas.
|
|
2494
|
-
y: Math.max(0, Math.min(endY - height / 2, canvas.
|
|
2734
|
+
x: Math.max(0, Math.min(rightwards ? anchorX + run : anchorX - run - width, canvas.width - width)),
|
|
2735
|
+
y: Math.max(0, Math.min(endY - height / 2, canvas.height - height)), endY,
|
|
2495
2736
|
run, side: (rightwards ? "right" : "left")
|
|
2496
2737
|
};
|
|
2497
2738
|
};
|
|
2739
|
+
/*
|
|
2740
|
+
* Where the icon sits in the label, and how far the pin's tip reaches from its centre, in layout pixels.
|
|
2741
|
+
* Measured from the icon's container, so a cluster's icon stack is wrapped the same way as a lone icon.
|
|
2742
|
+
*/
|
|
2743
|
+
const measurePin = () => {
|
|
2744
|
+
const scale = layer.coordinates.scaleX;
|
|
2745
|
+
const radius = Math.max(iconContainer.offsetWidth, iconContainer.offsetHeight) / 2 + PIN_RIM;
|
|
2746
|
+
return {
|
|
2747
|
+
x: (iconContainer.offsetLeft + iconContainer.offsetWidth / 2) / scale,
|
|
2748
|
+
y: (iconContainer.offsetTop + iconContainer.offsetHeight / 2) / layer.coordinates.scaleY,
|
|
2749
|
+
radius: radius / scale,
|
|
2750
|
+
// The body's one square corner, half a diagonal from its centre.
|
|
2751
|
+
tip: radius * Math.SQRT2 / scale
|
|
2752
|
+
};
|
|
2753
|
+
};
|
|
2754
|
+
/*
|
|
2755
|
+
* A pin stands over its anchor with the icon centred on it, and hangs below when there is no room above.
|
|
2756
|
+
* Off to the side it is only clamped back on screen, and its tip turns to keep pointing at the anchor.
|
|
2757
|
+
*/
|
|
2758
|
+
const fitPin = (anchorX, anchorY, stem, width, height, shape) => {
|
|
2759
|
+
const canvas = layer.viewport;
|
|
2760
|
+
const reach = stem + shape.tip;
|
|
2761
|
+
const above = anchorY - reach - shape.y;
|
|
2762
|
+
const below = anchorY + reach - shape.y;
|
|
2763
|
+
const upwards = above >= 0 || (below + height > canvas.height && anchorY >= canvas.height - anchorY);
|
|
2764
|
+
return {
|
|
2765
|
+
x: Math.max(0, Math.min(anchorX - shape.x, canvas.width - width)),
|
|
2766
|
+
y: upwards ? above : below
|
|
2767
|
+
};
|
|
2768
|
+
};
|
|
2498
2769
|
/*
|
|
2499
2770
|
* The on-screen centre and half-size of a point or billboard glyph, relative to its projected position.
|
|
2500
2771
|
* Read every frame, since styling and selection can rescale a billboard in place.
|
|
@@ -2609,9 +2880,46 @@ var EntityLabel;
|
|
|
2609
2880
|
this.viewer.scene.requestRender();
|
|
2610
2881
|
}).finally(settle);
|
|
2611
2882
|
}
|
|
2883
|
+
/*
|
|
2884
|
+
* The label's size when last laid out. A label hidden in a cluster leaves layout altogether, so a
|
|
2885
|
+
* frame reads its size from here; a shown one refreshes it when it changes, a new one on its first frame.
|
|
2886
|
+
*/
|
|
2887
|
+
let size = null;
|
|
2888
|
+
const measureSize = () => {
|
|
2889
|
+
size = {
|
|
2890
|
+
width: ele.offsetWidth,
|
|
2891
|
+
height: ele.offsetHeight,
|
|
2892
|
+
textWidth: (sourceText === null || sourceText === void 0 ? void 0 : sourceText.offsetWidth) || 0,
|
|
2893
|
+
textHeight: (sourceText === null || sourceText === void 0 ? void 0 : sourceText.offsetHeight) || 0,
|
|
2894
|
+
iconWidth: (iconElement === null || iconElement === void 0 ? void 0 : iconElement.offsetWidth) || 0,
|
|
2895
|
+
iconHeight: (iconElement === null || iconElement === void 0 ? void 0 : iconElement.offsetHeight) || 0,
|
|
2896
|
+
naturalTextWidth: (sourceNaturalText === null || sourceNaturalText === void 0 ? void 0 : sourceNaturalText.offsetWidth) || 0,
|
|
2897
|
+
pin: pin ? measurePin() : undefined
|
|
2898
|
+
};
|
|
2899
|
+
};
|
|
2900
|
+
// Whether the label was out of layout last frame, so staying hidden writes nothing.
|
|
2901
|
+
let hiddenLast = false;
|
|
2902
|
+
// Set by this frame's writes that change the label's size, so it is measured before it is placed.
|
|
2903
|
+
let sizeStale = true;
|
|
2904
|
+
// Set when the size changed on its own; a shown label reads it at the start of the next frame, while layout
|
|
2905
|
+
// is still clean, rather than forcing a layout mid-frame.
|
|
2906
|
+
let resizedSince = false;
|
|
2907
|
+
// The cluster badge's own size beside its icon, read with the label's.
|
|
2908
|
+
let badge = null;
|
|
2909
|
+
// Images, fonts and photo transitions change the size outside any write here. Without an observer the size
|
|
2910
|
+
// is read every frame instead.
|
|
2911
|
+
const resized = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => {
|
|
2912
|
+
if (this.disposed || this.counter !== counter) {
|
|
2913
|
+
resized.disconnect();
|
|
2914
|
+
return;
|
|
2915
|
+
}
|
|
2916
|
+
resizedSince = true;
|
|
2917
|
+
this.viewer.scene.requestRender();
|
|
2918
|
+
});
|
|
2919
|
+
resized === null || resized === void 0 ? void 0 : resized.observe(ele);
|
|
2612
2920
|
let cursorMotion = this.cursorMotion;
|
|
2613
2921
|
const project = () => {
|
|
2614
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
2922
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
2615
2923
|
if (this.disposed || !this.viewer || this.viewer.isDestroyed() || ((_a = this.visible) === null || _a === void 0 ? void 0 : _a.call(this)) === false ||
|
|
2616
2924
|
(presentation === "icon" && this.options.iconScale === 0)) {
|
|
2617
2925
|
return null;
|
|
@@ -2620,6 +2928,11 @@ var EntityLabel;
|
|
|
2620
2928
|
(this.hoverFade.from === 0 || Date.now() - this.hoverFade.start >= 120)) {
|
|
2621
2929
|
return null;
|
|
2622
2930
|
}
|
|
2931
|
+
// A new label is still in layout, so its first frame reads its size, as does a shown one that resized.
|
|
2932
|
+
if (!size || (resizedSince && !hiddenLast)) {
|
|
2933
|
+
measureSize();
|
|
2934
|
+
resizedSince = false;
|
|
2935
|
+
}
|
|
2623
2936
|
// Moving point/model positions must be sampled at the current clock time.
|
|
2624
2937
|
if (!this.prePositioned && visual instanceof Cesium.Entity && visual.position) {
|
|
2625
2938
|
const position = getValue(this.viewer, visual.position);
|
|
@@ -2667,8 +2980,8 @@ var EntityLabel;
|
|
|
2667
2980
|
y: ringPoint.y + (boxTarget.y - ringPoint.y) * boxBlend
|
|
2668
2981
|
} : undefined;
|
|
2669
2982
|
const start = boxAnchor || anchor;
|
|
2670
|
-
const onScreen = anchor.x >= 0 && anchor.y >= 0 && anchor.x <
|
|
2671
|
-
if (leader && (start.x < 0 || start.y < 0 || start.x >=
|
|
2983
|
+
const onScreen = anchor.x >= 0 && anchor.y >= 0 && anchor.x < layer.viewport.width && anchor.y < layer.viewport.height;
|
|
2984
|
+
if (leader && (start.x < 0 || start.y < 0 || start.x >= layer.viewport.width || start.y >= layer.viewport.height))
|
|
2672
2985
|
return null;
|
|
2673
2986
|
if (onScreen && !this.imageAsked && this.groupId && !HasIcon(this.options) && !this.options.photo) {
|
|
2674
2987
|
this.imageAsked = true;
|
|
@@ -2715,8 +3028,8 @@ var EntityLabel;
|
|
|
2715
3028
|
if (cursorAmount > 0 && !pinned) {
|
|
2716
3029
|
// A leader-less label starts centred on its anchor; preserve that box as it lifts away.
|
|
2717
3030
|
if (!normalLeader) {
|
|
2718
|
-
x -=
|
|
2719
|
-
y +=
|
|
3031
|
+
x -= size.width / layer.coordinates.scaleX / 2;
|
|
3032
|
+
y += size.height / layer.coordinates.scaleY / 2;
|
|
2720
3033
|
}
|
|
2721
3034
|
x += (cursorMotion.position.x + pixelOffset.x - x) * cursorAmount;
|
|
2722
3035
|
y += (cursorMotion.position.y + pixelOffset.y - y) * cursorAmount;
|
|
@@ -2731,6 +3044,10 @@ var EntityLabel;
|
|
|
2731
3044
|
else if (this.options.leaderLength != null) {
|
|
2732
3045
|
leaderLength = Math.max(0, this.options.leaderLength);
|
|
2733
3046
|
}
|
|
3047
|
+
else if (pin) {
|
|
3048
|
+
// The tip itself is the leader, so by default it touches what it marks.
|
|
3049
|
+
leaderLength = 0;
|
|
3050
|
+
}
|
|
2734
3051
|
else if (transientPivot) {
|
|
2735
3052
|
// Cursor callouts must not jump when the next hover target has a different extent.
|
|
2736
3053
|
leaderLength = 96;
|
|
@@ -2747,7 +3064,7 @@ var EntityLabel;
|
|
|
2747
3064
|
if (visual instanceof Cesium.Entity && (visual.polygon || visual.polyline))
|
|
2748
3065
|
leaderLength /= 3;
|
|
2749
3066
|
}
|
|
2750
|
-
if (boxAnchor && this.options.leaderLength == null) {
|
|
3067
|
+
if (boxAnchor && this.options.leaderLength == null && !pin) {
|
|
2751
3068
|
leaderLength += (MODEL_BOX_STEM - leaderLength) * boxBlend;
|
|
2752
3069
|
}
|
|
2753
3070
|
if (cursorAmount > 0) {
|
|
@@ -2755,31 +3072,31 @@ var EntityLabel;
|
|
|
2755
3072
|
}
|
|
2756
3073
|
;
|
|
2757
3074
|
// Measured from the ring, so the visible stem is the same length whatever the glyph's size.
|
|
2758
|
-
|
|
3075
|
+
// A pin's tip rests on the glyph instead, since no ring is drawn around it.
|
|
3076
|
+
leaderLength += pin ? (_t = icon === null || icon === void 0 ? void 0 : icon.radius) !== null && _t !== void 0 ? _t : 0 : iconRing;
|
|
2759
3077
|
y = anchorY - leaderLength;
|
|
2760
3078
|
}
|
|
2761
3079
|
else if (hover && !reused && !pinned) {
|
|
2762
3080
|
x = hover.x + pixelOffset.x;
|
|
2763
3081
|
y = hover.y + pixelOffset.y - 24;
|
|
2764
3082
|
}
|
|
2765
|
-
// Hidden participants remain measurable; visibility never removes their layout boxes.
|
|
2766
3083
|
const coordinates = layer.coordinates;
|
|
2767
|
-
const width =
|
|
2768
|
-
const height =
|
|
3084
|
+
const width = size.width / coordinates.scaleX;
|
|
3085
|
+
const height = size.height / coordinates.scaleY;
|
|
2769
3086
|
let clusterBounds;
|
|
2770
|
-
if ((
|
|
2771
|
-
const textWidth =
|
|
2772
|
-
const textHeight =
|
|
3087
|
+
if ((_u = this.options.cluster) === null || _u === void 0 ? void 0 : _u.enabled) {
|
|
3088
|
+
const textWidth = size.textWidth;
|
|
3089
|
+
const textHeight = size.textHeight;
|
|
2773
3090
|
// A photo is never part of the footprint, so its arrival cannot change which cluster a label joins.
|
|
2774
|
-
const iconWidth = look.iconPhoto ? 0 :
|
|
2775
|
-
const iconHeight = look.iconPhoto ? 0 :
|
|
3091
|
+
const iconWidth = look.iconPhoto ? 0 : size.iconWidth;
|
|
3092
|
+
const iconHeight = look.iconPhoto ? 0 : size.iconHeight;
|
|
2776
3093
|
const gap = sourceText && iconWidth ? 6 : 0;
|
|
2777
3094
|
const above = presentation === "icon-text-above";
|
|
2778
3095
|
// Match the fixed content gap and label padding, excluding the count badge.
|
|
2779
3096
|
const baseWidth = ((above ? Math.max(textWidth, iconWidth) : textWidth + iconWidth + gap) + 16) / coordinates.scaleX;
|
|
2780
3097
|
const baseHeight = ((above ? textHeight + iconHeight + gap : Math.max(textHeight, iconHeight)) + 12) / coordinates.scaleY;
|
|
2781
3098
|
clusterBounds = {
|
|
2782
|
-
x: leader ? x : x - baseWidth / 2,
|
|
3099
|
+
x: leader && !pin ? x : x - baseWidth / 2,
|
|
2783
3100
|
y: leader ? y - baseHeight : y - baseHeight / 2, width: baseWidth, height: baseHeight
|
|
2784
3101
|
};
|
|
2785
3102
|
}
|
|
@@ -2790,7 +3107,9 @@ var EntityLabel;
|
|
|
2790
3107
|
// Membership uses the unclamped source footprint, never the summary's changing dimensions.
|
|
2791
3108
|
let leaderRun;
|
|
2792
3109
|
let leaderSide;
|
|
2793
|
-
if (leader &&
|
|
3110
|
+
if (leader && pin)
|
|
3111
|
+
({ x, y } = fitPin(anchorX, anchorY, leaderLength, width, height, size.pin));
|
|
3112
|
+
else if (leader && angled) {
|
|
2794
3113
|
const fit = fitAngledLeader(anchorX, anchorY, leaderLength, width, height);
|
|
2795
3114
|
({ x, y } = fit);
|
|
2796
3115
|
({ run: leaderRun, side: leaderSide } = fit);
|
|
@@ -2798,19 +3117,19 @@ var EntityLabel;
|
|
|
2798
3117
|
else if (leader)
|
|
2799
3118
|
({ x, y } = fitLeader(anchorX, anchorY, leaderLength, width, height));
|
|
2800
3119
|
const bounds = clusterBounds || { x, y, width, height };
|
|
2801
|
-
if (!leader && (bounds.x + bounds.width < 0 || bounds.y + bounds.height < 0 || bounds.x >
|
|
3120
|
+
if (!leader && (bounds.x + bounds.width < 0 || bounds.y + bounds.height < 0 || bounds.x > layer.viewport.width || bounds.y > layer.viewport.height)) {
|
|
2802
3121
|
return null;
|
|
2803
3122
|
}
|
|
2804
|
-
const state = (
|
|
3123
|
+
const state = (_v = this.visualRegister) === null || _v === void 0 ? void 0 : _v.GetState({ entityId: (_w = this.rego) === null || _w === void 0 ? void 0 : _w.entityId, menuItemId: (_x = this.rego) === null || _x === void 0 ? void 0 : _x.menuItemId });
|
|
2805
3124
|
const opacity = this.prePositioned || hoverOnly || MAX_DISTANCE === Infinity ? 1 : 1 - distance / MAX_DISTANCE;
|
|
2806
3125
|
return {
|
|
2807
|
-
canFlip: leader && presentation !== "icon", hasLeader: leader,
|
|
2808
|
-
textWrapped:
|
|
3126
|
+
canFlip: leader && presentation !== "icon" && !pin, hasLeader: leader,
|
|
3127
|
+
textWrapped: size.naturalTextWidth > TEXT_MAX_WIDTH,
|
|
2809
3128
|
transient: this.Transient || Boolean(hover) || cursorAmount > 0,
|
|
2810
3129
|
extendedGeometry: visual instanceof Cesium.Entity && Boolean(visual.polygon || visual.polyline || visual.corridor),
|
|
2811
|
-
viewportWidth:
|
|
2812
|
-
id: this.id, entityKey: ((
|
|
2813
|
-
entityId: (
|
|
3130
|
+
viewportWidth: layer.viewport.width,
|
|
3131
|
+
id: this.id, entityKey: ((_y = this.rego) === null || _y === void 0 ? void 0 : _y.entityId) ? JSON.stringify([this.rego.entityId, this.rego.menuItemId || "", this.Transient && !this.Persistent ? "hover" : ""]) : undefined,
|
|
3132
|
+
entityId: (_z = this.rego) === null || _z === void 0 ? void 0 : _z.entityId, group: this.groupId, x, y, width, height, anchorX, anchorY, depth, leaderLength, leaderRun, leaderSide, distance,
|
|
2814
3133
|
iconRadius: icon === null || icon === void 0 ? void 0 : icon.radius, modelBox: boxed || undefined, boxBlend, follows: !pinned && Boolean(transientPivot || cursorMotion.target),
|
|
2815
3134
|
// Priority shows the hovered member individually without dragging its cluster along.
|
|
2816
3135
|
opacity: waiting ? 0 : opacity, priority: hover || cursorAmount > 0 || (state === null || state === void 0 ? void 0 : state.highlighted) ? 1 : 0, options: this.options, text: originalText, clusterBounds
|
|
@@ -2819,15 +3138,25 @@ var EntityLabel;
|
|
|
2819
3138
|
let displacement = { x: 0, y: 0 };
|
|
2820
3139
|
let nudge = { x: 0, y: 0, fromX: 0, fromY: 0, targetX: 0, targetY: 0, start: 0 };
|
|
2821
3140
|
const apply = (placement) => {
|
|
2822
|
-
var _a, _b, _c, _d, _e
|
|
3141
|
+
var _a, _b, _c, _d, _e;
|
|
2823
3142
|
const show = (placement === null || placement === void 0 ? void 0 : placement.visible) && placement.opacity > 0;
|
|
3143
|
+
if (!show && hiddenLast) {
|
|
3144
|
+
return;
|
|
3145
|
+
}
|
|
3146
|
+
if (show && hiddenLast) {
|
|
3147
|
+
sizeStale = true;
|
|
3148
|
+
}
|
|
3149
|
+
hiddenLast = !show;
|
|
2824
3150
|
shownOnce = shownOnce || Boolean(show);
|
|
2825
3151
|
clickEntityIds = show ? placement.entityIds : [];
|
|
3152
|
+
// Out of layout while hidden, so thousands of clustered labels cost the browser nothing to lay out.
|
|
3153
|
+
ele.style.display = show ? "flex" : "none";
|
|
2826
3154
|
ele.style.visibility = show ? "visible" : "hidden";
|
|
2827
3155
|
lineEle.style.display = show && leader ? "block" : "none";
|
|
2828
3156
|
if (runEle)
|
|
2829
3157
|
runEle.style.display = show && leader ? "block" : "none";
|
|
2830
|
-
|
|
3158
|
+
// A pin's tip marks the anchor itself, so it has no ring there.
|
|
3159
|
+
this.anchor.style.display = show && leader && !pin && !(((_a = placement.frame) === null || _a === void 0 ? void 0 : _a.boxBlend) >= 1) ? "block" : "none";
|
|
2831
3160
|
if (!show) {
|
|
2832
3161
|
displacement = { x: 0, y: 0 };
|
|
2833
3162
|
nudge = { x: 0, y: 0, fromX: 0, fromY: 0, targetX: 0, targetY: 0, start: 0 };
|
|
@@ -2860,6 +3189,7 @@ var EntityLabel;
|
|
|
2860
3189
|
const displayText = (_c = placement.text) !== null && _c !== void 0 ? _c : originalText;
|
|
2861
3190
|
if (textElement && textElement.textContent !== displayText) {
|
|
2862
3191
|
textElement.textContent = displayText;
|
|
3192
|
+
sizeStale = true;
|
|
2863
3193
|
// Measure the summary's footprint next frame without replacing each member's source text.
|
|
2864
3194
|
this.viewer.scene.requestRender();
|
|
2865
3195
|
}
|
|
@@ -2874,17 +3204,17 @@ var EntityLabel;
|
|
|
2874
3204
|
const count = placement.members.length ? String(placement.members.length) : "";
|
|
2875
3205
|
if (countElement.textContent !== count) {
|
|
2876
3206
|
countElement.textContent = count;
|
|
3207
|
+
sizeStale = true;
|
|
2877
3208
|
// The badge participates in layout, so its new width needs another measurement.
|
|
2878
3209
|
this.viewer.scene.requestRender();
|
|
2879
3210
|
}
|
|
2880
|
-
fitIconBackground === null || fitIconBackground === void 0 ? void 0 : fitIconBackground();
|
|
2881
3211
|
const stack = JSON.stringify(placement.icons || []);
|
|
2882
3212
|
if (iconStack && stack !== displayedStack) {
|
|
2883
3213
|
displayedStack = stack;
|
|
2884
3214
|
const looks = ((_d = placement.icons) === null || _d === void 0 ? void 0 : _d.length) ? [iconLook(this.options), ...placement.icons] : [];
|
|
2885
3215
|
// One small size for all, so no icon in the arrangement reads as more important than another.
|
|
2886
3216
|
const size = (this.options.iconSize || 24) * ((_e = this.options.iconScale) !== null && _e !== void 0 ? _e : 1) * ICON_STACK_SCALE;
|
|
2887
|
-
const built = looks.map(look => this.buildIcon({ ...look, iconSize: size }, counter));
|
|
3217
|
+
const built = looks.map(look => this.buildIcon({ ...(pin ? pinLook(look) : look), iconSize: size }, counter));
|
|
2888
3218
|
// A stack is on show already, so its photos load straight away.
|
|
2889
3219
|
built.forEach(({ start }) => start === null || start === void 0 ? void 0 : start());
|
|
2890
3220
|
// Two sit side by side; three make a triangle with the representative on top.
|
|
@@ -2893,6 +3223,7 @@ var EntityLabel;
|
|
|
2893
3223
|
built[0].icon.style.gridColumn = "1 / span 2";
|
|
2894
3224
|
}
|
|
2895
3225
|
iconStack.replaceChildren(...built.map(({ icon }) => icon));
|
|
3226
|
+
sizeStale = true;
|
|
2896
3227
|
iconStack.style.display = built.length ? "inline-grid" : "none";
|
|
2897
3228
|
// The glyph stays measurable, since cluster membership is taken from its footprint.
|
|
2898
3229
|
iconElement.style.visibility = built.length ? "hidden" : "";
|
|
@@ -2901,239 +3232,302 @@ var EntityLabel;
|
|
|
2901
3232
|
// The stack widens the label, which the next frame has to measure.
|
|
2902
3233
|
this.viewer.scene.requestRender();
|
|
2903
3234
|
}
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
(this.hoverFade.to === 0 ? this.retainedHoverPosition : (_f = this.visualRegister) === null || _f === void 0 ? void 0 : _f.GetLabelHoverPosition((_g = this.rego) === null || _g === void 0 ? void 0 : _g.entityId, (_h = this.rego) === null || _h === void 0 ? void 0 : _h.menuItemId)) : undefined));
|
|
2922
|
-
const iconRing = frame.iconRadius ? Math.max(ICON_RING_MIN, frame.iconRadius + ICON_RING_PADDING) : 0;
|
|
2923
|
-
const boxed = leader ? frame.modelBox : undefined;
|
|
2924
|
-
const hovered = pointer && (boxed ? hullContains(boxed.hull, pointer) :
|
|
2925
|
-
Math.hypot(pointer.x - frame.anchorX, pointer.y - frame.anchorY) <= Math.max((_j = ring === null || ring === void 0 ? void 0 : ring.hoverDistance) !== null && _j !== void 0 ? _j : 24, iconRing));
|
|
2926
|
-
if (look.iconPhoto && growPhoto) {
|
|
2927
|
-
// A rectangle leans on the leader's side of the label.
|
|
2928
|
-
if (photoShape === "rect") {
|
|
2929
|
-
const align = !leader ? "center" : placement.textSide === "left" ? "flex-end" : "flex-start";
|
|
2930
|
-
if (content.style.alignItems !== align) {
|
|
2931
|
-
content.style.alignItems = align;
|
|
2932
|
-
}
|
|
3235
|
+
/*
|
|
3236
|
+
* Everything above writes the label's content. The layer runs what follows in two passes over all
|
|
3237
|
+
* its labels, measuring every one before placing any, so no label reads layout another just changed.
|
|
3238
|
+
*/
|
|
3239
|
+
return () => {
|
|
3240
|
+
if (sizeStale || !resized) {
|
|
3241
|
+
fitIconBackground === null || fitIconBackground === void 0 ? void 0 : fitIconBackground();
|
|
3242
|
+
for (const fit of stackedFits)
|
|
3243
|
+
fit();
|
|
3244
|
+
badge = badgeOnIcon ? {
|
|
3245
|
+
width: countElement.offsetWidth,
|
|
3246
|
+
height: countElement.offsetHeight,
|
|
3247
|
+
iconWidth: iconElement.offsetWidth,
|
|
3248
|
+
iconHeight: iconElement.offsetHeight
|
|
3249
|
+
} : null;
|
|
3250
|
+
measureSize();
|
|
3251
|
+
sizeStale = false;
|
|
2933
3252
|
}
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
3253
|
+
const pinShape = leader && pin ? size.pin : undefined;
|
|
3254
|
+
const measuredWidth = size.width / coordinates.scaleX;
|
|
3255
|
+
const measuredHeight = size.height / coordinates.scaleY;
|
|
3256
|
+
return () => {
|
|
3257
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
3258
|
+
if (badge) {
|
|
3259
|
+
const narrow = badge.iconWidth < badge.iconHeight * 0.6;
|
|
3260
|
+
const clearance = badge.width ? (narrow ? badge.width / 2 + 2 : Math.max(0, badge.width / 2 - badge.iconWidth / 4)) : 0;
|
|
3261
|
+
// Reserve the badge overhang so adjacent text and viewport edges remain clear.
|
|
3262
|
+
const overhang = badge.height / 2;
|
|
3263
|
+
const margins = [
|
|
3264
|
+
badgeBelow ? "0px" : `${overhang}px`, badgeBelow ? `${overhang}px` : "0px", `${badge.width / 2 + clearance}px`
|
|
3265
|
+
];
|
|
3266
|
+
countElement.style.left = `calc(100% + ${clearance}px)`;
|
|
3267
|
+
if (iconContainer.style.marginTop !== margins[0] ||
|
|
3268
|
+
iconContainer.style.marginBottom !== margins[1] ||
|
|
3269
|
+
iconContainer.style.marginRight !== margins[2]) {
|
|
3270
|
+
[iconContainer.style.marginTop, iconContainer.style.marginBottom, iconContainer.style.marginRight] = margins;
|
|
3271
|
+
sizeStale = true;
|
|
3272
|
+
// The margins change the label's size, which the next frame measures.
|
|
3273
|
+
this.viewer.scene.requestRender();
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
const ring = this.options.anchorRing;
|
|
3277
|
+
const pointer = (layer.pointer || (cursorMotion.target ? cursorMotion.position : undefined) || (this.Transient && !this.Persistent ?
|
|
3278
|
+
(this.hoverFade.to === 0 ? this.retainedHoverPosition : (_a = this.visualRegister) === null || _a === void 0 ? void 0 : _a.GetLabelHoverPosition((_b = this.rego) === null || _b === void 0 ? void 0 : _b.entityId, (_c = this.rego) === null || _c === void 0 ? void 0 : _c.menuItemId)) : undefined));
|
|
3279
|
+
const iconRing = frame.iconRadius ? Math.max(ICON_RING_MIN, frame.iconRadius + ICON_RING_PADDING) : 0;
|
|
3280
|
+
const boxed = leader ? frame.modelBox : undefined;
|
|
3281
|
+
const hovered = pointer && (boxed ? hullContains(boxed.hull, pointer) :
|
|
3282
|
+
Math.hypot(pointer.x - frame.anchorX, pointer.y - frame.anchorY) <= Math.max((_d = ring === null || ring === void 0 ? void 0 : ring.hoverDistance) !== null && _d !== void 0 ? _d : 24, iconRing));
|
|
3283
|
+
if (look.iconPhoto && growPhoto) {
|
|
3284
|
+
// A rectangle leans on the leader's side of the label.
|
|
3285
|
+
if (photoShape === "rect") {
|
|
3286
|
+
const align = !leader ? "center" : placement.textSide === "left" ? "flex-end" : "flex-start";
|
|
3287
|
+
if (content.style.alignItems !== align) {
|
|
3288
|
+
content.style.alignItems = align;
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
// Grown in layout rather than scaled, so the border keeps its width, and the label,
|
|
3292
|
+
// whose bottom sits on the leader, grows up and sideways without changing its length.
|
|
3293
|
+
growPhoto(Boolean(hovered) && !((_e = placement.members) === null || _e === void 0 ? void 0 : _e.length));
|
|
3294
|
+
sizeStale = true;
|
|
3295
|
+
}
|
|
3296
|
+
const normalRadius = (!leader || (ring === null || ring === void 0 ? void 0 : ring.enabled) === false ? 0 : Math.max(frame.distance <= ((_f = ring === null || ring === void 0 ? void 0 : ring.nearDistance) !== null && _f !== void 0 ? _f : 100) ? ((_g = ring === null || ring === void 0 ? void 0 : ring.nearRadius) !== null && _g !== void 0 ? _g : 10) : 0, hovered ? ((_h = ring === null || ring === void 0 ? void 0 : ring.hoverRadius) !== null && _h !== void 0 ? _h : (this.Transient && !this.Persistent ? 15.4 : 22)) : 0));
|
|
3297
|
+
const targetRadius = normalRadius + (15.4 - normalRadius) * cursorMotion.amount;
|
|
3298
|
+
// Around a glyph the ring keeps its size and only fades its stroke in, never covering it.
|
|
3299
|
+
// A ring around the cursor marks nothing, so a riding label keeps only its leader.
|
|
3300
|
+
const targetOuter = frame.follows ? 0 : iconRing || targetRadius || 2.5;
|
|
3301
|
+
const targetInner = frame.follows ? 0 : iconRing ? (targetRadius > 0 ? iconRing - 2 : iconRing) : Math.max(0, targetRadius - 2);
|
|
3302
|
+
const now = Date.now();
|
|
3303
|
+
const duration = (_j = ring === null || ring === void 0 ? void 0 : ring.transitionDuration) !== null && _j !== void 0 ? _j : 200;
|
|
3304
|
+
const sharedRing = this.Transient && !this.Persistent && this.hoverFade.to === 1 ? this.hoverRingState : undefined;
|
|
3305
|
+
let ringAnimation = sharedRing ? sharedRing.animation : this.ringAnimation;
|
|
3306
|
+
if (!ringAnimation) {
|
|
3307
|
+
const outer = frame.follows ? 0 : iconRing || 2.5;
|
|
3308
|
+
const inner = frame.follows ? 0 : iconRing;
|
|
3309
|
+
ringAnimation = { target: outer, targetInner: inner, start: now, outer, inner, fromOuter: outer, fromInner: inner };
|
|
3310
|
+
}
|
|
3311
|
+
;
|
|
3312
|
+
const animateRing = () => {
|
|
3313
|
+
const progress = duration > 0 ? Math.min(1, Math.max(0, (now - ringAnimation.start) / duration)) : 1;
|
|
3314
|
+
const eased = progress * progress * (3 - 2 * progress);
|
|
3315
|
+
ringAnimation.outer = ringAnimation.fromOuter + (ringAnimation.target - ringAnimation.fromOuter) * eased;
|
|
3316
|
+
ringAnimation.inner = ringAnimation.fromInner + (ringAnimation.targetInner - ringAnimation.fromInner) * eased;
|
|
3317
|
+
return progress;
|
|
3318
|
+
};
|
|
3319
|
+
animateRing();
|
|
3320
|
+
if (ringAnimation.target !== targetOuter || ringAnimation.targetInner !== targetInner) {
|
|
3321
|
+
ringAnimation = {
|
|
3322
|
+
...ringAnimation,
|
|
3323
|
+
target: targetOuter,
|
|
3324
|
+
targetInner,
|
|
3325
|
+
start: now,
|
|
3326
|
+
fromOuter: ringAnimation.outer,
|
|
3327
|
+
fromInner: ringAnimation.inner
|
|
3328
|
+
};
|
|
3329
|
+
}
|
|
3330
|
+
// Animate the hole and stem together; no CSS transition may lag behind a moving world anchor.
|
|
3331
|
+
if (animateRing() < 1 && (ringAnimation.fromOuter !== targetOuter || ringAnimation.fromInner !== targetInner)) {
|
|
3332
|
+
this.viewer.scene.requestRender();
|
|
3333
|
+
}
|
|
3334
|
+
this.ringAnimation = ringAnimation;
|
|
3335
|
+
if (sharedRing) {
|
|
3336
|
+
sharedRing.animation = ringAnimation;
|
|
3337
|
+
}
|
|
3338
|
+
const ringShare = 1 - (frame.boxBlend || 0);
|
|
3339
|
+
const radius = ringShare > 0 && ringAnimation.inner > 0 ? ringAnimation.outer * ringShare : 0;
|
|
3340
|
+
const stem = (pinShape ? fitPin(frame.anchorX, frame.anchorY, frame.leaderLength, measuredWidth, measuredHeight, pinShape) :
|
|
3341
|
+
leader ? (angled ? fitAngledLeader : fitLeader)(frame.anchorX, frame.anchorY, Math.max(frame.leaderLength, radius ? radius + 4 : 0), measuredWidth, measuredHeight, radius) : undefined);
|
|
3342
|
+
const position = { x: (stem || frame).x, y: (stem || frame).y };
|
|
3343
|
+
const width = measuredWidth;
|
|
3344
|
+
const height = measuredHeight;
|
|
3345
|
+
if (leader && angled) {
|
|
3346
|
+
// The declutter owns the side; the fit only says which one had the room to begin with.
|
|
3347
|
+
const run = Math.max(ANGLED_LEADER_RUN, radius + 4);
|
|
3348
|
+
const side = (_l = (_k = placement.textSide) !== null && _k !== void 0 ? _k : frame.leaderSide) !== null && _l !== void 0 ? _l : "right";
|
|
3349
|
+
const beside = side === "left" ? frame.anchorX - run - width : frame.anchorX + run;
|
|
3350
|
+
position.x = Math.max(0, Math.min(beside, layer.viewport.width - width));
|
|
3351
|
+
}
|
|
3352
|
+
else if (leader && !pin && placement.textSide === "left") {
|
|
3353
|
+
position.x = Math.max(0, Math.min(frame.anchorX - width, layer.viewport.width - width));
|
|
3354
|
+
}
|
|
3355
|
+
const gap = (_o = (_m = this.options.pointerAvoidance) === null || _m === void 0 ? void 0 : _m.gap) !== null && _o !== void 0 ? _o : 12;
|
|
3356
|
+
const containsPointer = (x, y, margin) => {
|
|
3357
|
+
return pointer && pointer.x >= x - margin && pointer.x <= x + width + margin && pointer.y >= y - margin && pointer.y <= y + height + margin;
|
|
3358
|
+
};
|
|
3359
|
+
const passive = !selectOnClick || !this.visualRegister;
|
|
3360
|
+
if (passive && ((_p = this.options.pointerAvoidance) === null || _p === void 0 ? void 0 : _p.enabled) !== false && pointer &&
|
|
3361
|
+
(containsPointer(position.x, position.y, gap) || containsPointer(position.x + displacement.x, position.y + displacement.y, gap))) {
|
|
3362
|
+
if (containsPointer(position.x + displacement.x, position.y + displacement.y, 0)) {
|
|
3363
|
+
// Choose against the original box; keep the offset until the pointer leaves both.
|
|
3364
|
+
const candidates = [
|
|
3365
|
+
{ x: 0, y: pointer.y - gap - height - position.y },
|
|
3366
|
+
{ x: 0, y: pointer.y + gap - position.y },
|
|
3367
|
+
{ x: pointer.x - gap - width - position.x, y: 0 },
|
|
3368
|
+
{ x: pointer.x + gap - position.x, y: 0 }
|
|
3369
|
+
].filter(offset => position.x + offset.x >= 0 && position.y + offset.y >= 0 &&
|
|
3370
|
+
position.x + offset.x + width <= layer.viewport.width && position.y + offset.y + height <= layer.viewport.height)
|
|
3371
|
+
.sort((a, b) => Math.hypot(a.x, a.y) - Math.hypot(b.x, b.y));
|
|
3372
|
+
displacement = candidates[0] || { x: 0, y: 0 };
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3375
|
+
else {
|
|
3376
|
+
displacement = { x: 0, y: 0 };
|
|
3377
|
+
}
|
|
3378
|
+
const nudgeDuration = (_r = (_q = this.options.pointerAvoidance) === null || _q === void 0 ? void 0 : _q.transitionDuration) !== null && _r !== void 0 ? _r : 200;
|
|
3379
|
+
const animateNudge = () => {
|
|
3380
|
+
const progress = now < nudge.start ? 0 : nudgeDuration > 0 ? Math.min(1, (now - nudge.start) / nudgeDuration) : 1;
|
|
3381
|
+
const eased = progress * progress * (3 - 2 * progress);
|
|
3382
|
+
nudge.x = nudge.fromX + (nudge.targetX - nudge.fromX) * eased;
|
|
3383
|
+
nudge.y = nudge.fromY + (nudge.targetY - nudge.fromY) * eased;
|
|
3384
|
+
return progress;
|
|
3385
|
+
};
|
|
3386
|
+
animateNudge();
|
|
3387
|
+
if (nudge.targetX !== displacement.x || nudge.targetY !== displacement.y) {
|
|
3388
|
+
nudge = {
|
|
3389
|
+
...nudge,
|
|
3390
|
+
fromX: nudge.x,
|
|
3391
|
+
fromY: nudge.y,
|
|
3392
|
+
targetX: displacement.x,
|
|
3393
|
+
targetY: displacement.y,
|
|
3394
|
+
start: now + ((_t = (_s = this.options.pointerAvoidance) === null || _s === void 0 ? void 0 : _s.delay) !== null && _t !== void 0 ? _t : 180)
|
|
3395
|
+
};
|
|
3396
|
+
}
|
|
3397
|
+
if (animateNudge() < 1 && (nudge.fromX !== nudge.targetX || nudge.fromY !== nudge.targetY)) {
|
|
3398
|
+
this.viewer.scene.requestRender();
|
|
3399
|
+
}
|
|
3400
|
+
position.x += nudge.x;
|
|
3401
|
+
position.y += nudge.y;
|
|
3402
|
+
ele.style.left = `${coordinates.x + position.x * coordinates.scaleX}px`;
|
|
3403
|
+
ele.style.top = `${coordinates.y + position.y * coordinates.scaleY}px`;
|
|
3404
|
+
for (const clickTarget of Array.from(content.querySelectorAll('[role="button"]'))) {
|
|
3405
|
+
clickTarget.setAttribute("aria-label", placement.members.length ? `Select ${placement.entityIds.length} entities` : `Select ${(_v = (_u = this.options.text) !== null && _u !== void 0 ? _u : text) !== null && _v !== void 0 ? _v : (_w = this.rego) === null || _w === void 0 ? void 0 : _w.entityId}`);
|
|
3406
|
+
}
|
|
3407
|
+
if (leader) {
|
|
3408
|
+
const nodeRadius = ringAnimation.outer * (1 - (frame.boxBlend || 0));
|
|
3409
|
+
const anchor = this.anchor;
|
|
3410
|
+
anchor.style.left = `${coordinates.x + (frame.anchorX - nodeRadius) * coordinates.scaleX}px`;
|
|
3411
|
+
anchor.style.top = `${coordinates.y + (frame.anchorY - nodeRadius) * coordinates.scaleY}px`;
|
|
3412
|
+
anchor.style.width = `${nodeRadius * 2 * coordinates.scaleX}px`;
|
|
3413
|
+
anchor.style.height = `${nodeRadius * 2 * coordinates.scaleY}px`;
|
|
3414
|
+
anchor.style.boxSizing = "border-box";
|
|
3415
|
+
anchor.style.background = "transparent";
|
|
3416
|
+
const svg = anchor.firstElementChild;
|
|
3417
|
+
svg.setAttribute("viewBox", `0 0 ${nodeRadius * 2} ${nodeRadius * 2}`);
|
|
3418
|
+
const circle = svg.firstElementChild;
|
|
3419
|
+
circle.setAttribute("cx", String(nodeRadius));
|
|
3420
|
+
circle.setAttribute("cy", String(nodeRadius));
|
|
3421
|
+
const innerRadius = ringAnimation.inner * (1 - (frame.boxBlend || 0));
|
|
3422
|
+
circle.setAttribute("r", String((nodeRadius + innerRadius) / 2));
|
|
3423
|
+
circle.setAttribute("stroke", this.options.leaderColor || "rgba(255, 255, 255, 0.8)");
|
|
3424
|
+
circle.setAttribute("stroke-width", String(nodeRadius - innerRadius));
|
|
3425
|
+
anchor.style.boxShadow = radius ? "none" : "0 0 5px rgba(0, 0, 0, 0.3)";
|
|
3426
|
+
anchor.style.opacity = String(opacity * (normalLeader ? 1 : cursorMotion.amount) * (1 - (frame.boxBlend || 0)));
|
|
3427
|
+
anchor.style.zIndex = String(placement.zIndex);
|
|
3428
|
+
// The stem starts at the rim, never across the clear centre, even after displacement.
|
|
3429
|
+
const straightX = Math.max(position.x, Math.min(frame.anchorX, position.x + width));
|
|
3430
|
+
const straightY = frame.anchorY < position.y ? position.y : frame.anchorY > position.y + height ? position.y + height : frame.anchorY;
|
|
3431
|
+
const beside = angled && (frame.anchorX < position.x || frame.anchorX > position.x + width);
|
|
3432
|
+
const elbowY = position.y + height / 2;
|
|
3433
|
+
let endX = beside ? frame.anchorX : straightX;
|
|
3434
|
+
let endY = beside ? elbowY : straightY;
|
|
3435
|
+
if (pinShape) {
|
|
3436
|
+
// Aimed from wherever clamping or a nudge left it; a stem, if any, meets the tip.
|
|
3437
|
+
const centreX = position.x + pinShape.x, centreY = position.y + pinShape.y;
|
|
3438
|
+
const aim = Math.atan2(frame.anchorY - centreY, frame.anchorX - centreX);
|
|
3439
|
+
const reach = Math.min(pinShape.tip, Math.hypot(frame.anchorX - centreX, frame.anchorY - centreY));
|
|
3440
|
+
endX = centreX + Math.cos(aim) * reach;
|
|
3441
|
+
endY = centreY + Math.sin(aim) * reach;
|
|
3442
|
+
const size = `${pinShape.radius * 2 * coordinates.scaleX}px`;
|
|
3443
|
+
if (pinHolder.style.width !== size) {
|
|
3444
|
+
pinHolder.style.width = pinHolder.style.height = size;
|
|
3445
|
+
pinHolder.style.margin = `-${pinShape.radius * coordinates.scaleX}px`;
|
|
3446
|
+
}
|
|
3447
|
+
// The body's square corner starts lower right, a quarter turn short of down.
|
|
3448
|
+
const turn = Math.round((aim - Math.PI / 4) * 200) / 200;
|
|
3449
|
+
const rotation = `rotate(${turn}rad)`;
|
|
3450
|
+
if (pinBody.style.transform !== rotation) {
|
|
3451
|
+
pinBody.style.transform = rotation;
|
|
3452
|
+
// A box shadow turns with the body, so its offset is turned back to fall down
|
|
3453
|
+
// and right; a drop-shadow filter would not turn, but repaints every moving pin.
|
|
3454
|
+
const offsetX = Math.round((Math.cos(turn) + 2 * Math.sin(turn)) * 4) / 4;
|
|
3455
|
+
const offsetY = Math.round((2 * Math.cos(turn) - Math.sin(turn)) * 4) / 4;
|
|
3456
|
+
pinBody.style.boxShadow = `${offsetX}px ${offsetY}px 3px rgba(0, 0, 0, 0.35)`;
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3459
|
+
const runToX = frame.anchorX < position.x ? position.x : position.x + width;
|
|
3460
|
+
const dx = endX - frame.anchorX, dy = endY - frame.anchorY;
|
|
3461
|
+
const length = Math.hypot(dx, dy);
|
|
3462
|
+
const leaderAngle = Math.atan2(dy, dx);
|
|
3463
|
+
const pointerDx = pointer ? pointer.x - frame.anchorX : 0;
|
|
3464
|
+
const pointerDy = pointer ? pointer.y - frame.anchorY : 0;
|
|
3465
|
+
const desiredAngle = Math.hypot(pointerDx, pointerDy) > 0.5 ? Math.atan2(pointerDy, pointerDx) + Math.PI - leaderAngle : 0;
|
|
3466
|
+
const wrappedAngle = Math.atan2(Math.sin(desiredAngle), Math.cos(desiredAngle));
|
|
3467
|
+
// Keep the stem inside the 126-degree arc, away from antialiased endpoints.
|
|
3468
|
+
const arcFraction = 0.35;
|
|
3469
|
+
const rotationLimit = Math.PI * arcFraction - Math.PI / 30;
|
|
3470
|
+
const targetOffset = hovered ? Math.max(-rotationLimit, Math.min(rotationLimit, wrappedAngle)) : ((_x = ringAnimation.arcOffset) !== null && _x !== void 0 ? _x : 0);
|
|
3471
|
+
const targetOpen = cursorMotion.target || (hovered && (ring === null || ring === void 0 ? void 0 : ring.enabled) !== false && targetRadius > 0) ? 1 : 0;
|
|
3472
|
+
const elapsed = Math.min(32, Math.max(0, now - ((_y = ringAnimation.arcTime) !== null && _y !== void 0 ? _y : now)));
|
|
3473
|
+
const blend = duration > 0 ? 1 - Math.exp(-elapsed / (duration / 3)) : 1;
|
|
3474
|
+
const approach = (value, target) => Math.abs(value - target) < 0.001 ? target : value + (target - value) * blend;
|
|
3475
|
+
ringAnimation.arcOffset = approach((_z = ringAnimation.arcOffset) !== null && _z !== void 0 ? _z : 0, targetOffset);
|
|
3476
|
+
ringAnimation.arcOpen = approach((_0 = ringAnimation.arcOpen) !== null && _0 !== void 0 ? _0 : 0, targetOpen);
|
|
3477
|
+
ringAnimation.arcTime = now;
|
|
3478
|
+
if (ringAnimation.arcOffset !== targetOffset || ringAnimation.arcOpen !== targetOpen) {
|
|
3479
|
+
this.viewer.scene.requestRender();
|
|
3480
|
+
}
|
|
3481
|
+
const circumference = Math.PI * (nodeRadius + ringAnimation.inner);
|
|
3482
|
+
const filledFraction = 1 - ringAnimation.arcOpen * (1 - arcFraction);
|
|
3483
|
+
circle.setAttribute("stroke-dasharray", `${circumference * filledFraction} ${circumference * (1 - filledFraction)}`);
|
|
3484
|
+
circle.setAttribute("transform", `rotate(${(leaderAngle + ringAnimation.arcOffset - Math.PI * filledFraction) * 180 / Math.PI} ${nodeRadius} ${nodeRadius})`);
|
|
3485
|
+
const cut = Math.min(radius, length);
|
|
3486
|
+
const startX = frame.anchorX + (length ? dx / length * cut : 0);
|
|
3487
|
+
const startY = frame.anchorY + (length ? dy / length * cut : 0);
|
|
3488
|
+
const draw = (element, fromX, fromY, toX, toY) => {
|
|
3489
|
+
const screenDx = (toX - fromX) * coordinates.scaleX;
|
|
3490
|
+
const screenDy = (toY - fromY) * coordinates.scaleY;
|
|
3491
|
+
element.style.width = `${2 * coordinates.scaleX}px`;
|
|
3492
|
+
element.style.left = `${coordinates.x + (fromX - 1) * coordinates.scaleX}px`;
|
|
3493
|
+
element.style.top = `${coordinates.y + fromY * coordinates.scaleY}px`;
|
|
3494
|
+
element.style.height = `${Math.hypot(screenDx, screenDy)}px`;
|
|
3495
|
+
element.style.transform = `rotate(${Math.atan2(screenDy, screenDx) - Math.PI / 2}rad)`;
|
|
3496
|
+
element.style.boxShadow = radius ? "none" : "0 0 5px rgba(0, 0, 0, 0.3)";
|
|
3497
|
+
element.style.transformOrigin = "top center";
|
|
3498
|
+
element.style.opacity = String(opacity * (normalLeader ? 1 : cursorMotion.amount));
|
|
3499
|
+
element.style.zIndex = String(placement.zIndex);
|
|
3500
|
+
};
|
|
3501
|
+
draw(lineEle, startX, startY, endX, endY);
|
|
3502
|
+
if (layer.modelBoxes.Hull(this.id)) {
|
|
3503
|
+
layer.modelBoxes.Request(this.id, {
|
|
3504
|
+
whole: Boolean(cursorMotion.target), from: { x: frame.anchorX, y: frame.anchorY },
|
|
3505
|
+
opacity, zIndex: placement.zIndex, color: this.options.leaderColor || "rgba(255, 255, 255, 0.8)", duration
|
|
3506
|
+
});
|
|
3507
|
+
}
|
|
3508
|
+
if (runEle) {
|
|
3509
|
+
// Overlap the corner by the stem's own width so the elbow has no notch in it.
|
|
3510
|
+
const overlap = frame.anchorX < runToX ? -1 : 1;
|
|
3511
|
+
runEle.style.display = beside ? "block" : "none";
|
|
3512
|
+
if (beside)
|
|
3513
|
+
draw(runEle, endX + overlap, endY, runToX, endY);
|
|
3514
|
+
}
|
|
3515
|
+
}
|
|
2970
3516
|
};
|
|
2971
|
-
}
|
|
2972
|
-
// Animate the hole and stem together; no CSS transition may lag behind a moving world anchor.
|
|
2973
|
-
if (animateRing() < 1 && (ringAnimation.fromOuter !== targetOuter || ringAnimation.fromInner !== targetInner)) {
|
|
2974
|
-
this.viewer.scene.requestRender();
|
|
2975
|
-
}
|
|
2976
|
-
this.ringAnimation = ringAnimation;
|
|
2977
|
-
if (sharedRing) {
|
|
2978
|
-
sharedRing.animation = ringAnimation;
|
|
2979
|
-
}
|
|
2980
|
-
const ringShare = 1 - (frame.boxBlend || 0);
|
|
2981
|
-
const radius = ringShare > 0 && ringAnimation.inner > 0 ? ringAnimation.outer * ringShare : 0;
|
|
2982
|
-
const stem = (leader ? (angled ? fitAngledLeader : fitLeader)(frame.anchorX, frame.anchorY, Math.max(frame.leaderLength, radius ? radius + 4 : 0), ele.offsetWidth / coordinates.scaleX, ele.offsetHeight / coordinates.scaleY, radius) : undefined);
|
|
2983
|
-
const position = { x: (stem || frame).x, y: (stem || frame).y };
|
|
2984
|
-
const width = ele.offsetWidth / coordinates.scaleX;
|
|
2985
|
-
const height = ele.offsetHeight / coordinates.scaleY;
|
|
2986
|
-
if (leader && angled) {
|
|
2987
|
-
// The declutter owns the side; the fit only says which one had the room to begin with.
|
|
2988
|
-
const run = Math.max(ANGLED_LEADER_RUN, radius + 4);
|
|
2989
|
-
const side = (_r = (_q = placement.textSide) !== null && _q !== void 0 ? _q : frame.leaderSide) !== null && _r !== void 0 ? _r : "right";
|
|
2990
|
-
const beside = side === "left" ? frame.anchorX - run - width : frame.anchorX + run;
|
|
2991
|
-
position.x = Math.max(0, Math.min(beside, this.viewer.canvas.clientWidth - width));
|
|
2992
|
-
}
|
|
2993
|
-
else if (leader && placement.textSide === "left") {
|
|
2994
|
-
position.x = Math.max(0, Math.min(frame.anchorX - width, this.viewer.canvas.clientWidth - width));
|
|
2995
|
-
}
|
|
2996
|
-
const gap = (_t = (_s = this.options.pointerAvoidance) === null || _s === void 0 ? void 0 : _s.gap) !== null && _t !== void 0 ? _t : 12;
|
|
2997
|
-
const containsPointer = (x, y, margin) => {
|
|
2998
|
-
return pointer && pointer.x >= x - margin && pointer.x <= x + width + margin && pointer.y >= y - margin && pointer.y <= y + height + margin;
|
|
2999
|
-
};
|
|
3000
|
-
const passive = !selectOnClick || !this.visualRegister;
|
|
3001
|
-
if (passive && ((_u = this.options.pointerAvoidance) === null || _u === void 0 ? void 0 : _u.enabled) !== false && pointer &&
|
|
3002
|
-
(containsPointer(position.x, position.y, gap) || containsPointer(position.x + displacement.x, position.y + displacement.y, gap))) {
|
|
3003
|
-
if (containsPointer(position.x + displacement.x, position.y + displacement.y, 0)) {
|
|
3004
|
-
// Choose against the original box and retain the offset until the pointer leaves both boxes.
|
|
3005
|
-
const candidates = [
|
|
3006
|
-
{ x: 0, y: pointer.y - gap - height - position.y },
|
|
3007
|
-
{ x: 0, y: pointer.y + gap - position.y },
|
|
3008
|
-
{ x: pointer.x - gap - width - position.x, y: 0 },
|
|
3009
|
-
{ x: pointer.x + gap - position.x, y: 0 }
|
|
3010
|
-
].filter(offset => position.x + offset.x >= 0 && position.y + offset.y >= 0 &&
|
|
3011
|
-
position.x + offset.x + width <= this.viewer.canvas.clientWidth && position.y + offset.y + height <= this.viewer.canvas.clientHeight)
|
|
3012
|
-
.sort((a, b) => Math.hypot(a.x, a.y) - Math.hypot(b.x, b.y));
|
|
3013
|
-
displacement = candidates[0] || { x: 0, y: 0 };
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
|
-
else {
|
|
3017
|
-
displacement = { x: 0, y: 0 };
|
|
3018
|
-
}
|
|
3019
|
-
const nudgeDuration = (_w = (_v = this.options.pointerAvoidance) === null || _v === void 0 ? void 0 : _v.transitionDuration) !== null && _w !== void 0 ? _w : 200;
|
|
3020
|
-
const animateNudge = () => {
|
|
3021
|
-
const progress = now < nudge.start ? 0 : nudgeDuration > 0 ? Math.min(1, (now - nudge.start) / nudgeDuration) : 1;
|
|
3022
|
-
const eased = progress * progress * (3 - 2 * progress);
|
|
3023
|
-
nudge.x = nudge.fromX + (nudge.targetX - nudge.fromX) * eased;
|
|
3024
|
-
nudge.y = nudge.fromY + (nudge.targetY - nudge.fromY) * eased;
|
|
3025
|
-
return progress;
|
|
3026
3517
|
};
|
|
3027
|
-
animateNudge();
|
|
3028
|
-
if (nudge.targetX !== displacement.x || nudge.targetY !== displacement.y) {
|
|
3029
|
-
nudge = {
|
|
3030
|
-
...nudge,
|
|
3031
|
-
fromX: nudge.x,
|
|
3032
|
-
fromY: nudge.y,
|
|
3033
|
-
targetX: displacement.x,
|
|
3034
|
-
targetY: displacement.y,
|
|
3035
|
-
start: now + ((_y = (_x = this.options.pointerAvoidance) === null || _x === void 0 ? void 0 : _x.delay) !== null && _y !== void 0 ? _y : 180)
|
|
3036
|
-
};
|
|
3037
|
-
}
|
|
3038
|
-
if (animateNudge() < 1 && (nudge.fromX !== nudge.targetX || nudge.fromY !== nudge.targetY)) {
|
|
3039
|
-
this.viewer.scene.requestRender();
|
|
3040
|
-
}
|
|
3041
|
-
position.x += nudge.x;
|
|
3042
|
-
position.y += nudge.y;
|
|
3043
|
-
ele.style.left = `${coordinates.x + position.x * coordinates.scaleX}px`;
|
|
3044
|
-
ele.style.top = `${coordinates.y + position.y * coordinates.scaleY}px`;
|
|
3045
|
-
for (const clickTarget of Array.from(content.querySelectorAll('[role="button"]'))) {
|
|
3046
|
-
clickTarget.setAttribute("aria-label", placement.members.length ? `Select ${placement.entityIds.length} entities` : `Select ${(_0 = (_z = this.options.text) !== null && _z !== void 0 ? _z : text) !== null && _0 !== void 0 ? _0 : (_1 = this.rego) === null || _1 === void 0 ? void 0 : _1.entityId}`);
|
|
3047
|
-
}
|
|
3048
|
-
if (leader) {
|
|
3049
|
-
const nodeRadius = ringAnimation.outer * (1 - (frame.boxBlend || 0));
|
|
3050
|
-
const anchor = this.anchor;
|
|
3051
|
-
anchor.style.left = `${coordinates.x + (frame.anchorX - nodeRadius) * coordinates.scaleX}px`;
|
|
3052
|
-
anchor.style.top = `${coordinates.y + (frame.anchorY - nodeRadius) * coordinates.scaleY}px`;
|
|
3053
|
-
anchor.style.width = `${nodeRadius * 2 * coordinates.scaleX}px`;
|
|
3054
|
-
anchor.style.height = `${nodeRadius * 2 * coordinates.scaleY}px`;
|
|
3055
|
-
anchor.style.boxSizing = "border-box";
|
|
3056
|
-
anchor.style.background = "transparent";
|
|
3057
|
-
const svg = anchor.firstElementChild;
|
|
3058
|
-
svg.setAttribute("viewBox", `0 0 ${nodeRadius * 2} ${nodeRadius * 2}`);
|
|
3059
|
-
const circle = svg.firstElementChild;
|
|
3060
|
-
circle.setAttribute("cx", String(nodeRadius));
|
|
3061
|
-
circle.setAttribute("cy", String(nodeRadius));
|
|
3062
|
-
const innerRadius = ringAnimation.inner * (1 - (frame.boxBlend || 0));
|
|
3063
|
-
circle.setAttribute("r", String((nodeRadius + innerRadius) / 2));
|
|
3064
|
-
circle.setAttribute("stroke", this.options.leaderColor || "rgba(255, 255, 255, 0.8)");
|
|
3065
|
-
circle.setAttribute("stroke-width", String(nodeRadius - innerRadius));
|
|
3066
|
-
anchor.style.boxShadow = radius ? "none" : "0 0 5px rgba(0, 0, 0, 0.3)";
|
|
3067
|
-
anchor.style.opacity = String(opacity * (normalLeader ? 1 : cursorMotion.amount) * (1 - (frame.boxBlend || 0)));
|
|
3068
|
-
anchor.style.zIndex = String(placement.zIndex);
|
|
3069
|
-
// The stem starts at the rim, never across the transparent centre, even after passive displacement.
|
|
3070
|
-
const straightX = Math.max(position.x, Math.min(frame.anchorX, position.x + width));
|
|
3071
|
-
const straightY = frame.anchorY < position.y ? position.y : frame.anchorY > position.y + height ? position.y + height : frame.anchorY;
|
|
3072
|
-
const beside = angled && (frame.anchorX < position.x || frame.anchorX > position.x + width);
|
|
3073
|
-
const elbowY = position.y + height / 2;
|
|
3074
|
-
const endX = beside ? frame.anchorX : straightX;
|
|
3075
|
-
const endY = beside ? elbowY : straightY;
|
|
3076
|
-
const runToX = frame.anchorX < position.x ? position.x : position.x + width;
|
|
3077
|
-
const dx = endX - frame.anchorX, dy = endY - frame.anchorY;
|
|
3078
|
-
const length = Math.hypot(dx, dy);
|
|
3079
|
-
const leaderAngle = Math.atan2(dy, dx);
|
|
3080
|
-
const pointerDx = pointer ? pointer.x - frame.anchorX : 0;
|
|
3081
|
-
const pointerDy = pointer ? pointer.y - frame.anchorY : 0;
|
|
3082
|
-
const desiredAngle = Math.hypot(pointerDx, pointerDy) > 0.5 ? Math.atan2(pointerDy, pointerDx) + Math.PI - leaderAngle : 0;
|
|
3083
|
-
const wrappedAngle = Math.atan2(Math.sin(desiredAngle), Math.cos(desiredAngle));
|
|
3084
|
-
// Keep the stem inside the 126-degree arc, away from antialiased endpoints.
|
|
3085
|
-
const arcFraction = 0.35;
|
|
3086
|
-
const rotationLimit = Math.PI * arcFraction - Math.PI / 30;
|
|
3087
|
-
const targetOffset = hovered ? Math.max(-rotationLimit, Math.min(rotationLimit, wrappedAngle)) : ((_2 = ringAnimation.arcOffset) !== null && _2 !== void 0 ? _2 : 0);
|
|
3088
|
-
const targetOpen = cursorMotion.target || (hovered && (ring === null || ring === void 0 ? void 0 : ring.enabled) !== false && targetRadius > 0) ? 1 : 0;
|
|
3089
|
-
const elapsed = Math.min(32, Math.max(0, now - ((_3 = ringAnimation.arcTime) !== null && _3 !== void 0 ? _3 : now)));
|
|
3090
|
-
const blend = duration > 0 ? 1 - Math.exp(-elapsed / (duration / 3)) : 1;
|
|
3091
|
-
const approach = (value, target) => Math.abs(value - target) < 0.001 ? target : value + (target - value) * blend;
|
|
3092
|
-
ringAnimation.arcOffset = approach((_4 = ringAnimation.arcOffset) !== null && _4 !== void 0 ? _4 : 0, targetOffset);
|
|
3093
|
-
ringAnimation.arcOpen = approach((_5 = ringAnimation.arcOpen) !== null && _5 !== void 0 ? _5 : 0, targetOpen);
|
|
3094
|
-
ringAnimation.arcTime = now;
|
|
3095
|
-
if (ringAnimation.arcOffset !== targetOffset || ringAnimation.arcOpen !== targetOpen) {
|
|
3096
|
-
this.viewer.scene.requestRender();
|
|
3097
|
-
}
|
|
3098
|
-
const circumference = Math.PI * (nodeRadius + ringAnimation.inner);
|
|
3099
|
-
const filledFraction = 1 - ringAnimation.arcOpen * (1 - arcFraction);
|
|
3100
|
-
circle.setAttribute("stroke-dasharray", `${circumference * filledFraction} ${circumference * (1 - filledFraction)}`);
|
|
3101
|
-
circle.setAttribute("transform", `rotate(${(leaderAngle + ringAnimation.arcOffset - Math.PI * filledFraction) * 180 / Math.PI} ${nodeRadius} ${nodeRadius})`);
|
|
3102
|
-
const cut = Math.min(radius, length);
|
|
3103
|
-
const startX = frame.anchorX + (length ? dx / length * cut : 0);
|
|
3104
|
-
const startY = frame.anchorY + (length ? dy / length * cut : 0);
|
|
3105
|
-
const draw = (element, fromX, fromY, toX, toY) => {
|
|
3106
|
-
const screenDx = (toX - fromX) * coordinates.scaleX;
|
|
3107
|
-
const screenDy = (toY - fromY) * coordinates.scaleY;
|
|
3108
|
-
element.style.width = `${2 * coordinates.scaleX}px`;
|
|
3109
|
-
element.style.left = `${coordinates.x + (fromX - 1) * coordinates.scaleX}px`;
|
|
3110
|
-
element.style.top = `${coordinates.y + fromY * coordinates.scaleY}px`;
|
|
3111
|
-
element.style.height = `${Math.hypot(screenDx, screenDy)}px`;
|
|
3112
|
-
element.style.transform = `rotate(${Math.atan2(screenDy, screenDx) - Math.PI / 2}rad)`;
|
|
3113
|
-
element.style.boxShadow = radius ? "none" : "0 0 5px rgba(0, 0, 0, 0.3)";
|
|
3114
|
-
element.style.transformOrigin = "top center";
|
|
3115
|
-
element.style.opacity = String(opacity * (normalLeader ? 1 : cursorMotion.amount));
|
|
3116
|
-
element.style.zIndex = String(placement.zIndex);
|
|
3117
|
-
};
|
|
3118
|
-
draw(lineEle, startX, startY, endX, endY);
|
|
3119
|
-
if (layer.modelBoxes.Hull(this.id)) {
|
|
3120
|
-
layer.modelBoxes.Request(this.id, {
|
|
3121
|
-
whole: Boolean(cursorMotion.target), from: { x: frame.anchorX, y: frame.anchorY },
|
|
3122
|
-
opacity, zIndex: placement.zIndex, color: this.options.leaderColor || "rgba(255, 255, 255, 0.8)", duration
|
|
3123
|
-
});
|
|
3124
|
-
}
|
|
3125
|
-
if (runEle) {
|
|
3126
|
-
// Overlap the corner by the stem's own width so the elbow has no notch in it.
|
|
3127
|
-
const overlap = frame.anchorX < runToX ? -1 : 1;
|
|
3128
|
-
runEle.style.display = beside ? "block" : "none";
|
|
3129
|
-
if (beside)
|
|
3130
|
-
draw(runEle, endX + overlap, endY, runToX, endY);
|
|
3131
|
-
}
|
|
3132
|
-
}
|
|
3133
3518
|
};
|
|
3134
3519
|
ele.style.display = "flex";
|
|
3135
3520
|
ele.style.visibility = "hidden";
|
|
3136
|
-
|
|
3521
|
+
// Hovering, riding the cursor or a highlight lift a label out of its cluster, which a stale frame misses.
|
|
3522
|
+
const wake = () => {
|
|
3523
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
3524
|
+
return Boolean(this.Transient ||
|
|
3525
|
+
((_a = this.cursorMotion) === null || _a === void 0 ? void 0 : _a.target) ||
|
|
3526
|
+
((_b = this.cursorMotion) === null || _b === void 0 ? void 0 : _b.amount) > 0 ||
|
|
3527
|
+
((_c = this.visualRegister) === null || _c === void 0 ? void 0 : _c.GetLabelHoverPosition((_d = this.rego) === null || _d === void 0 ? void 0 : _d.entityId, (_e = this.rego) === null || _e === void 0 ? void 0 : _e.menuItemId)) ||
|
|
3528
|
+
((_j = (_f = this.visualRegister) === null || _f === void 0 ? void 0 : _f.GetState({ entityId: (_g = this.rego) === null || _g === void 0 ? void 0 : _g.entityId, menuItemId: (_h = this.rego) === null || _h === void 0 ? void 0 : _h.menuItemId })) === null || _j === void 0 ? void 0 : _j.highlighted));
|
|
3529
|
+
};
|
|
3530
|
+
this.renderRemoval = layer.Add({ project, apply, wake });
|
|
3137
3531
|
leaveLayer === null || leaveLayer === void 0 ? void 0 : leaveLayer();
|
|
3138
3532
|
// If terrain changes then we'll re-call createLabel as the position may have changed.
|
|
3139
3533
|
let terrTimeout = null;
|