Class: Viewer
viewer.Viewer
classdesc
The Viewer object represents the navigable image viewer.
Create a Viewer by specifying a container, client ID, image ID and
other options. The viewer exposes methods and events for programmatic
interaction.
In the case of asynchronous methods, MapillaryJS returns promises to the results. Notifications are always emitted through JavaScript events.
#
Hierarchy↳
Viewer
#
Implements#
Constructors#
constructor• new Viewer(options
)
Create a new viewer instance.
description
The Viewer
object represents the street imagery
viewer on your web page. It exposes methods and properties that
you can use to programatically change the view, and fires
events as users interact with it.
It is possible to initialize the viewer with or without a ID.
When you want to show a specific image in the viewer from the start you should initialize it with a ID.
When you do not know the first image ID at implementation
time, e.g. in a map-viewer application you should initialize
the viewer without a ID and call moveTo
instead.
When initializing with an ID the viewer is bound to that ID until the image for that ID has been successfully loaded. Also, a cover with the image of the ID will be shown. If the data for that ID can not be loaded because the ID is faulty or other errors occur it is not possible to navigate to another ID because the viewer is not navigable. The viewer becomes navigable when the data for the ID has been loaded and the image is shown in the viewer. This way of initializing the viewer is mostly for embedding in blog posts and similar where one wants to show a specific image initially.
If the viewer is initialized without a ID (with null or
undefined) it is not bound to any particular ID and it is
possible to move to any ID with viewer.moveTo("<my-image-id>")
.
If the first move to a ID fails it is possible to move to another
ID. The viewer will show a black background until a move
succeeds. This way of intitializing is suited for a map-viewer
application when the initial ID is not known at implementation
time.
example
var viewer = new Viewer({ accessToken: "<my-access-token>", container: "<my-container-id>",});
#
ParametersName | Type | Description |
---|---|---|
options | ViewerOptions | Optional configuration object specifying Viewer's and the components' initial setup. |
#
Overrides#
Defined in#
Events#
on• on(type
, handler
): void
Fired when the viewing direction of the camera changes.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("bearing", function() { console.log("A bearing event has occurred.");});
#
ParametersName | Type |
---|---|
type | "bearing" |
handler | (event : ViewerBearingEvent ) => void |
#
Returnsvoid
#
Implementation of#
Overrides#
Defined in• on(type
, handler
): void
Fired when a pointing device (usually a mouse) is pressed and released at the same point in the viewer.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("click", function() { console.log("A click event has occurred.");});
#
ParametersName | Type |
---|---|
type | "click" |
handler | (event : ViewerMouseEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when the right button of the mouse is clicked within the viewer.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("contextmenu", function() { console.log("A contextmenu event has occurred.");});
#
ParametersName | Type |
---|---|
type | "contextmenu" |
handler | (event : ViewerMouseEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when the viewer is loading data.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("dataloading", function() { console.log("A loading event has occurred.");});
#
ParametersName | Type |
---|---|
type | "dataloading" |
handler | (event : ViewerDataLoadingEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when a pointing device (usually a mouse) is clicked twice at the same point in the viewer.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("dblclick", function() { console.log("A dblclick event has occurred.");});
#
ParametersName | Type |
---|---|
type | "dblclick" |
handler | (event : ViewerMouseEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when the viewer's vertical field of view changes.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("fov", function() { console.log("A fov event has occurred.");});
#
ParametersName | Type |
---|---|
type | "fov" |
handler | (event : ViewerStateEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired immediately after all necessary resources have been downloaded and the first visually complete rendering of the viewer has occurred.
This event is only fired for viewer configurations where the WebGL context is created, i.e. not when using the fallback functionality only.
example
example
// Set an event listenerviewer.on('load', function(event) { console.log('A load event has occured');});
#
ParametersName | Type |
---|---|
type | "load" |
handler | (event : ViewerLoadEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when a pointing device (usually a mouse) is pressed within the viewer.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("mousedown", function() { console.log("A mousedown event has occurred.");});
#
ParametersName | Type |
---|---|
type | "mousedown" |
handler | (event : ViewerMouseEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when a pointing device (usually a mouse) is moved within the viewer.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("mousemove", function() { console.log("A mousemove event has occurred.");});
#
ParametersName | Type |
---|---|
type | "mousemove" |
handler | (event : ViewerMouseEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when a pointing device (usually a mouse) leaves the viewer's canvas.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("mouseout", function() { console.log("A mouseout event has occurred.");});
#
ParametersName | Type |
---|---|
type | "mouseout" |
handler | (event : ViewerMouseEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when a pointing device (usually a mouse) is moved onto the viewer's canvas.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("mouseover", function() { console.log("A mouseover event has occurred.");});
#
ParametersName | Type |
---|---|
type | "mouseover" |
handler | (event : ViewerMouseEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when a pointing device (usually a mouse) is released within the viewer.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("mouseup", function() { console.log("A mouseup event has occurred.");});
#
ParametersName | Type |
---|---|
type | "mouseup" |
handler | (event : ViewerMouseEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when the viewer motion stops and it is in a fixed position with a fixed point of view.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("moveend", function() { console.log("A moveend event has occurred.");});
#
ParametersName | Type |
---|---|
type | "moveend" |
handler | (event : ViewerStateEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when the motion from one view to another start, either by changing the position (e.g. when changing image) or when changing point of view (e.g. by interaction such as pan and zoom).
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("movestart", function() { console.log("A movestart event has occurred.");});
#
ParametersName | Type |
---|---|
type | "movestart" |
handler | (event : ViewerStateEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when the navigable state of the viewer changes.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("navigable", function() { console.log("A navigable event has occurred.");});
#
ParametersName | Type |
---|---|
type | "navigable" |
handler | (event : ViewerNavigableEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired every time the viewer navigates to a new image.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("image", function() { console.log("A image event has occurred.");});
#
ParametersName | Type |
---|---|
type | "image" |
handler | (event : ViewerImageEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when the viewer's position changes.
description
The viewer's position changes when transitioning
between images.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("position", function() { console.log("A position event has occurred.");});
#
ParametersName | Type |
---|---|
type | "position" |
handler | (event : ViewerStateEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when the viewer's point of view changes. The point of view changes when the bearing, or tilt changes.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("pov", function() { console.log("A pov event has occurred.");});
#
ParametersName | Type |
---|---|
type | "pov" |
handler | (event : ViewerStateEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when the viewer's reference position changes.
The reference position specifies the origin in the viewer's topocentric coordinate system.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("reference", function(reference) { console.log("A reference event has occurred.");});
#
ParametersName | Type |
---|---|
type | "reference" |
handler | (event : ViewerReferenceEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired when the viewer is removed. After this event is emitted you must not call any methods on the viewer.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("remove", function() { console.log("A remove event has occurred.");});
#
ParametersName | Type |
---|---|
type | "remove" |
handler | (event : ViewerStateEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired every time the sequence edges of the current image changes.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("sequenceedges", function() { console.log("A sequenceedges event has occurred.");});
#
ParametersName | Type |
---|---|
type | "sequenceedges" |
handler | (event : ViewerNavigationEdgeEvent ) => void |
#
Returnsvoid
#
Defined in• on(type
, handler
): void
Fired every time the spatial edges of the current image changes.
example
// Initialize the viewervar viewer = new Viewer({ // viewer options });// Set an event listenerviewer.on("spatialedges", function() { console.log("A spatialedges event has occurred.");});
#
ParametersName | Type |
---|---|
type | "spatialedges" |
handler | (event : ViewerNavigationEdgeEvent ) => void |
#
Returnsvoid
#
Defined in#
Accessors#
dataProvider• get
dataProvider(): IDataProvider
Returns the data provider used by the viewer to fetch all contracts, ents, and buffers.
description
The viewer's data provider can be set
upon initialization through the ViewerOptions.dataProvider
property.
#
ReturnsThe viewer's data provider.
#
Implementation of#
Defined in#
isNavigable• get
isNavigable(): boolean
Return a boolean indicating if the viewer is in a navigable state.
description
The navigable state indicates if the viewer supports
moving, i.e. calling the moveTo and moveDir
methods or changing the authentication state,
i.e. calling setAccessToken. The viewer will not be in a navigable
state if the cover is activated and the viewer has been supplied a ID.
When the cover is deactivated or the viewer is activated without being
supplied a ID it will be navigable.
#
Returnsboolean
Boolean indicating whether the viewer is navigable.
#
Implementation of#
Defined in#
Methods#
activateCombinedPanningâ–¸ activateCombinedPanning(): void
Activate the combined panning functionality.
description
The combined panning functionality is active by default.
#
Returnsvoid
#
Implementation ofIViewer.activateCombinedPanning
#
Defined in#
activateComponentâ–¸ activateComponent(name
): void
Activate a component.
example
viewer.activateComponent("marker");
#
ParametersName | Type | Description |
---|---|---|
name | ComponentName | FallbackComponentName | Name of the component which will become active. |
#
Returnsvoid
#
Implementation of#
Defined in#
activateCoverâ–¸ activateCover(): void
Activate the cover (deactivates all other components).
#
Returnsvoid
#
Implementation of#
Defined in#
addCustomRendererâ–¸ addCustomRenderer(renderer
): void
Add a custom renderer to the viewer's rendering pipeline.
description
During a render pass, custom renderers
are called in the order they were added.
#
ParametersName | Type | Description |
---|---|---|
renderer | ICustomRenderer | The custom renderer implementation. |
#
Returnsvoid
#
Implementation of#
Defined in#
attachCustomCameraControlsâ–¸ attachCustomCameraControls(controls
): void
Attach custom camera controls to control the viewer's camera pose and projection.
description
Custom camera controls allow the API user
to move the viewer's camera freely and define the camera
projection. These camera properties are used
to render the viewer 3D scene directly into the
viewer's GL context.
Only a single custom camera control instance can be attached to the viewer. A new custom camera control instance can be attached after detaching a previous one.
Set the viewer's camera controls to CameraControls.Custom to activate attached camera controls. If CameraControls.Custom has already been set when a custom camera control instance is attached, it will be activated immediately.
Set the viewer's camera controls to any other CameraControls mode to deactivate the custom camera controls.
throws
{MapillaryError} When camera controls attached
are already attached to the viewer.
#
ParametersName | Type | Description |
---|---|---|
controls | ICustomCameraControls | The custom camera controls implementation. |
#
Returnsvoid
#
Implementation ofIViewer.attachCustomCameraControls
#
Defined in#
deactivateCombinedPanningâ–¸ deactivateCombinedPanning(): void
Deactivate the combined panning functionality.
description
Deactivating the combined panning functionality
could be needed in scenarios involving sequence only navigation.
#
Returnsvoid
#
Implementation ofIViewer.deactivateCombinedPanning
#
Defined in#
deactivateComponentâ–¸ deactivateComponent(name
): void
Deactivate a component.
example
viewer.deactivateComponent("pointer");
#
ParametersName | Type | Description |
---|---|---|
name | ComponentName | FallbackComponentName | Name of component which become inactive. |
#
Returnsvoid
#
Implementation of#
Defined in#
deactivateCoverâ–¸ deactivateCover(): void
Deactivate the cover (activates all components marked as active).
#
Returnsvoid
#
Implementation of#
Defined in#
detachCustomCameraControlsâ–¸ detachCustomCameraControls(): Promise
<ICustomCameraControls
>
Detach a previously attached custom camera control instance from the viewer.
description
If no custom camera control instance
has previously been attached, calling this method
has no effect.
Already attached custom camera controls need to be detached before attaching another custom camera control instance.
#
ReturnsPromise
<ICustomCameraControls
>
#
Implementation ofIViewer.detachCustomCameraControls
#
Defined in#
fireâ–¸ fire(type
, event
): void
#
ParametersName | Type |
---|---|
type | "bearing" |
event | ViewerBearingEvent |
#
Returnsvoid
#
Implementation of#
OverridesEventEmitter.fire
#
Defined inâ–¸ fire(type
, event
): void
#
ParametersName | Type |
---|---|
type | "dataloading" |
event | ViewerDataLoadingEvent |
#
Returnsvoid
#
Implementation ofIViewer.fire
#
OverridesEventEmitter.fire
#
Defined inâ–¸ fire(type
, event
): void
#
ParametersName | Type |
---|---|
type | "navigable" |
event | ViewerNavigableEvent |
#
Returnsvoid
#
Implementation ofIViewer.fire
#
OverridesEventEmitter.fire
#
Defined inâ–¸ fire(type
, event
): void
#
ParametersName | Type |
---|---|
type | "image" |
event | ViewerImageEvent |
#
Returnsvoid
#
Implementation ofIViewer.fire
#
OverridesEventEmitter.fire
#
Defined inâ–¸ fire(type
, event
): void
#
ParametersName | Type |
---|---|
type | "sequenceedges" | "spatialedges" |
event | ViewerNavigationEdgeEvent |
#
Returnsvoid
#
Implementation ofIViewer.fire
#
OverridesEventEmitter.fire
#
Defined inâ–¸ fire(type
, event
): void
#
ParametersName | Type |
---|---|
type | "reference" |
event | ViewerReferenceEvent |
#
Returnsvoid
#
Implementation ofIViewer.fire
#
OverridesEventEmitter.fire
#
Defined inâ–¸ fire(type
, event
): void
#
ParametersName | Type |
---|---|
type | "fov" | "moveend" | "movestart" | "position" | "pov" | "remove" |
event | ViewerStateEvent |
#
Returnsvoid
#
Implementation ofIViewer.fire
#
OverridesEventEmitter.fire
#
Defined inâ–¸ fire(type
, event
): void
#
ParametersName | Type |
---|---|
type | "click" | "contextmenu" | "dblclick" | "mousedown" | "mousemove" | "mouseout" | "mouseover" | "mouseup" |
event | ViewerMouseEvent |
#
Returnsvoid
#
Implementation ofIViewer.fire
#
OverridesEventEmitter.fire
#
Defined in#
getBearingâ–¸ getBearing(): Promise
<number
>
Get the bearing of the current viewer camera.
description
The bearing depends on how the camera
is currently rotated and does not correspond
to the compass angle of the current image if the view
has been panned.
Bearing is measured in degrees clockwise with respect to north.
example
viewer.getBearing().then(b => { console.log(b); });
#
ReturnsPromise
<number
>
Promise to the bearing of the current viewer camera.
#
Implementation of#
Defined in#
getCameraControlsâ–¸ getCameraControls(): Promise
<CameraControls
>
Get the viewer's camera control mode.
description
The camera control mode determines
how the camera is controlled when the viewer
receives pointer and keyboard input.
example
viewer.getCameraControls().then(c => { console.log(c); });
#
ReturnsPromise
<CameraControls
>
controls - Camera control mode.
#
Implementation of#
Defined in#
getCanvasâ–¸ getCanvas(): HTMLCanvasElement
Returns the viewer's canvas element.
description
This is the element onto which the viewer renders
the WebGL content.
#
ReturnsHTMLCanvasElement
The viewer's canvas element, or null or not initialized.
#
Implementation of#
Defined in#
getCanvasContainerâ–¸ getCanvasContainer(): HTMLDivElement
Returns the HTML element containing the viewer's canvas element.
description
This is the element to which event bindings for viewer
interactivity (such as panning and zooming) are attached.
#
ReturnsHTMLDivElement
The container for the viewer's canvas element.
#
Implementation of#
Defined in#
getCenterâ–¸ getCenter(): Promise
<number
[]>
Get the basic coordinates of the current image that is at the center of the viewport.
description
Basic coordinates are 2D coordinates on the [0, 1] interval
and have the origin point, (0, 0), at the top left corner and the
maximum value, (1, 1), at the bottom right corner of the original
image.
example
viewer.getCenter().then(c => { console.log(c); });
#
ReturnsPromise
<number
[]>
Promise to the basic coordinates of the current image at the center for the viewport.
#
Implementation of#
Defined in#
getComponentâ–¸ getComponent<TComponent
>(name
): TComponent
Get a component.
example
var pointerComponent = viewer.getComponent("pointer");
#
Type parametersName | Type |
---|---|
TComponent | extends Component <ComponentConfiguration , TComponent > |
#
ParametersName | Type | Description |
---|---|---|
name | ComponentName | FallbackComponentName | Name of component. |
#
ReturnsTComponent
The requested component.
#
Implementation of#
Defined in#
getContainerâ–¸ getContainer(): HTMLElement
Returns the viewer's containing HTML element.
#
ReturnsHTMLElement
The viewer's container.
#
Implementation of#
Defined in#
getFieldOfViewâ–¸ getFieldOfView(): Promise
<number
>
Get the viewer's current vertical field of view.
description
The vertical field of view rendered on the viewer canvas
measured in degrees.
example
viewer.getFieldOfView().then(fov => { console.log(fov); });
#
ReturnsPromise
<number
>
Promise to the current field of view of the viewer camera.
#
Implementation of#
Defined in#
getImageâ–¸ getImage(): Promise
<Image
>
Get the viewer's current image.
example
viewer.getImage().then(image => { console.log(image.id); });
#
ReturnsPromise
<Image
>
Promise to the current image.
#
Implementation of#
Defined in#
getPointOfViewâ–¸ getPointOfView(): Promise
<PointOfView
>
Get the viewer's current point of view.
example
viewer.getPointOfView().then(pov => { console.log(pov); });
#
ReturnsPromise
<PointOfView
>
Promise to the current point of view of the viewer camera.
#
Implementation of#
Defined in#
getPositionâ–¸ getPosition(): Promise
<LngLat
>
Get the viewer's current position
example
viewer.getPosition().then(pos => { console.log(pos); });
#
ReturnsPromise
<LngLat
>
Promise to the viewers's current position.
#
Implementation of#
Defined in#
getReferenceâ–¸ getReference(): Promise
<LngLatAlt
>
Get the viewer's current reference position.
description
The reference position specifies the origin in
the viewer's topocentric coordinate system.
example
viewer.getReference().then(reference => { console.log(reference); });
#
ReturnsPromise
<LngLatAlt
>
Promise to the reference position.
#
Implementation of#
Defined in#
getZoomâ–¸ getZoom(): Promise
<number
>
Get the image's current zoom level.
example
viewer.getZoom().then(z => { console.log(z); });
#
ReturnsPromise
<number
>
Promise to the viewers's current zoom level.
#
Implementation of#
Defined in#
hasCustomCameraControlsâ–¸ hasCustomCameraControls(controls
): boolean
Check if a controls instance is the camera controls that are currently attached to the viewer.
#
ParametersName | Type | Description |
---|---|---|
controls | ICustomCameraControls | Camera controls instance. |
#
Returnsboolean
Value indicating whether the controls instance is currently attached.
#
Implementation ofIViewer.hasCustomCameraControls
#
Defined in#
hasCustomRendererâ–¸ hasCustomRenderer(rendererId
): boolean
Check if a custom renderer has been added to the viewer's rendering pipeline.
#
ParametersName | Type |
---|---|
rendererId | string |
#
Returnsboolean
Value indicating whether the customer renderer has been added.
#
Implementation of#
Defined in#
moveDirâ–¸ moveDir(direction
): Promise
<Image
>
Navigate in a given direction.
throws
If the current image does not have the edge direction
or the edges has not yet been cached.
throws
Propagates any IO errors to the caller.
throws
When viewer is not navigable.
throws
CancelMapillaryError When a subsequent move request
is made before the move dir call has completed.
example
viewer.moveDir(NavigationDirection.Next).then( image => { console.log(image); }, error => { console.error(error); });
#
ParametersName | Type | Description |
---|---|---|
direction | NavigationDirection | Direction in which which to move. |
#
ReturnsPromise
<Image
>
Promise to the image that was navigated to.
#
Implementation of#
Defined in#
moveToâ–¸ moveTo(imageId
): Promise
<Image
>
Navigate to a given image ID.
throws
Propagates any IO errors to the caller.
throws
When viewer is not navigable.
throws
CancelMapillaryError When a subsequent
move request is made before the move to ID call has completed.
example
viewer.moveTo("<my-image-id>").then( image => { console.log(image); }, error => { console.error(error); });
#
ParametersName | Type | Description |
---|---|---|
imageId | string | Id of the image to move to. |
#
ReturnsPromise
<Image
>
Promise to the image that was navigated to.
#
Implementation of#
Defined in#
offâ–¸ off(type
, handler
): void
Unsubscribe from an event by its name.
#
ParametersName | Type |
---|---|
type | "bearing" |
handler | (event : ViewerBearingEvent ) => void |
#
Returnsvoid
#
Implementation of#
Overrides#
Defined inâ–¸ off(type
, handler
): void
#
ParametersName | Type |
---|---|
type | "dataloading" |
handler | (event : ViewerDataLoadingEvent ) => void |
#
Returnsvoid
#
Implementation ofIViewer.off
#
OverridesEventEmitter.off
#
Defined inâ–¸ off(type
, handler
): void
#
ParametersName | Type |
---|---|
type | "navigable" |
handler | (event : ViewerNavigableEvent ) => void |
#
Returnsvoid
#
Implementation ofIViewer.off
#
OverridesEventEmitter.off
#
Defined inâ–¸ off(type
, handler
): void
#
ParametersName | Type |
---|---|
type | "image" |
handler | (event : ViewerImageEvent ) => void |
#
Returnsvoid
#
Implementation ofIViewer.off
#
OverridesEventEmitter.off
#
Defined inâ–¸ off(type
, handler
): void
#
ParametersName | Type |
---|---|
type | "sequenceedges" | "spatialedges" |
handler | (event : ViewerNavigationEdgeEvent ) => void |
#
Returnsvoid
#
Implementation ofIViewer.off
#
OverridesEventEmitter.off
#
Defined inâ–¸ off(type
, handler
): void
#
ParametersName | Type |
---|---|
type | "reference" |
handler | (event : ViewerReferenceEvent ) => void |
#
Returnsvoid
#
Implementation ofIViewer.off
#
OverridesEventEmitter.off
#
Defined inâ–¸ off(type
, handler
): void
#
ParametersName | Type |
---|---|
type | "fov" | "moveend" | "movestart" | "position" | "pov" | "remove" |
handler | (event : ViewerStateEvent ) => void |
#
Returnsvoid
#
Implementation ofIViewer.off
#
OverridesEventEmitter.off
#
Defined inâ–¸ off(type
, handler
): void
#
ParametersName | Type |
---|---|
type | "click" | "contextmenu" | "dblclick" | "mousedown" | "mousemove" | "mouseout" | "mouseover" | "mouseup" |
handler | (event : ViewerMouseEvent ) => void |
#
Returnsvoid
#
Implementation ofIViewer.off
#
OverridesEventEmitter.off
#
Defined in#
projectâ–¸ project(lngLat
): Promise
<number
[]>
Project geodetic coordinates to canvas pixel coordinates.
description
The geodetic coordinates may not always correspond to pixel
coordinates, e.g. if the geodetic coordinates have a position behind the
viewer camera. In the case of no correspondence the returned value will
be null
.
If the distance from the viewer camera position to the provided
longitude-latitude is more than 1000 meters null
will be returned.
The projection is performed from the ground plane, i.e. the altitude with respect to the ground plane for the geodetic point is zero.
Note that whenever the camera moves, the result of the method will be different.
example
viewer.project({ lat: 0, lng: 0 }) .then(pixelPoint => { if (!pixelPoint) { console.log("no correspondence"); }
console.log(pixelPoint); });
#
ParametersName | Type | Description |
---|---|---|
lngLat | LngLat | Geographical coordinates to project. |
#
ReturnsPromise
<number
[]>
Promise to the pixel coordinates corresponding to the lngLat.
#
Implementation of#
Defined in#
projectFromBasicâ–¸ projectFromBasic(basicPoint
): Promise
<number
[]>
Project basic image coordinates for the current image to canvas pixel coordinates.
description
The basic image coordinates may not always correspond to a
pixel point that lies in the visible area of the viewer container. In the
case of no correspondence the returned value can be null
.
example
viewer.projectFromBasic([0.3, 0.7]) .then(pixelPoint => { console.log(pixelPoint); });
#
ParametersName | Type | Description |
---|---|---|
basicPoint | number [] | Basic images coordinates to project. |
#
ReturnsPromise
<number
[]>
Promise to the pixel coordinates corresponding to the basic image point.
#
Implementation of#
Defined in#
removeâ–¸ remove(): void
Clean up and release all internal resources associated with this viewer.
description
This includes DOM elements, event bindings, and
WebGL resources.
Use this method when you are done using the viewer and wish to ensure that it no longer consumes browser resources. Afterwards, you must not call any other methods on the viewer.
fires
remove
example
viewer.remove();
#
Returnsvoid
#
Implementation of#
Defined in#
removeCustomRendererâ–¸ removeCustomRenderer(rendererId
): void
Remove a custom renderer from the viewer's rendering pipeline.
#
ParametersName | Type |
---|---|
rendererId | string |
#
Returnsvoid
#
Implementation of#
Defined in#
resizeâ–¸ resize(): void
Detect the viewer's new width and height and resize it manually.
description
The components will also detect the viewer's
new size and resize their rendered elements if needed.
When the ViewerOptions.trackResize option is set to true, the viewer will automatically resize when the browser window is resized. If any other custom behavior is preferred, the option should be set to false and the Viewer.resize method should be called on demand.
example
viewer.resize();
#
Returnsvoid
#
Implementation of#
Defined in#
setAccessTokenâ–¸ setAccessToken(accessToken?
): Promise
<void
>
Set an access token for authenticated API requests of protected resources.
The token may be a user access token or a client access token.
description
When the supplied user token is null or undefined,
any previously set user bearer token will be cleared and the
viewer will make unauthenticated requests.
Calling setAccessToken aborts all outstanding move requests. The promises of those move requests will be rejected with a CancelMapillaryError the rejections need to be caught.
Calling setAccessToken also resets the complete viewer cache so it should not be called repeatedly.
throws
When viewer is not navigable.
example
viewer.setAccessToken("<my access token>") .then(() => { console.log("user token set"); });
#
ParametersName | Type |
---|---|
accessToken? | string |
#
ReturnsPromise
<void
>
Promise that resolves after token is set.
#
Implementation of#
Defined in#
setCameraControlsâ–¸ setCameraControls(controls
): void
Set the viewer's camera control mode.
description
The camera control mode determines
how the camera is controlled when the viewer
receives pointer and keyboard input.
Changing the camera control mode is not possible when the slider component is active and attempts to do so will be ignored.
example
viewer.setCameraControls(CameraControls.Street);
#
ParametersName | Type | Description |
---|---|---|
controls | CameraControls | Camera control mode. |
#
Returnsvoid
#
Implementation of#
Defined in#
setCenterâ–¸ setCenter(center
): void
Set the basic coordinates of the current image to be in the center of the viewport.
description
Basic coordinates are 2D coordinates on the [0, 1] interval
and has the origin point, (0, 0), at the top left corner and the
maximum value, (1, 1), at the bottom right corner of the original
image.
example
viewer.setCenter([0.5, 0.5]);
#
ParametersName | Type |
---|---|
center | number [] |
#
Returnsvoid
#
Implementation of#
Defined in#
setFieldOfViewâ–¸ setFieldOfView(fov
): void
Set the viewer's current vertical field of view.
description
Sets the vertical field of view rendered
on the viewer canvas measured in degrees. The value
will be clamped to be able to set a valid zoom level
based on the projection model of the current image and
the viewer's current render mode.
example
viewer.setFieldOfView(45);
#
ParametersName | Type | Description |
---|---|---|
fov | number | Vertical field of view in degrees. |
#
Returnsvoid
#
Implementation of#
Defined in#
setFilterâ–¸ setFilter(filter?
): Promise
<void
>
Set the filter selecting images to use when calculating the spatial edges.
description
The following filter types are supported:
Comparison
["==", key, value]
equality: image[key] = value
["!=", key, value]
inequality: image[key] ≠value
["<", key, value]
less than: image[key] < value
["<=", key, value]
less than or equal: image[key] ≤ value
[">", key, value]
greater than: image[key] > value
[">=", key, value]
greater than or equal: image[key] ≥ value
Set membership
["in", key, v0, ..., vn]
set inclusion: image[key] ∈ {v0, ..., vn}
["!in", key, v0, ..., vn]
set exclusion: image[key] ∉ {v0, ..., vn}
Combining
["all", f0, ..., fn]
logical AND
: f0 ∧ ... ∧ fn
A key must be a string that identifies a property name of a
simple Image property, i.e. a key of the FilterKey
type. A value must be a string, number, or
boolean. Strictly-typed comparisons are used. The values
f0, ..., fn
of the combining filter must be filter expressions.
Clear the filter by setting it to null or empty array.
Commonly used filter properties (see the Image class documentation for a full list of properties that can be used in a filter) are shown the the example code.
example
// Examplesviewer.setFilter(["==", "cameraType", "spherical"]);viewer.setFilter([">=", "capturedAt", <my-time-stamp>]);viewer.setFilter(["in", "sequenceId", "<sequence-id-1>", "<sequence-id-2>"]);
#
ParametersName | Type |
---|---|
filter? | FilterExpression |
#
ReturnsPromise
<void
>
Promise that resolves after filter is applied.
#
Implementation of#
Defined in#
setRenderModeâ–¸ setRenderMode(renderMode
): void
Set the viewer's render mode.
example
viewer.setRenderMode(RenderMode.Letterbox);
#
ParametersName | Type | Description |
---|---|---|
renderMode | RenderMode | Render mode. |
#
Returnsvoid
#
Implementation of#
Defined in#
setTransitionModeâ–¸ setTransitionMode(transitionMode
): void
Set the viewer's transition mode.
example
viewer.setTransitionMode(TransitionMode.Instantaneous);
#
ParametersName | Type | Description |
---|---|---|
transitionMode | TransitionMode | Transition mode. |
#
Returnsvoid
#
Implementation of#
Defined in#
setZoomâ–¸ setZoom(zoom
): void
Set the image's current zoom level.
description
Possible zoom level values are on the [0, 3] interval.
Zero means zooming out to fit the image to the view whereas three
shows the highest level of detail.
example
viewer.setZoom(2);
#
ParametersName | Type |
---|---|
zoom | number |
#
Returnsvoid
#
Implementation of#
Defined in#
triggerRerenderâ–¸ triggerRerender(): void
Trigger the rendering of a single frame.
description
Use this method with custom renderers to
force the viewer to rerender when the custom content
changes. Calling this multiple times before the next
frame is rendered will still result in only a single
frame being rendered.
#
Returnsvoid
#
Implementation of#
Defined in#
unprojectâ–¸ unproject(pixelPoint
): Promise
<LngLat
>
Unproject canvas pixel coordinates to geodetic coordinates.
description
The pixel point may not always correspond to geodetic
coordinates. In the case of no correspondence the returned value will
be null
.
The unprojection to a lngLat will be performed towards the ground plane, i.e. the altitude with respect to the ground plane for the returned lngLat is zero.
example
viewer.unproject([100, 100]) .then(lngLat => { console.log(lngLat); });
#
ParametersName | Type | Description |
---|---|---|
pixelPoint | number [] | Pixel coordinates to unproject. |
#
ReturnsPromise
<LngLat
>
Promise to the lngLat corresponding to the pixel point.
#
Implementation of#
Defined in#
unprojectToBasicâ–¸ unprojectToBasic(pixelPoint
): Promise
<number
[]>
Unproject canvas pixel coordinates to basic image coordinates for the current image.
description
The pixel point may not always correspond to basic image
coordinates. In the case of no correspondence the returned value will
be null
.
example
viewer.unprojectToBasic([100, 100]) .then(basicPoint => { console.log(basicPoint); });
#
ParametersName | Type | Description |
---|---|---|
pixelPoint | number [] | Pixel coordinates to unproject. |
#
ReturnsPromise
<number
[]>
Promise to the basic coordinates corresponding to the pixel point.