Constructs a Giro3D Instance
Options
const instance = new Instance({
target: 'parentElement', // The id of the <div> to attach the instance
crs: 'EPSG:3857',
});
Gets the underlying CSS2DRenderer.
Gets the canvas that this instance renders into.
Gets the rendering engine
Gets whether at least one entity is currently loading data.
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.
Gets the CRS used in this instance.
Gets the underlying WebGL renderer.
Gets the rendering options.
Note: you must call notifyChange() to take the changes into account.
Gets the group containing native Three.js objects.
Gets the DOM element that contains the Giro3D viewport.
Add THREE object or Entity to the instance.
If the object or entity has no parent, it will be added to the default tree (i.e under
.scene
for entities and under .threeObjects
for regular Object3Ds.).
If the object or entity already has a parent, then it will not be changed. Check that this
parent is present in the scene graph (i.e has the .scene
object as ancestor), otherwise it
will never be displayed.
the object to add
a promise resolved with the new layer object when it is fully initialized or rejected if any error occurred.
Adds a listener to an event type.
The type of event to listen to.
The function that gets called when the event is fired.
Fire an event type.
The event that gets fired.
Dispose of this instance object. Free all memory used.
Note: this will not dispose the following reusable objects:
controls.dispose()
inspector.detach()
Extract canvas coordinates from a mouse-event / touch-event.
event can be a MouseEvent or a TouchEvent
The target to set with the result.
Touch index when using a TouchEvent (default: 0)
canvas coordinates (in pixels, 0-0 = top-left of the instance)
Extract normalized coordinates (NDC) from a mouse-event / touch-event.
event can be a MouseEvent or a TouchEvent
The target to set with the result.
Touch index when using a TouchEvent (default: 0)
NDC coordinates (x and y are [-1, 1])
Moves the camera to look at an object.
Object to look at
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'));
Optional
filter: ((obj: Entity<EntityEventMap, EntityUserData>) => boolean)the optional filter predicate
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');
Optional
filter: ((obj: Object3D<Object3DEventMap> | Entity<EntityEventMap, EntityUserData>) => boolean)the optional filter predicate.
an array containing the queried objects
Checks if listener is added to an event type.
The type of event to listen to.
The function that gets called when the event is fired.
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)
The source(s) of the change. Might be a single object or an array.
Optional
options: { Notification options.
Optional
immediate?: booleanShould the update be immediate? If false
, the update is deferred to the
next animation frame.
Optional
needsShould we render the scene?
Return objects from some layers/objects3d under the mouse in this instance.
mouse position in window coordinates, i.e [0, 0] = top-left,
or MouseEvent
or TouchEvent
Options
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(mouseEvent)
instance.pickObjectsAt(mouseEvent, { radius: 1, where: [entity0, entity1] })
instance.pickObjectsAt(mouseEvent, { radius: 3, where: [entity0] })
Removes the entity or THREE object from the scene.
the object to remove.
Removes a listener from an event type.
The type of the listener that gets removed.
The listener function that gets removed.
Static
registerCRSRegisters 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({ crs: 'EPSG:102115' });
the short name, or EPSG code to identify this CRS.
the CRS definition, either in proj syntax, or in WKT syntax.
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.