Class Instance

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

// example of Giro3D instantiation
const instance = new Instance(viewerDiv, { crs: extent.crs() });
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

Implements

Constructors

  • Constructs a Giro3D Instance

    Parameters

    • viewerDiv: HTMLDivElement

      Where to instanciate the Three.js scene in the DOM

    • options: InstanceOptions

      Options

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

    Returns Instance

Properties

_camera: Camera
_controlFunctions?: ControlFunctions
_engine: C3DEngine
_isDisposing: boolean
_mainLoop: MainLoop
_referenceCrs: string
_resizeObserver?: ResizeObserver
_resizeTimeout?: string | number | Timeout
_scene: Scene
_threeObjects: Group<Object3DEventMap>
_viewport: HTMLDivElement

Accessors

  • get camera(): Camera
  • Gets the Camera.

    Returns Camera

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

    Returns HTMLCanvasElement

  • get engine(): C3DEngine
  • Gets the rendering engine

    Returns C3DEngine

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

    Returns boolean

  • get mainLoop(): MainLoop
  • Gets the main loop

    Returns MainLoop

  • 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 referenceCrs(): string
  • Gets the CRS used in this instance.

    Returns string

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

    Returns WebGLRenderer

  • get scene(): Scene
  • Gets the 3D Scene.

    Returns Scene

  • get threeObjects(): Group<Object3DEventMap>
  • Gets the group containing native Three.js objects.

    Returns Group<Object3DEventMap>

  • get viewport(): HTMLDivElement
  • Gets the DOM element that contains the Giro3D viewport.

    Returns HTMLDivElement

Methods

  • Parameters

    • div: HTMLDivElement

    Returns void

  • Parameters

    • div: HTMLDivElement

    Returns void

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

    Parameters

    Returns Promise<Object3D<Object3DEventMap> | Entity<EntityEventMap, EntityUserData>>

    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

    Parameters

    • type: T

      The type of event to listen to.

    • listener: EventListener<InstanceEvents[T], 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

  • 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

    Parameters

    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: MouseEvent | TouchEvent

      event can be a MouseEvent or a TouchEvent

    • target: Vector2

      The target to set with the result.

    • touchIdx: number = 0

      Touch 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: MouseEvent | TouchEvent

      event can be a MouseEvent or a TouchEvent

    • target: Vector2

      The target to set with the result.

    • touchIdx: number = 0

      Touch index when using a TouchEvent (default: 0)

    Returns Vector2

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

  • Moves the camera to look at an object.

    Parameters

    Returns void

  • Get all entities, with an optional predicate applied.

    // get all entities
    const allEntities = instance.getEntities();

    // get all entities whose name contains 'building'
    const buildings = instance.getEntities(entity => entity.name.includes('building'));

    Parameters

    Returns Entity<EntityEventMap, EntityUserData>[]

    an array containing the queried entities

  • Get all top-level objects (entities and regular THREE objects), using an optional filter predicate.

    // get all objects
    const allObjects = instance.getObjects();
    // get all object whose name includes 'foo'
    const fooObjects = instance.getObjects(obj => obj.name === 'foo');

    Parameters

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

      the optional filter predicate.

    Returns (Object3D<Object3DEventMap> | Entity<EntityEventMap, EntityUserData>)[]

    an array containing the queried objects

  • Checks if listener is added to an event type.

    Type Parameters

    Parameters

    • type: T

      The type of event to listen to.

    • listener: EventListener<InstanceEvents[T], 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: unknown = 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

    • options: PickObjectsAtOptions = {}

      Options

    Returns PickResult<unknown>[]

    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). If options.pickFeatures if true, features property may be set.

    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

    Parameters

    • type: T

      The type of the listener that gets removed.

    • listener: EventListener<InstanceEvents[T], T, Instance>

      The listener function that gets removed.

    Returns void

  • Type Parameters

    • T extends string

    Parameters

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

    Returns void

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

    Returns void

  • 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

    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.

     // 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' });

    Parameters

    • name: string

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

    • value: string

      the CRS definition, either in proj syntax, or in WKT syntax.

    Returns void

Generated using TypeDoc