Metareal Stage Player SDK - Programming Guide
This section provides detailed guides on how to use the Metareal Stage Player SDK features.
Documentation
How To
Installation
To use the Metareal Stage Player SDK, simply reference the following Javascript file: https://stage.metareal.com/playersdk/playersdk.min.1.0.js in your web application. A non-minified version is also available for debugging purposes: https://stage.metareal.com/playersdk/playersdk.1.0.js.
Creating a Player
A player is the main object that will allow your web page to load the tour and play it back. A web application can use more than one player, to play multiple tours at the same time for example. Players must have an HTML element parent, such as a div.
To create a new player inside of an HTML element myWebApp:
let player = MetarealPlayerSDK.create( "myWebApp" );
To destroy the player, and unparent it:
MetarealPlayerSDK.destroy( player );
Loading a Tour
Tours are loaded inside player objects using the load function. The URL provided to the load function corresponds to the published URL of the tour. e.g.: https://tour.metareal.com/apps/player?asset=b8ce9219-e883-4848-9a33-abe18a9697bb. The load function takes a callback as a parameter that is called once the tour is ready to be played back.
let tourURL = "https://tour.metareal.com/apps/player?asset=b8ce9219-e883-4848-9a33-abe18a9697bb";
player.load( tourURL, () => {
console.log( "Tour is loaded" );
} );
Getting Properties
Properties are read only values that are data members of the different objects. They can be queried directly like this:
console.log( tour.name );
You can use the Data Explorer example to see what are the different properties that are available for each type of objects.
Listening to Events
Certain events are triggered when playing back, or when interacting with the tour. These events can call a callback that implements custom logic or behaviour based on the user input.
Use the Player.setEventListener To set an callback on a specific event:
function startMove( data ) {
console.log( "The user is starting to move" );
};
player.setEventListener( "startmove", startMove );
Note that you cannot set more than one callback per event type.
The types of events that are supported are:
- ready: Player is ready, all data is loaded
- startmove: The user is starting to move
- moving: The user is moving
- endmove: The user has stopped moving
- look: The user is looking at something
- roomviewpointchanged: The user has selected a new view point in the room choose
- labelclicked: The user has clicked on a label
- label2clicked: The user has clicked on a label 2.0
- label2linkclicked: The user has clicked on a label 2.0 link
- label2opened: The user has opened a label 2.0
- label2closed: The user has closed a label 2.0
- modelviewdoubleclick: The user has double clicked in the model view
- modelviewclick: The user has clicked in the model view
- modelviewcamerachange: The camera has changed in the model view
- switchview: The user has switched view
- floorplanpanoclick: The user has clicked on a panorama in the floor plan view
- floorplanroomclick: The user has clicked on a room in the floor plan view
- floorplanchangefloorclick: The user has clicked on a floor to change floors in the floor plan view
- floorplanzoom: The user zoomed in/out in the floor plan view
- floorplandrag: The user has dragged the floor plan
Controlling the Player
The player can be programmed to perform certain actions:
- startShowcase(): Start showcasing the tour that has been loaded
- setViewMode( mode ): Set the player view mode to tour, floor plan or model using the following values: "TOUR", "FLOOR PLAN", "MODEL"
- setStartingViewMode( mode ): Set the player starting view mode when the tour has been loaded to tour, floor plan or model using the following values: "TOUR", "MODEL"
- getLookAtPosition( cb ): Get the 3D coordinates of where the user is looking at. This will do a raycast on the 3D geometry and will call the callback function with the coordinates of the collision point. This is an expensive function so use it only when you really need it
- moveToPanorama( panorama, transition ): Move the user to another panorama using the specified transition. Transitions can be "teleport" or "travel"
- moveToRoomViewPoint( roomViewPoint ): Switches the user to a new view point as specified in the room chooser
- hide( element ): Hide the element in the tour, fullscreen button or vr button using the following values: "FULLSCREEN", "VR"
- show( element ): Show the element in the tour, fullscreen button or vr button using the following values: "FULLSCREEN", "VR"