ic-embed
allows you to use your IntoCities Virtual Tour on your website.
In general, we recommend to use the preview function to include the tour on your website. The preview function displays only a teaser with a 'Start Tour' button. When the user clicks or taps it, the fully interactive virtual tour loads. The preview function causes only a small network load, which is usually desirable. See chapter Preview.
You can also embed it directly so that the virtual tour starts right away. See chapter Embed.
This script also enables you to programmatically interact with the embedded tour, for example to change the scene. It also notifies you when the user has navigated within the tour and triggered a scene change. See information about subscribing to events and using the Tour API below.
- add an empty div element at the position you'd like to show your virtual tour.
- load the script on your website:
<script src="/path/to/ic-embed.min.js"></script>
- initialize in your Javascript
IC.preview(document.querySelector('div'), { id: 1, // change to your ID key: '...' // change to your key })
The Preview function utilizes some CSS variables. With the help of these variables, you can change the appearance: add a .ic-preview
selector to your CSS and overrule them.
See src/styles.ts
or investigate in the web developer console on your site which uses the ic-embed Preview.
Similar to Preview above, but call IC.embed
:
- add an empty div element at the position you'd like to show your virtual tour.
- load the script on your website:
<script src="/path/to/ic-embed.min.js"></script>
- initialize in your Javascript
IC.embed(document.querySelector('div'), { id: 1, // change to your ID key: '...' // change to your key })
After embedding, the iframe
element will receive events when the Virtual Tour changed.
sceneChanged
const iframe = document.querySelector('iframe')
iframe.addEventListener('sceneChanged', (event) => {
const details = event.detail
console.log('sceneChanged', details)
})
For the tour API to work, the iframe must have been loaded (e.g. the start button in Preview has been clicked or the virtual has been embedded via IC.embed
).
If the tour has been embedded directly, you can get access to the api via the embed object with embed.tour
.
If using the preview function and have just the reference to preview
, access the tour API via: preview.embed.tour
Please note: an API call can lead to an event in return. Make sure not to end in a loop.
Parameter | Type | Required? | Description |
---|---|---|---|
sceneId |
String | yes | Name of the scene to display. |
ath |
Number/String | no | horizontal view direction |
atv |
Number/String | no | vertical view direction |
Returns an object containing the current URL parameters of the tour, which can contain sceneId
, ath
, atv
and z
(= zoom).
There are many possibilities to build a great user experience with your tour. The virtual tour will help you tremendously to showcase your location.
When you want the Virtual Tour to change, you can use the API to do so.
[Your Website] ------------> [Virtual Tour]
Events communicate from the Virtual Tour to your website.
[Your Website] <------------ [Virtual Tour]
It's up to you if and how to handle them.
In conjunction with Turbolinks you can keep the instance of the Virtual Tour but change current page on your site*.
*Be aware of the problem of keeping an <iframe>
active during navigation. Use this Turbolinks version until the PR gets merged to work around that.
This script relies on Window.postMessage which is widely supported.
We do not support the IE11.
ic-embed is written in Typescript. The build is a bundled script (created with browserify) which is minified. The generated JS is tested with Jest. The files are formatted with prettier.
- Checkout the repo and
yarn install
. - To run the tests:
yarn test
or build and bundle:yarn build
. - See other
"scripts"
to run inpackage.json
.
When developing, yarn test --watch
watches for changes and runs the tests automatically.