<!doctype html>
<html>
<head>
<title>Test Embed Illustration</title>
<meta name="description" content="Our first page" />
<script type="module">
const disableRotationInput = document.getElementById('disableRotation')
const urlInput = document.getElementById('url')
const iframe = document.getElementById('ih-embed')
const output = document.getElementById('output')
const updateUrl = () => {
iframe.src = `${urlInput.value}?${
disableRotationInput.checked ? 'DISABLE_CAMERA_ROTATION' : ''
}`
}
disableRotationInput.addEventListener('change', updateUrl)
urlInput.addEventListener('change', updateUrl)
let mouseOverHighlighted = []
let mouseClickHighlighted = []
window.addEventListener('message', function (event) {
output.textContent = JSON.stringify(event.data)
switch (event.data.type) {
case 'pointerOverGeom': {
const path = event.data.path
if (path[5] == '369-331') {
mouseOverHighlighted = path.slice(0, 5)
iframe.contentWindow.postMessage(
{
type: 'addHighlight',
key: 'mouse-over',
path: mouseOverHighlighted,
color: '#ff0000',
fill: 0.0,
},
'*',
)
}
break
}
case 'pointerLeaveGeom': {
const path = event.data.path
if (path[5] == '369-331') {
const newHighlighted = path.slice(0, 5)
if (
!newHighlighted.some(
(elem, index) => elem != mouseOverHighlighted[index],
)
) {
iframe.contentWindow.postMessage(
{
type: 'removeHighlight',
key: 'mouse-over',
path: mouseOverHighlighted,
},
'*',
)
mouseOverHighlighted = []
}
}
break
}
case 'pointerClickedOnGeom': {
const path = event.data.path
if (path[5] == '369-331') {
const newHighlighted = path.slice(0, 5)
if (
!newHighlighted.some(
(elem, index) => elem != mouseClickHighlighted[index],
)
) {
iframe.contentWindow.postMessage(
{
type: 'removeHighlight',
key: 'selection',
path: mouseClickHighlighted,
},
'*',
)
mouseClickHighlighted = []
return
}
mouseClickHighlighted = path.slice(0, 5)
iframe.contentWindow.postMessage(
{
type: 'addHighlight',
key: 'selection',
path: mouseClickHighlighted,
color: '#ffbb00',
fill: 0.2,
},
'*',
)
}
break
}
}
})
</script>
<meta name="keywords" content="html tutorial template" />
<style>
body {
background-color: linen;
}
.container {
display: flex; /* or inline-flex */
flex-direction: column;
justify-content: space-between;
padding: 10px;
}
#url {
width: 80%;
}
.wh-full {
width: 100%;
height: 100%;
}
#ih-embed {
width: calc(100% - 20px);
height: 600px;
border: none;
}
</style>
</head>
<body class="wh-full">
<h2>Embedded Illustration Example</h2>