Overview
Photo Sphere Viewer exposes methods directly on theViewer instance. The full list is available in the API reference.
It is good practice to wait for the ready event before calling any method:
Position definitions
Methods that accept a position argument support two coordinate systems:- Spherical:
yawandpitchvalues in radians or degrees (e.g.{ yaw: Math.PI, pitch: '20deg' }) - Texture:
textureXandtextureYpixel coordinates on the source image (e.g.{ textureX: 1500, textureY: 600 })
textureFace.
Navigation
animate(options)
Returns: Animation (a Promise with an additional .cancel() method)
Smoothly rotates and zooms the view. You can target a position (yaw/pitch or textureX/textureY) and/or a zoom level.
The speed option accepts a duration in milliseconds or a revolutions-per-minute string:
stopAnimation()
Returns: PromiseLike<any>
Stops the current animation. Returns a promise that resolves once the animation has been cancelled.
rotate(position)
Immediately rotates the view to the given position without any animation.
Zoom
zoom(level)
Sets the zoom level instantly. level is a number between 0 (maximum FOV, zoomed out) and 100 (minimum FOV, zoomed in).
zoomIn([step = 1])
Increases the zoom level by step.
zoomOut([step = 1])
Decreases the zoom level by step.
getZoomLevel()
Returns: number
Returns the current zoom level between 0 and 100.
Panorama
setPanorama(panorama[, options])
Returns: Promise<boolean> — resolves to false if the loading was aborted by another call
Loads a new panorama, with an optional transition animation (enabled by default). If another load is already in progress it is aborted.
State
getPosition()
Returns: Position
Returns the current camera position as { yaw: number, pitch: number }.
getSize()
Returns: Size
Returns the current viewer size as { width: number, height: number }.
isFullscreenEnabled()
Returns: boolean
Returns true if the viewer is currently in fullscreen.
Options
setOption(option, value)
Updates a single configuration option at runtime.
The following options cannot be changed after initialization:
panorama, panoData, container, adapter, and plugins.setOptions(options)
Updates multiple options at once.
Fullscreen
enterFullscreen()
Enters fullscreen mode.
exitFullscreen()
Exits fullscreen mode.
toggleFullscreen()
Enters or exits fullscreen depending on the current state.
Keyboard
startKeyboardControl()
Enables keyboard controls manually. Normally managed automatically based on the keyboard option.
stopKeyboardControl()
Disables keyboard controls manually.
UI
createTooltip(config)
Returns: Tooltip
Creates a new tooltip. Use tooltip.move() to reposition an existing tooltip without recreating it.
showError(message)
Displays an error overlay with the given message.
hideError()
Hides the error overlay.
setCursor(cursor)
Changes the global mouse cursor. Pass null to restore the default cursor based on the mousemove setting.
needsUpdate()
Requests a single re-render of the scene on the next frame.
needsContinuousUpdate(enabled)
Enables or disables continuous rendering. Useful when displaying videos.
resize(size)
Resizes the viewer container. size is a CssSize object with width and height as CSS strings (e.g. '500px', '100%').
