-
Notifications
You must be signed in to change notification settings - Fork 208
/
ToolTipProvider.ts
75 lines (62 loc) · 2.5 KB
/
ToolTipProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Tools
*/
import { HitDetail, IModelApp, Tool, ToolTipProvider } from "@itwin/core-frontend";
import { parseToggle } from "./parseToggle";
/** Augments tooltips with detailed information useful for debugging.
* @internal
*/
class DebugToolTipProvider implements ToolTipProvider {
private static _instance?: DebugToolTipProvider;
public async augmentToolTip(hit: HitDetail, tooltipPromise: Promise<HTMLElement | string>): Promise<HTMLElement | string> {
// discard and overwrite
await tooltipPromise;
const keys = ["sourceId", "modelId", "subCategoryId", "tileId", "geometryClass"] satisfies Array<keyof HitDetail>;
let html = "";
for (const key of keys) {
const value = hit[key];
if (undefined === value)
continue;
html = `${html + key}: ${value.toString()}<br>`;
}
const div = document.createElement("div");
div.innerHTML = html;
return div;
}
public static setEnabled(enabled: boolean | undefined): void {
if (undefined === enabled)
enabled = undefined === this._instance;
if (enabled) {
if (undefined === this._instance) {
this._instance = new DebugToolTipProvider();
IModelApp.viewManager.addToolTipProvider(this._instance);
}
} else if (undefined !== this._instance) {
IModelApp.viewManager.dropToolTipProvider(this._instance);
this._instance = undefined;
}
}
}
/** Replaces the default tooltips displayed when mousing over elements to instead display information useful for debugging, including
* element, model, subcategory, and tile Ids as well as geometry class.
* @beta
*/
export class ToggleToolTipsTool extends Tool {
public static override toolId = "ToggleToolTips";
public static override get minArgs() { return 0; }
public static override get maxArgs() { return 1; }
public override async run(enable?: boolean): Promise<boolean> {
DebugToolTipProvider.setEnabled(enable);
return true;
}
public override async parseAndRun(...args: string[]): Promise<boolean> {
const enable = parseToggle(args[0]);
if (typeof enable !== "string")
await this.run(enable);
return true;
}
}