Add hotspot functionality

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-10-23 09:20:32 -07:00
parent 728ebf2e44
commit 36f8cbe04b
3 changed files with 128 additions and 9 deletions

View File

@@ -34,10 +34,32 @@ class GlModelViewer extends ImageHandler {
} else {
$viewClass = 'default';
}
$modelView = $metadata['viewerConfig'][$viewClass];
$modelView = array_merge(['src' => $file->getFullUrl()], $modelView);
$modelView['style'] = 'width: 800px; height: 600px;';
$result = Html::element('model-viewer', $modelView);
if (isset($metadata['annotations'])) {
$hotspots = [];
foreach($metadata['annotations'] as $idx => $an) {
$elAnnot = Html::rawElement('div',['class' => 'HotspotAnnotation HiddenAnnotation'],$an['label']);
$hsDefault = array(
'class' => 'Hotspot',
'slot' => 'hotspot-'.($idx +1),
'onmousedown' => 'event.stopPropagation()',
'ontouchstart' => 'event.stopPropagation()',
'onclick' => 'onAnnotation(event)'
);
$attrHotspot = array_merge($hsDefault, $an);
$elHotspot = Html::rawElement('button',$attrHotspot,$elAnnot.($idx +1));
array_push($hotspots, $elHotspot);
}
}
$attrModelView = $metadata['viewerConfig'][$viewClass];
$attrModelView = array_merge(['src' => $file->getFullUrl(), 'class' => 'mv-model'], $attrModelView);
$attrModelView['style'] = 'width: 100%; height: 100%; min-height: 400px;';
$elModel = Html::rawElement('model-viewer', $attrModelView, implode($hotspots));
$attrContainer = array(
'style' => "width: 800px; height: 600px;",
'onmousedown' => 'clearAnnotations()',
'ontouchstart' => 'clearAnnotations()'
);
$result = Html::rawElement('div', $attrContainer, $elModel);
echo '<script>';
#GlModelViewer::console_log($handlerParams);
#GlModelViewer::console_log($frameParams['class']);