AttachmentAPI

Interface AttachmentAPI

The AttachmentAPI provides basic functionalities to define additional data optionally attached to a node. This data can be of any type defined in AttachmentType and is stored in the form of a URI. The AttachmentAPI provides methods to fetch, set and remove the data.

Example: Create a new attachment with text data.

const context = webvis.getContext();

// Create a new attachment
const attachmentId = context.createAttachment(webvis.AttachmentType.TEXT);

// Set the attachment data
context.setAttachmentData(attachmentId, "hello world");

// Fetch the attachment data
await context.fetchAttachmentData(attachmentId); // returns "hello world"

Attachments can be added to nodes using the setProperty method.

Example: attaching an attachment to a node.

const context = webvis.getContext();

// Create a new attachment and set data
const attachmentId = context.createAttachment(webvis.AttachmentType.TEXT);
context.setAttachmentData(attachmentId, "hello world");

// Attach the attachment to a node
context.setProperty(nodeId, webvis.Property.ATTACHMENT, attachmentId);

// Fetch the attachment data
await context.getProperty(nodeId, webvis.Property.ATTACHMENT); // returns "hello world"

The following events are associated with the AttachmentAPI:

interface AttachmentAPI {
    createAttachment(dataType: AttachmentType): number;
    fetchAttachmentData<T = any>(attachmentID: number): Promise<T>;
    getAttachmentData<T = any>(attachmentID: number): T;
    getAttachmentDataURI(attachmentID: number): string;
    removeAttachment(attachmentID: number, safe?: boolean): RemoveState;
    setAttachmentData<T = any>(attachmentID: number, data: T): void;
    setAttachmentDataURI(attachmentID: number, dataURI: string): void;
}

Hierarchy (View Summary)

Methods

  • Fetches and returns the attachment data of the specified attachment.

    Type Parameters

    • T = any

      The data type fitting the AttachmentType of the attachment data.

    Parameters

    • attachmentID: number

      Specifies the attachment object.

    Returns Promise<T>

    The attached data.

  • Returns the attachment data.

    Type Parameters

    • T = any

    Parameters

    • attachmentID: number

      Specifies the attachment object.

    Returns T

    The attached data

    getAttachmentData is deprecated, please use fetchAttachmentData instead.

  • Returns the attachment data URI.

    Parameters

    • attachmentID: number

      Specifies the attachment object.

    Returns string

    The attachment data URI.

  • Removes the Attachment from the scene and all related snapshots.

    Triggers an AttachmentRemovedEvent.

    Parameters

    • attachmentID: number

      Specifies the attachment object.

    • Optionalsafe: boolean

      Performs a safe remove which interrupt the removal process if the attachment is part of one or more snapshots. If no safe remove, a snapshot could link to missing data. Default: false.

    Returns RemoveState

    The state of the removal process.

  • Sets the attachment data.

    Triggers an AttachmentDataChangedEvent.

    Type Parameters

    • T = any

    Parameters

    • attachmentID: number

      Specifies the attachment object.

    • data: T

      The new attachment data.

    Returns void

  • Sets the attachment data URI.

    Parameters

    • attachmentID: number

      Specifies the attachment object.

    • dataURI: string

      The attachment data URI.

    Returns void


Did you find this page useful? Please give it a rating:
Thank you for rating this page!
Any issues or feedback?
What kind of problem would you like to report?
Please tell us more about what's wrong: