This is the main class used to display a ps2 synth.
Name | Definition | Description |
---|---|---|
PS2Viewer | PS2Viewer(containerElement:node, options?: PS2ViewerOptions) | Initialize a new instance of PS2Viewer class. |
Name | Return value | Description |
---|---|---|
addEventListener(eventName, callback) | None | Register the provided callback to the specified event. |
blur() | None | Removes focus from the viewer so that it does not respond to keyboard events. |
dispose() | None | Deletes the viewer object and releases any associated resources. (Sadly it's leaking if the hidden 42 menu has been invoked: dat.gui needs to be fixed.) |
focus() | None | Applies focus to the viewer so that it responds to keyboard events. |
getCameraMode() | PS.Packet.ViewMode | Return the current camera mode of the player from the PS.Packet.ViewMode enum. (Smooth=0, Linear=1, Global=2) |
getInternal() | PS.Packet.Player | Return the internal PS.Packet.Player object (use with caution!). |
goHomeZoom() | None | If the viewer is zoomed into a seadragon image it will zoom back to the 'home' level. |
gotoCamera(camera, options) | None | Move the viewer to the specified camera on the path. You can provide 2 options: onComplete callback or speedFactor number. |
isHomeZoom() | boolean | Return if the seadragon viewer is at the home zoom level. |
isPlaying() | boolean | Return if the viewer is animating (=if the user has pressed the play button, it's also true if autoStart=true) |
load(url) | None | Load the synth from the provided url (could be local or remote) into the viewer. |
loadGuid(guid) | None | Load the synth hosted on photosynth.net. |
play(direction) | None | Start playing the synth (direction could be null or 1 or -1, null = respect last dragging direction, and 1 or -1 are used to define the default or reverse way) |
preload(url, onPreloaded) | None | Start preloading a dataset. The onPreloaded callback is fired when the dataset is preloaded with the dataset as first argument. (see example bellow). |
removeEventListener(eventName, callback) | None | Remove the callback previously registered with addEventListener. |
resize(width, height, mode) | None | Resize the viewer to the specified size. mode is a PS.Packet.ResizeMode enum: 0=Fast = css scaling only 1=Slow = resize the webgl renderer too |
setActiveDataset(dataset) | None | Change the current active dataset (swap the dataset being viewed). |
setAnimationSpeed(speed) | None | Change the animation speed. |
setCameraMode(mode) | None | Change the camera mode (mode is a PS.Packet.ViewMode enum: Smooth=0, Linear=1, Global=2) |
setPosition(qIndex) | None | Manually change the position on the path (qIndex = number from 0 to dataset.path.nbPoints) |
stop(onStopped) | None | Stop the animation of the viewer. There is a tween to stop the motion, so the optionnal onStopped callback is fired when the viewer is actually stopped. |
togglePlay(options) | None | Toggle the playing status of the viewer (between play/stop). The options object contains the direction and onStopped property with same meaning as in play and stop function. |
Name | Arguments | Description |
---|---|---|
animation-start | None | Occurs when the viewer start animating. |
animation-stop | None | Occurs when the viewer stop animating. |
annotate | Internal usage. Occurs when the user click on the annotate button. | |
camera-changed | camera, sIndex | Occurs when the viewer resting camera is changed. (First argument is a PS.Packet.Camera, Second argument is the sIndex of that camera) |
camera-mode-changed | mode | Occurs when the camera mode of the viewer is changed. (mode = PS.Packet.ViewMode enum) |
cameras-changed | sIndexA, sIndexB | Occurs when the pair of camera surrounding the virtual camera is changed. This will occur while dragging on the path |
container-transformed | Internal usage | |
dataset-loaded | dataset | Occurs when the minimal amount of data needed to render a dataset has been loaded and parsed. dataset is a PS.Packet.Dataset object. |
dataset-rendered | dataset | Occurs when the dataset is rendered (=when the webgl renderer is rendering it). dataset is a PS.Packet.Dataset object. |
enter-fullscreen | None | Occurs when entering fullscreen mode |
exit-fullscreen | None | Occurs when exiting fullscreen mode |
geometry-loaded | None | Occurs when all geometry of the synth have been loaded (the viewer has reach 100% and will start animating at this stage if autoStart=true and if the user hasn't interacted with the synth before this stage) |
imagery-loaded | None | Occurs when all HD imagery of the synth have been loaded (this will happen after geometry-loaded) |
pose-changed | None | Internal usage (trigger when the viewer is snapping to a resting frame) |
position-changed | qIndex | Occurs when the viewer is moving. The position can be off. You can fix it by calling dataset.path.fixRange(qIndex). |
resize | resizeState, resizeMode | Occurs when the viewer is resized. |
seadragon-resize | Internal usage | |
viewer-built | None | Fired when the viewer DOM is created. |
viewer-updated | None | Fired when the viewer DOM is changed (due to a call to .load() and for the intial loading). |
zoom-level-changed | isHomeZoom | Occurs when the viewer start to zoom into a seadragon image or when it comes back to the home zoom level. |
var _container = document.getElementById("viewer-container");
var _viewer = new Photosynth.PS2Viewer(_container, {
pathToWorker: "js/PS2PacketPlayer.worker.min.js"
});
_viewer.loadGuid("676195e2-64ca-43f5-80ba-a7cb7b10e3aa");
var _guid = "676195e2-64ca-43f5-80ba-a7cb7b10e3aa";
//loadGuid is ...
_viewer.loadGuid(_guid);
//... a shortcut for:
PS.API.getPS2Url(_guid, function(url) {
if (url) {
_viewer.preload(url, function(dataset) {
_viewer.setActiveDataset(dataset);
});
}
else {
//not a valid ps2 guid
}
});
var _guid = "676195e2-64ca-43f5-80ba-a7cb7b10e3aa";
var _firstCamera;
var _lastCamera;
var _viewer = new Photosynth.PS2Viewer(_container, {
pathToWorker: "js/PS2PacketPlayer.worker.min.js",
autoStart: false
});
_viewer.addEventListener("dataset-loaded", function(dataset) {
var cameras = dataset.cameras;
_firstCamera = cameras[0];
_lastCamera = cameras[cameras.length-1];
});
_viewer.addEventListener("geometry-loaded", function() {
_viewer.gotoCamera(_firstCamera, {
onComplete: function() {
_viewer.gotoCamera(_lastCamera);
}
});
});
_viewer.loadGuid(_guid);