Hello,
I have created `index.html` page. It has a simple function, which loads the hotspot written in it. The name of the function is function load_hotspots()
Now I have also added the neded code in it, but the popup is not opening, I just want to open simple HTML code from it.
Here is the code of my page, I am also attaching the screenshot of page if needed as how it looks.
HTML
<!DOCTYPE html>
<html>
<head>
<title>krpano Javascript API Examples</title>
<meta name="viewport" content="width=500, initial-scale=0.64, minimum-scale=0.64" />
<style>
body{ font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000000; -webkit-text-size-adjust:none;-moz-text-size-adjust:none;-ms-text-size-adjust:none;text-size-adjust:none; }
.button{ display:inline-block; border:1px solid gray; border-radius:1px; cursor:pointer; padding:4px 8px; margin:4px 0; user-select:none; -moz-user-select:none; }
.button:hover{ background-color:#EEEEEE; }
</style>
</head>
<body>
<h3>krpano Javascript API Examples</h3>
The krpano viewer window:
<div id="pano" style="width:480px; height:320px; border:1px solid gray;"></div>
<br>
Buttons to do something via JS:<br>
<div class="button" onclick="loadpano('pano1.xml');">load pano1.xml</div>
<div class="button" onclick="loadpano('pano2.xml');">load pano2.xml</div>
<div class="button" onclick="loadxmlstring();">load xml string</div><br>
<div class="button" onclick="randomview_set();">Set a Random view</div><br>
<div class="button" onclick="randomview_lookto();">Animated Look-to a Random view</div><br>
<div class="button" onclick="get_current_view();">Get current view</div> <span id="currentview" style="padding-left:16px; font-family:monospace;"></span><br>
<div class="button" onclick="add_hotspot();">Add a Hotspot at the current position</div>
<div class="button" onclick="remove_all_hotspots();">Remove all hotspots</div><br>
<div class="button" onclick="track_mouse();">Track mouse position</div> <span id="mousepos" style="padding-left:16px; font-family:monospace;"></span><br>
<script src="../../../krpano.js"></script>
<script>
// global krpano interface (will be set in the onready callback)
var krpano = null;
// embed the krpano viewer into the 'pano' div element
embedpano({
swf : "../../../krpano.swf", // path to flash viewer (use null if no flash fallback will be requiered)
id : "krpanoSWFObject",
xml : "test.xml",
target : "pano",
consolelog : true, // trace krpano messages also to the browser console
passQueryParameters : true, // pass query parameters of the url to krpano
onready : krpano_onready_callback
});
// callback function that will be called when krpano is embedded and ready for using
function krpano_onready_callback(krpano_interface)
{
krpano = krpano_interface;
}
// examples (called by the button onclick events)
function loadpano(xmlname)
{
if (krpano)
{
krpano.call("loadpano(" + xmlname + ", null, MERGE, BLEND(0.5));");
}
}
function loadxmlstring()
{
if (krpano)
{
var xmlstring =
'<krpano>'+
'<preview type="grid(cube,64,64,512,0xCCCCCC,0xF6F6F6,0x999999);" />'+
'<view hlookat="0" vlookat="0" fov="100" distortion="0.0" />'+
'</krpano>';
krpano.call("loadxml(" + escape(xmlstring) + ", null, MERGE, BLEND(0.5));");
}
}
function randomview_set()
{
if (krpano)
{
krpano.set("view.hlookat", Math.random() * 360.0 - 180.0 );
krpano.set("view.vlookat", Math.random() * 180.0 - 90.0 );
krpano.set("view.fov", 80.0 + Math.random() * 100.0 );
krpano.set("view.distortion", Math.random() * 1.0 );
}
}
function randomview_lookto()
{
if (krpano)
{
krpano.call("lookto(" + (Math.random() * 360.0 - 180.0) + "," + (Math.random() * 180.0 - 90.0) + "," + (80.0 + Math.random() * 100.0) + ")");
}
}
function get_current_view()
{
if (krpano)
{
var hlookat = krpano.get("view.hlookat");
var vlookat = krpano.get("view.vlookat");
var fov = krpano.get("view.fov");
var distortion = krpano.get("view.distortion");
document.getElementById("currentview").innerHTML =
'hlookat="' + hlookat.toFixed(2) + '" '+
'vlookat="' + vlookat.toFixed(2) + '" '+
'fov="' + fov.toFixed(2) + '" '+
'distortion="' + distortion.toFixed(2) + '"';
}
}
function load_hotspots() {
if (krpano) {
var hotspotsArray = [
"addhotspot(hs471720192);",
"set(hotspot[hs471720192].url, 'vtourskin_hotspot.png');",
"set(hotspot[hs471720192].ath, 0);",
"set(hotspot[hs471720192].atv, 0);",
"set(hotspot[hs471720192].distorted, true);",
"set(hotspot[hs471720192].rx, 0);",
"set(hotspot[hs471720192].ry, 0);",
"set(hotspot[hs471720192].rz, null);",
"set(hotspot[hs471720192].width, 20);",
"set(hotspot[hs471720192].height, 20);",
"set(hotspot[hs471720192].url, 'vtourskin_hotspot.png');",
// Add event listener to toggle layer visibility on click
// Modify the event listener to change visibility
"set(hotspot[hs471720192].onclick, set('layer[infoLayer_hs471720192].visible', hotspot[hs471720192].clicked ? true : false));",
];
// Create the layer with HTML content beforehand
krpano.call("addlayer(infoLayer_hs471720192);");
krpano.set("layer[infoLayer_hs471720192].html", "<p>This is some HTML code that will be shown when the hs471720192 hotspot is clicked.</p>");
krpano.set("layer[infoLayer_hs471720192].visible", false); // Initially hide the layer
// Loop through the array and execute each hotspot configuration
for (var i = 0; i < hotspotsArray.length; i++) {
krpano.call(hotspotsArray[i]);
}
}
}
// Call the load_hotspots function when the page loads
document.addEventListener("DOMContentLoaded", function () {
load_hotspots();
});
// Rest of your existing code...
function remove_all_hotspots()
{
if (krpano)
{
krpano.call("loop(hotspot.count GT 0, removehotspot(0) );");
}
}
var track_mouse_enabled = false;
var track_mouse_interval_id = null;
function track_mouse_interval_callback()
{
var mx = krpano.get("mouse.x");
var my = krpano.get("mouse.y");
var pnt = krpano.screentosphere(mx,my);
var h = pnt.x;
var v = pnt.y;
document.getElementById("mousepos").innerHTML = 'x="' + mx + '" y="' + my + '" ath="' + h.toFixed(2) + '" atv="' + v.toFixed(2) + '"';
}
function track_mouse()
{
if (krpano)
{
if (track_mouse_enabled == false)
{
// enable - call 60 times per second
track_mouse_interval_id = setInterval(track_mouse_interval_callback, 1000.0 / 60.0);
track_mouse_enabled = true;
}
else
{
// disable
clearInterval(track_mouse_interval_id);
document.getElementById("mousepos").innerHTML = "";
track_mouse_enabled = false;
}
}
}
</script>
</body>
</html>
Display More
Please help so that I am able to open the popup on clicking this hotspot