Abstract base class for all CAD view implementations.

This class provides the foundation for rendering and interacting with CAD drawings. It manages:

  • Canvas and viewport dimensions
  • Mouse event handling and coordinate conversion
  • Entity selection and highlighting
  • View modes (selection, pan, etc.)
  • Spatial queries for entity picking
  • Hover/unhover detection with timing

Concrete implementations must provide specific rendering logic and coordinate transformations appropriate for their rendering technology (e.g., Three.js, SVG).

  • Input Management: Handles mouse events and user interactions
  • Selection: Manages selected entities and visual feedback
  • Coordinate Systems: Converts between screen and world coordinates
  • Spatial Queries: Finds entities at specific locations
  • View State: Tracks current position, zoom, and view mode
class MyView extends AcEdBaseView {
// Implement required abstract methods
get missedData() { return { fonts: {}, images: new Map() }; }
get mode() { return this._mode; }
set mode(value) { this._mode = value; }
// ... other abstract methods
}

const view = new MyView(canvasElement);
view.events.mouseMove.addEventListener(args => {
console.log('Mouse at world coords:', args.x, args.y);
});

Hierarchy (View Summary)

Constructors

  • Creates a new base view instance.

    Sets up the canvas, initializes internal state, and registers event listeners for mouse interactions and container resize events.

    Parameters

    • canvas: HTMLCanvasElement

      The HTML canvas element to render into

    • container: HTMLElement

      The HTML element to contain this viewer. The canvas element must be children element of container element.

    Returns AcEdBaseView

Properties

_canvas: HTMLCanvasElement

The HTML canvas element for rendering

_container: HTMLElement

The HTML element to contain this view

events: {
    hover: AcCmEventManager<AcEdViewHoverEventArgs>;
    mouseMove: AcCmEventManager<AcEdMouseEventArgs>;
    unhover: AcCmEventManager<AcEdViewHoverEventArgs>;
    viewChanged: AcCmEventManager<void>;
    viewResize: AcCmEventManager<AcEdViewResizedEventArgs>;
} = ...

Events fired by the view for various interactions

Type declaration

Accessors

Methods

  • Add the specified entity or entities in drawing database into the current scene and draw it or them

    Parameters

    • entity: AcDbEntity | AcDbEntity[]

      Input one or multiple entities to add into the current scene

    Returns void

  • Moves the current view to the specified 2D point at the given scale.

    Parameters

    • point: AcGeVector2dLike

      Target location in world coordinates to fly the view to.

    • Optionalscale: number

      The optional target zoom scale to apply after the transition. If not specified, the scale will not change.

    Returns void

  • Picks entities that intersect a hit-region centered at the specified point in world coordinates.

    The hit-region is defined as a square (or bounding box) centered at the input point, whose half-size is determined by the hitRadius parameter. Only entities whose geometry intersects this region are returned.

    Parameters

    • Optionalpoint: AcGeVector2dLike

      The center point of the hit-region in world coordinates. If omitted, the current cursor position is used.

    • OptionalhitRadius: number

      The half-width (in pixel size) of the hit-region around the point. It will be converted on one value in the world coordinate 'wcsHitRadius' and creates a square bounding box: [point.x ± wcsHitRadius, point.y ± wcsHitRadius]. A larger value increases the pick sensitivity. If omitted, a reasonable default is used.

    • OptionalpickOneOnly: boolean

    Returns AcEdSpatialQueryResultItemEx[]

    Return query results representing the entities that intersect the hit-region.

  • Remove the specified entity or entities from current drawing database and current scene and draw it or them

    Parameters

    • entity: AcDbEntity | AcDbEntity[]

      Input one or multiple entities to remove

    Returns void

  • Converts a point from screen coordinates to world coordinates.

    The screen coordinate system has its origin at the top-left corner of the canvas, with Y increasing downward. World coordinates use the CAD coordinate system with Y typically increasing upward.

    Parameters

    • point: AcGeVector2dLike

      Point in screen coordinates

    Returns AcGePoint2d

    Point in world coordinates

    const screenPoint = { x: 100, y: 200 }; // 100px right, 200px down
    const worldPoint = view.screenToWorld(screenPoint);
    console.log('World coordinates:', worldPoint.x, worldPoint.y);
  • Select entities intersected with the specified bounding box in the world coordinate system, add them to the current selection set, and highlight them.

    Parameters

    • box: AcGeBox2d

      Input one bounding box in the world coordinate system.

    Returns void

  • Update the specified layer in the current scene

    Parameters

    • layer: AcDbLayerTableRecord

      The layer to update

    • changes: Partial<AcDbLayerTableRecordAttrs>

      Changes made to the layer

    Returns void

  • Converts a point from world coordinates to screen coordinates.

    This is the inverse of screenToWorld(), converting from the CAD world coordinate system to screen pixel coordinates.

    Parameters

    • point: AcGeVector2dLike

      Point in world coordinates

    Returns AcGePoint2d

    Point in screen coordinates

    const worldPoint = new AcGePoint2d(10, 20); // CAD coordinates
    const screenPoint = view.worldToScreen(worldPoint);
    console.log('Screen position:', screenPoint.x, screenPoint.y);
  • Zooms the view to fit the specified bounding box with optional margin.

    This method adjusts the view's center and zoom level so that the entire specified bounding box is visible within the viewport. The margin parameter adds extra space around the bounding box to provide visual padding.

    Parameters

    • box: AcGeBox2d

      The bounding box to zoom to, in world coordinates

    • margin: number

      Additional margin around the bounding box (in world units)

    Returns void

  • Zooms the view to fit all visible entities in the current drawing.

    This method automatically calculates the bounding box of all entities currently displayed in the view and adjusts the view's center and zoom level to show the entire scene. This is useful for getting an overview of the entire drawing or after loading new content.

    This function takes effect only if the current view has finished rendering all entities. When opening a file, progressive Rendering is used to render entities incrementally. So this function will wait until all of entities rendered or a timeout occurs.

    Parameters

    • Optionaltimeout: number

      Maximum time (ms) to wait before executing zoom to fit action. Default: 0 (no timeout).

    Returns void

  • Zooms the view to fit all visible entities in the current scene.

    This method automatically calculates the bounding box of all entities currently displayed in the specified layer and adjusts the view's center and zoom level to show the entire layer. This is useful for getting an overview of the entire layer of one drawing or after loading new content.

    Parameters

    • layerName: string

      The layer name

    Returns boolean

    • Return true if zoomed to the layer successfully.