InputManager API
About 2 min
InputManager API
InputManager wraps interactive input: points, selection, numbers, keywords, and strings. Access via cadLayer.inputManager.
All get* methods return Promise<InputResult>.
Input methods
getPoint
getPoint(options?: PointInputOptions): Promise<InputResult>Pick a point on the map.
| Parameter | Type | Description |
|---|---|---|
options | PointInputOptions | Optional options |
Example:
const result = await inputManager.getPoint({
prompt: '指定第一个点',
basePoint: { x: 0, y: 0 },
});
if (result.status === InputStatusEnum.OK) {
console.log(result.point); // { x, y }
}getSelection
getSelection(options?: SelectionInputOptions): Promise<InputResult>Pick a set of entities.
| Parameter | Type | Description |
|---|---|---|
options | SelectionInputOptions | Optional filters |
Example:
const result = await inputManager.getSelection({
prompt: '选择要删除的实体',
});
if (result.status === InputStatusEnum.OK) {
result.entities!.forEach(e => cadLayer.deleteEntity(e.id));
}getReal
getReal(options?: RealInputOptions): Promise<InputResult>Read a floating-point value.
| Parameter | Type | Description |
|---|---|---|
options | RealInputOptions | Optional defaults, range |
getInteger
getInteger(options?: IntegerInputOptions): Promise<InputResult>Read an integer.
| Parameter | Type | Description |
|---|---|---|
options | IntegerInputOptions | Optional defaults, range |
getKeyword
getKeyword(options?: KeywordInputOptions): Promise<InputResult>Pick from a keyword list.
| Parameter | Type | Description |
|---|---|---|
options | KeywordInputOptions | Keywords, etc. |
Example:
const result = await inputManager.getKeyword({
prompt: '选择操作',
keywords: ['移动', '复制', '旋转'],
defaultKeyword: '移动',
});
if (result.status === InputStatusEnum.OK) {
console.log(result.keyword); // '移动' | '复制' | '旋转'
}getString
getString(options?: StringInputOptions): Promise<InputResult>Read a string.
| Parameter | Type | Description |
|---|---|---|
options | StringInputOptions | Optional default |
cancelCurrentInput
cancelCurrentInput(): voidCancel the active input; the pending get* resolves with Cancel.
Nudge properties
| Property | Type | Description |
|---|---|---|
nudgePixels | number | Arrow-key nudge in pixels |
nudgeRotateDeg | number | Nudge rotation in degrees |
nudgeScaleFactor | number | Nudge scale factor |
InputResult
Return type for all get* methods.
interface InputResult {
status: InputStatusEnum;
point?: Point2D;
value?: number;
keyword?: string;
entities?: EntityBase[];
}| Property | Type | Description |
|---|---|---|
status | InputStatusEnum | Outcome |
point | Point2D | From getPoint |
value | number | From getReal / getInteger |
keyword | string | From getKeyword |
entities | EntityBase[] | From getSelection |
InputStatusEnum
enum InputStatusEnum {
OK = 'ok',
Cancel = 'cancel',
Keyword = 'keyword',
}| Value | Description | |---|---|---| | OK | Success | | Cancel | User cancelled (Escape / right-click) | | Keyword | Keyword entered (during point pick, etc.) |
Option types
PointInputOptions
interface PointInputOptions {
prompt?: string;
basePoint?: Point2DLike;
keywords?: string[];
defaultKeyword?: string;
}| Property | Type | Description |
|---|---|---|
prompt | string | Prompt text |
basePoint | Point2DLike | Rubber-band base |
keywords | string[] | Optional keywords |
defaultKeyword | string | Default keyword |
SelectionInputOptions
interface SelectionInputOptions {
prompt?: string;
filter?: (entity: EntityBase) => boolean;
singleSelect?: boolean;
}| Property | Type | Description |
|---|---|---|
prompt | string | Prompt text |
filter | (entity: EntityBase) => boolean | Entity filter |
singleSelect | boolean | Single-selection mode |
RealInputOptions
interface RealInputOptions {
prompt?: string;
defaultValue?: number;
min?: number;
max?: number;
keywords?: string[];
}IntegerInputOptions
interface IntegerInputOptions {
prompt?: string;
defaultValue?: number;
min?: number;
max?: number;
keywords?: string[];
}KeywordInputOptions
interface KeywordInputOptions {
prompt?: string;
keywords: string[];
defaultKeyword?: string;
}StringInputOptions
interface StringInputOptions {
prompt?: string;
defaultValue?: string;
}EntityInputOptions
interface EntityInputOptions {
prompt?: string;
filter?: (entity: EntityBase) => boolean;
}Shortcuts
ShortcutMap
type ShortcutMap = Record<string, string>;Keys are shortcut strings (e.g. 'ctrl+z'), values are command names.
getDefaultShortcuts
function getDefaultShortcuts(): ShortcutMapReturns: Built-in default shortcut map.
Example:
import { getDefaultShortcuts } from 'vjmapext';
const shortcuts = getDefaultShortcuts();
console.log(shortcuts);
// { 'ctrl+z': 'undo', 'ctrl+y': 'redo', ... }