Class Instance

The instance is the core component of Giro3D. It encapsulates the 3D scene, the current camera and one or more entities, such as a Map.

// example of Giro3D instantiation
const instance = new Instance(viewerDiv, extent.crs(), {camera: camera})
const map = new Map('myMap', null, extent, { maxSubdivisionLevel: 10 });
instance.add(map);

// Bind an event listener on double click
instance.domElement.addEventListener('dblclick', dblClickHandler);

// Get the camera position
const myvector = instance.camera.camera3D.position;
// Set the camera position
instance.camera.camera3D.position.set(newPosition);
instance.camera.camera3D.lookAt(lookAt);

Hierarchy

  • EventDispatcher
    • Instance

Constructors

  • Constructs a giro3d Instance

    Parameters

    • viewerDiv: HTMLElement

      Where to instanciate the Three.js scene in the DOM

    • Optional options: {
          crs: string;
          renderer: {
              alpha: boolean;
              antialias: boolean;
              checkShaderErrors: boolean;
              clearColor: number | boolean;
              colorManagement: boolean;
              logarithmicDepthBuffer: boolean;
              renderer: WebGLRenderer;
          };
          scene3D: Scene;
      }

      Optional properties.

      • crs: string

        The coordinate reference system of the scene. Must be a cartesian system.

      • renderer: {
            alpha: boolean;
            antialias: boolean;
            checkShaderErrors: boolean;
            clearColor: number | boolean;
            colorManagement: boolean;
            logarithmicDepthBuffer: boolean;
            renderer: WebGLRenderer;
        }

        The options for the renderer.

        • alpha: boolean
        • antialias: boolean
        • checkShaderErrors: boolean
        • clearColor: number | boolean
        • colorManagement: boolean
        • logarithmicDepthBuffer: boolean
        • renderer: WebGLRenderer
      • scene3D: Scene

        The Three.js Scene instance to use, otherwise a default one will be constructed

    Returns Instance

    Example

    const opts = {
    camera: camera,
    crs = exent.crs()
    };
    const instance = new Instance(viewerDiv, opts);
    const map = new Map('myMap', null, extent, { maxSubdivisionLevel: 10 });
    instance.add(map);

Properties

_allLayersAreReadyCallback: (() => void)

Type declaration

    • (): void
    • Returns void

_changeSources: Set<any>
_controlFunctions: {
    eventListener: (() => void);
    frameRequester: (() => any);
}

Type declaration

  • eventListener: (() => void)
      • (): void
      • Returns void

  • frameRequester: (() => any)
      • (): any
      • Returns any

_delayedFrameRequesterRemoval: any[]
_frameRequesters: {}

Type declaration

    _isDisposing: boolean
    _objects: any[]
    _resizeTimeout: Timeout
    _viewport: HTMLElement
    camera: Camera

    Gets the current camera.

    controls: object
    engine: C3DEngine
    isDebugMode: boolean
    mainLoop: MainLoop
    referenceCrs: string
    resizeObserver: ResizeObserver
    scene: Scene
    scene2D: Scene
    threeObjects: Group<Object3DEventMap>

    Accessors

    • get domElement(): HTMLCanvasElement
    • Gets the canvas that this instance renders into.

      Returns HTMLCanvasElement

    • get loading(): boolean
    • Gets whether at least one entity is currently loading data.

      Returns boolean

    • get progress(): number
    • Gets the progress (between 0 and 1) of the processing of the entire instance. This is the average of the progress values of all entities. Note: This value is only meaningful is loading is true. Note: if no entity is present in the instance, this will always return 1.

      Returns number

    • get renderer(): WebGLRenderer
    • Gets the underlying WebGL renderer.

      Returns WebGLRenderer

    • get renderingOptions(): RenderingOptions
    • Gets the rendering options.

      Note: you must call notifyChange() to take the changes into account.

      Returns RenderingOptions

    • get viewport(): HTMLElement
    • Gets the DOM element that contains the giro3d viewport.

      Returns HTMLElement

    Methods

    • Parameters

      • div: any

      Returns void

    • Returns void

    • Parameters

      • div: any

      Returns void

    • Add THREE object or Entity to the instance. The entity id must be unique.

      Parameters

      Returns Promise<any>

      a promise resolved with the new layer object when it is fully initialized or rejected if any error occurred.

      Example

      // Add Map to instance
      instance.add(new Map('myMap', myMapExtent));

      // Add Map to instance then wait for the map to be ready.
      instance.add(new Map('myMap', myMapExtent)).then(...);
    • Adds a listener to an event type.

      Type Parameters

      • T extends string

      Parameters

      • type: T

        The type of event to listen to.

      • listener: EventListener<any, T, Instance>

        The function that gets called when the event is fired.

      Returns void

    • Type Parameters

      • T extends string

      Parameters

      • type: T
      • listener: EventListener<{}, T, Instance>

      Returns void

    • Add a frame requester to this instance.

      FrameRequesters can activate the MainLoop update by calling instance.notifyChange.

      Parameters

      • when: string

        decide when the frameRequester should be called during the update cycle. Can be any of module:core/Instance.INSTANCE_EVENTS INSTANCE_EVENTS.

      • frameRequester: FrameRequester

        this function will be called at each MainLoop update with the time delta between last update, or 0 if the MainLoop has just been relaunched.

      Returns void

    • Convert canvas coordinates to normalized device coordinates (NDC).

      Parameters

      • canvasCoords: Vector2

        (in pixels, 0-0 = top-left of the instance)

      • target: Vector2

        The target to set with the result.

      Returns Vector2

      NDC coordinates (x and y are [-1, 1])

    • Fire an event type.

      Type Parameters

      • T extends string

      Parameters

      • event: any

        The event that gets fired.

      Returns void

    • Dispose of this instance object. Free all memory used.

      Note: this will not dispose the following reusable objects:

      • controls (because they can be attached and detached). For THREE.js controls, use controls.dispose()
      • Inspectors, use inspector.detach()
      • any openlayers objects, please see their individual documentation

      Returns void

    • Extract canvas coordinates from a mouse-event / touch-event

      Parameters

      • event: Event

        event can be a MouseEvent or a TouchEvent

      • target: Vector2

        The target to set with the result.

      • touchIdx: number = 0

        finger index when using a TouchEvent (default: 0)

      Returns Vector2

      canvas coordinates (in pixels, 0-0 = top-left of the instance)

    • Extract normalized coordinates (NDC) from a mouse-event / touch-event

      Parameters

      • event: Event

        event can be a MouseEvent or a TouchEvent

      • target: Vector2

        The target to set with the result.

      • touchIdx: number = 0

        finger index when using a TouchEvent (default: 0)

      Returns Vector2

      NDC coordinates (x and y are [-1, 1])

    • Execute a frameRequester.

      Parameters

      • when: string

        attach point of this (these) requester(s). Can be any of module:core/Instance.INSTANCE_EVENTS INSTANCE_EVENTS.

      • dt: number

        delta between this update and the previous one

      • updateLoopRestarted: boolean

        true if giro3d' update loop just restarted

      • Rest ...args: any[]

        optional arguments

      Returns void

    • Parameters

      • obj: any

      Returns void

    • Get all objects, with an optional filter applied. The filter method allows to get only a subset of objects

      Parameters

      • Optional filter: ((arg0) => boolean)

        the optional query filter

          • (arg0): boolean
          • Parameters

            • arg0: object

            Returns boolean

      Returns object[]

      an array containing the queried objects

      Example

      // get all objects
      instance.getObjects();
      // get one layer with id
      instance.getObjects(obj => obj.id === 'itt');
    • Checks if listener is added to an event type.

      Type Parameters

      • T extends string

      Parameters

      • type: T

        The type of event to listen to.

      • listener: EventListener<any, T, Instance>

        The function that gets called when the event is fired.

      Returns boolean

    • Type Parameters

      • T extends string

      Parameters

      • type: T
      • listener: EventListener<{}, T, Instance>

      Returns boolean

    • Convert NDC coordinates to canvas coordinates

      Parameters

      • ndcCoords: Vector2

        the NDC coordinates to convert

      • target: Vector2

        The target to set with the result.

      Returns Vector2

      canvas coordinates (in pixels, 0-0 = top-left of the instance)

    • Notifies the scene it needs to be updated due to changes exterior to the scene itself (e.g. camera movement). non-interactive events (e.g: texture loaded)

      Parameters

      • changeSource: any = undefined

        the source of the change

      • needsRedraw: boolean = true

        indicates if notified change requires a full scene redraw.

      Returns void

    • Return objects from some layers/objects3d under the mouse in this instance.

      Parameters

      • mouseOrEvt: Vector2 | MouseEvent | TouchEvent

        mouse position in window coordinates, i.e [0, 0] = top-left, or MouseEvent or TouchEvent

      • Optional options: {
            filter: object;
            limit: number;
            radius: number;
            where: any[];
        } = {}

        Optional properties.

        • filter: object

          Filter on resulting objects

        • limit: number

          maximum number of objects to return

        • radius: number

          picking will happen in a circle centered on mouseOrEvt. Radius is the radius of this circle, in pixels

        • where: any[]

          where to look for objects. Can be either: empty (= look in all layers with type === 'geometry'), layer ids or layers or a mix of all the above.

      Returns any[]

      an array of objects. Each element contains at least an object property which is the Object3D under the cursor. Then depending on the queried layer/source, there may be additionnal properties (coming from THREE.Raycaster for instance).

      Example

      instance.pickObjectsAt({ x, y })
      instance.pickObjectsAt({ x, y }, { radius: 1, where: ['wfsBuilding'] })
      instance.pickObjectsAt({ x, y }, { radius: 3, where: ['wfsBuilding', myLayer] })
    • Removes the entity or THREE object from the scene.

      Parameters

      Returns void

    • Removes a listener from an event type.

      Type Parameters

      • T extends string

      Parameters

      • type: T

        The type of the listener that gets removed.

      • listener: EventListener<any, T, Instance>

        The listener function that gets removed.

      Returns void

    • Type Parameters

      • T extends string

      Parameters

      • type: T
      • listener: EventListener<{}, T, Instance>

      Returns void

    • Remove a frameRequester. The effective removal will happen either later; at worst it'll be at the beginning of the next frame.

      Parameters

      • when: string

        attach point of this requester. Can be any of module:core/Instance.INSTANCE_EVENTS INSTANCE_EVENTS.

      • frameRequester: FrameRequester

        the frameRequester to remove

      Returns void

    • Removes a THREE controls previously added. The controls won't be disable.

      Returns void

    • This function allows to use three.js controls (files in examples/{js,jsm}/controls folder of THREE.js) into giro3d 3D scene.

      Giro3d supports the controls that check the following assumptions:

      • they fire 'change' events when something happens
      • they have an update method

      Parameters

      • controls: object

        An instance of a THREE controls

      Returns void

    • Registers a new coordinate reference system. This should be done before creating the instance. This method can be called several times to add multiple CRS.

      Parameters

      • name: string

        the short name, or EPSG code to identify this CRS.

      • value: string

        the proj string describing this CRS.

      Returns void

      Static

      Example

      // register the CRS first...
      Instance.registerCRS(
      'EPSG:102115',
      '+proj=utm +zone=5 +ellps=clrk66 +units=m +no_defs +type=crs');

      // ...then create the instance
      const instance = new Instance(div, { crs: 'EPSG:102115' });

    Generated using TypeDoc