Class Camera

API to control and respond to the state of the camera within the scene.

Hierarchy

  • Camera

Properties

interactions: {
    disable: (() => void);
    enable: (() => void);
    set: ((options) => void);
}

Enable or disable the ability for the user to interact with the camera (e.g. pan, zoom, tilt, etc). This does not affect programmatic camera controls, such as set and focusOn.

// The user can no longer interact to move the camera
mapView.Camera.interactions.disable();

// The user can now interact to move the camera again
mapView.Camera.interactions.enable();

Type declaration

  • disable: (() => void)
      • (): void
      • Disable all user interactions.

        Returns void

  • enable: (() => void)
      • (): void
      • Enable all user interactions.

        Returns void

  • set: ((options) => void)
      • (options): void
      • Enable or disable specific user interactions.

        mapView.Camera.interactions.set({ zoom: false });
        

        Parameters

        Returns void

off: (<EVENT_NAME>(eventName, fn) => void)

Type declaration

    • <EVENT_NAME>(eventName, fn): void
    • Unsubscribe a function that was previously subscribed with on.

      mapView.Camera.on(E_CAMERA_EVENT.CHANGED, cameraChangedHandler);

      ...

      // Something changed and I no longer want this event to fire
      mapView.Camera.off(E_CAMERA_EVENT.CHANGED, cameraChangedHandler);

      Type Parameters

      Parameters

      • eventName: EVENT_NAME

        An E_CAMERA_EVENT that is fired when the camera changes.

      • fn: ((payload) => void)

        A function that was previously passed to on. The function must have the same reference as the function that was subscribed.

      Returns void

on: (<EVENT_NAME>(eventName, fn) => void)

Type declaration

    • <EVENT_NAME>(eventName, fn): void
    • Subscribe a function to be called when an E_CAMERA_EVENT is fired.

      const cameraChangedHandler = ({ tilt, position, zoom, rotation }) => {
      // Do something with the new values
      };
      mapView.Camera.on(E_CAMERA_EVENT.CHANGED, cameraChangedHandler);

      Type Parameters

      Parameters

      • eventName: EVENT_NAME

        An E_CAMERA_EVENT that is fired when the camera changes.

      • fn: ((payload) => void)

        A callback that gets called when the corresponding event is fired. The callback will get passed an argument with a type that's one of CAMERA_EVENT_PAYLOAD.

      Returns void

Accessors

  • get currentAnimation(): undefined | Promise<undefined>
  • The current camera animation, if any. Resolves when the animation finishes.

    Returns undefined | Promise<undefined>

  • get maxTilt(): number
  • Get the current maximum tilt angle (in radians) the camera is allowed to use.

    Returns number

  • set maxTilt(radians): void
  • Sets the maximum tilt angle (in radians) the camera is allowed to use.

    Tilt angle must be between 0 and π/2 radians. It will be clamped within this range if it exceeds it on either end.

    As tilt angle approaches π/2 radians, this will impact overall touch controls and should be used sparingly.

    Parameters

    • radians: number

    Returns void

  • get maxZoom(): number
  • Get the maximum distance (in meters) the camera is allowed to get from the ground.

    Returns number

  • set maxZoom(meters): void
  • Set the maximum distance (in meters) the camera is allowed to get from the ground.

    Parameters

    • meters: number

    Returns void

  • get minZoom(): number
  • Get the minimum distance (in meters) the camera is allowed to get to the ground.

    Returns number

  • set minZoom(meters): void
  • Set the minimum distance (in meters) the camera is allowed to get to the ground.

    Parameters

    • meters: number

    Returns void

  • get rotation(): number
  • Current Camera rotation (in radians) from north

    Returns number

  • get tilt(): number
  • Current camera tilt angle (in radians), relative to a top-down view.

    ex: 0 means the camera is facing top-down, π/2 means the camera is facing directly from the side.

    Returns number

  • get zoom(): number
  • Current Camera zoom (in meters)

    Returns number

Methods

  • Smoothly transition the camera's transform to be in a new configuration. See also set.

    const coord = mapView.venue.maps[0].createCoordinate(33.66107, 31.83911);

    // Animate the camera to be top-down at a specified coordinate
    mapView.Camera.animate({
    tilt: 0,
    position: coord,
    });

    Parameters

    Returns Promise<undefined>

    a Promise that resolves when the animation finishes, or rejects when it is cancelled.

  • Cancel the currently active Camera animation.

    Returns void

  • Convert the altitude returned by getZoom into Mercator Zoom level

    Parameters

    • altitude: number

    Returns any

  • Convert a Mercator Zoom Level to altitude, which can be used in the Camera APIs

    Parameters

    • zoomLevel: number

    Returns any

  • Animate the camera to focus on a collection of targets. To control where the targets should be placed on screen, either specify safeAreaInsets on the TFocusOnCameraOptions or call setSafeAreaInsets.

    const location = mapView.venue.locations.find((l) => l.name === "My Location")!;

    mapView.Camera.focusOn({
    polygons: location.polygons,
    nodes: location.nodes,
    });

    Parameters

    Returns Promise<unknown>

    a Promise that resolves when the animation finishes, or rejects when it is cancelled.

  • Retrieve the values previously set by setSafeAreaInsets.

    Returns TPadding

    An object defining a number of pixels from the top, left, bottom, and right of the screen.

  • Instantaneously set the camera's transform to be in a new configuration. See also animate.

    const coord = mapView.venue.maps[0].createCoordinate(33.66107, 31.83911);

    // Place the camera top-down at a specified coordinate
    mapView.Camera.set({
    tilt: 0,
    position: coord,
    });

    Parameters

    Returns void

  • Define an area of the screen that is safe for the camera. Anything outside the safe area is assumed to be covered in some way (e.g. by UI) meaning the camera will not place any map elements there when calling focusOn.

    // The top 100px of the canvas are covered by a UI element
    mapView.Camera.setSafeAreaInsets({ top: 100, left: 0, bottom: 0, right: 0});
    mapView.Camera.focusOn({ nodes });

    Parameters

    • insets: {
          bottom: number;
          left: number;
          right: number;
          top: number;
      }

      An object defining a number of pixels from the top, left, bottom, and right of the screen. Only the area within the padding defined by these pixels is considered safe.

      • bottom: number
      • left: number
      • right: number
      • top: number

    Returns void

  • Moves the Camera view in a relative direction by a given distance in meters.

    // Move the camera 50 meters up relative to the camera frame
    mapView.Camera.translate(E_CAMERA_DIRECTION.UP, 50);

    Parameters

    Returns Promise<unknown>

    a Promise that resolves when the translation animation finishes, or rejects when it is cancelled.