Note: The Matterport Web Component is currently in public beta - interface and syntax are subject to change. Please email developer@matterport.com with any suggestions or questions.
The Matterport Web Component (NPM package name: @matterport/webcomponent
) is a Web Component (custom HTML element) that encapsulates the Matterport experience in a single DOM element:
<!-- Create a full 3D viewer on your site -->
<matterport-viewer m="SxQL3iGyoDo"></matterport-viewer>
You can use the web component as a full replacement for the iframe-based SDK bundle. Read the quick installation instructions, check out advanced usage tips, or continue to the tutorial to learn more.
Quick Installation
- Install package:
- Yarn:
yarn add @matterport/webcomponent three
- NPM:
npm install @matterport/webcomponent three
- Yarn:
- Install static assets (replace
YOUR_STATIC_ASSETS_DIR
with your static assets dir):- Yarn:
yarn matterport-assets YOUR_STATIC_ASSETS_DIR
- NPM:
npx matterport-assets YOUR_STATIC_ASSETS_DIR
- Yarn:
import @matterport/webcomponent
in your JS/TS- Add a
<matterport-viewer>
to your HTML. Add them
attribute with the SID of the model you want to use. - To use the SDK:
- Add the application-key attribute with the value set to your SDK key
- Either:
- Wait for the
playingPromise
:const viewer = document.querySelector('matterport-viewer'); const mpSdk = await viewer.playingPromise;
- OR listen for the
mpSdkPlaying
event:const viewer = document.querySelector('matterport-viewer'); viewer.addEventListener('mpSdkPlaying', async (evt) => { const mpSdk = evt.detail.mpSdk; /* do something with mpSdk... */ });
- Wait for the
Full example
(Make sure you complete steps 1 and 2 above first!)
HTML:
<matterport-viewer
m="YOUR_MODEL_SID"
application-key="YOUR_APPLICATION_KEY"
></matterport-viewer>
JS/TS:
import '@matterport/webcomponent';
const viewer = document.querySelector('matterport-viewer');
viewer.addEventListener('mpSdkPlaying', async (evt) => {
const mpSdk = evt.detail.mpSdk;
/* do something with mpSdk... */
});