Class DefaultBoardCamera

The default board camera. This is basically the same as the BaseCamera class. But it's observable.

Implements

Camera

Other

  • Parameters

    • viewPortWidth: number = 1000

      The width of the viewport. (The width of the canvas in css pixels)

    • viewPortHeight: number = 1000

      The height of the viewport. (The height of the canvas in css pixels)

    • position: Point = { x: 0, y: 0 }

      The position of the camera in the world coordinate system

    • rotation: number = 0

      The rotation of the camera in the world coordinate system

    • zoomLevel: number = 1

      The zoom level of the camera

    • boundaries: Boundaries = { min: { x: -10000, y: -10000 }, max: { x: 10000, y: 10000 } }

      The boundaries of the camera in the world coordinate system

    • zoomLevelBoundaries: ZoomLevelLimits = { min: 0.1, max: 10 }

      The boundaries of the zoom level of the camera

    • rotationBoundaries: RotationLimits = undefined

      The boundaries of the rotation of the camera

    Returns DefaultBoardCamera

  • The order of the transformation is as follows:

    1. Scale (scale the context using the device pixel ratio)
    2. Translation (move the origin of the context to the center of the canvas)
    3. Rotation (rotate the context negatively the rotation of the camera)
    4. Zoom (scale the context using the zoom level of the camera)
    5. Translation (move the origin of the context to the position of the camera in the context coordinate system)

    Parameters

    • devicePixelRatio: number

      The device pixel ratio of the canvas

    • alignCoorindate: boolean

      Whether to align the coordinate system to the camera's position

    Returns TransformMatrix

    The transformation matrix

  • Inverts a point from the world coordinate system to the viewport coordinate system.

    Parameters

    • point: Point

      The point in the world coordinate system.

    Returns Point

    The point in the viewport coordinate system.

  • This function is used to set the position of the camera.This function has a guard that checks if the destination point is within the boundaries of the camera. If the destination point is not within the boundaries, the function will return false and the position will not be updated. If the destination point is within the boundaries, the function will return true and the position will be updated.

    Parameters

    • destination: Point

      The destination point of the camera.

    Returns boolean

    Whether the position is set successfully.