Is there a simple way to limit hotspots to only show at specific zoom levels? I'm putting together a Gigapixel right now and I'd rather not show the hotspots when the user is fully zoomed out. Just wondering if anyone has done this and has an example. Thanks!
Display hotspots only when zoomed in
-
-
I havent tried it but I believe you can use the current field of view https://krpano.com/docu/xml/#view.fov to control a the visible variable so that it changes its value at a threshold of your choice https://krpano.com/docu/xml/#layer.visible .
Roughly like:
Code
Display More<action name="determineshowhotspot"> if(view.fov GT 80, set(hotspot[button].visible, false)); if(view.fov LT 79, set(hotspot[button].visible, true)); </action> events onviewchanged= "determineshowhotspot" /> <hotspot name="button" url="hotspots/buttonimage.png" frame="0" ath="0" atv="20" scale="1" onclick="loadscene(closerview,null,MERGE,BLEND(1))" />
pardon the edits
-
Try this code (not tested)
Code
Display More<events name="ev_show_hs" keep="true" onviewchange="js_show_hs(get(global.view.fov))" /> <action name="js_show_hs" type="Javascript"><![CDATA[ var fovx = args[1]; var hotspotarray = krpano.get("hotspot").getArray(); for (var i=0; i < hotspotarray.length; i++) { var hs = hotspotarray[i]; if(fovx LT 80) { hs.visible = true; } else { hs.visible = false; } } ]]></action>
-
Getting this in the console with that code:
ERROR: js_show_hs - SyntaxError: Unexpected identifierI've tried with a basic action to set the visibility, but it doesn't seem to update the status of the hotspot. I'm assuming maybe it's because nothing is reloading.
Try this code (not tested)
Code
Display More<events name="ev_show_hs" keep="true" onviewchange="js_show_hs(get(global.view.fov))" /> <action name="js_show_hs" type="Javascript"><![CDATA[ var fovx = args[1]; var hotspotarray = krpano.get("hotspot").getArray(); for (var i=0; i < hotspotarray.length; i++) { var hs = hotspotarray[i]; if(fovx LT 80) { hs.visible = true; } else { hs.visible = false; } } ]]></action>
-
I've tried with a basic action to "set" the visibility, but it doesn't seem to update on the fly.
If you want to dig deeper, as to why your basic action fails to update the hotspot I recommend turning on debugmode, assigning a logkey and spreading some debugvar(varname) or also debugvar("yourstring") here and there so you can see what works and what doesn’t.
I've tried (and updated) mine above and it works. It may impact rendering performance.
-
Thanks so much! When I used a trace with debug mode enabled, I confirmed my suspicion that since I am using a flat gigapixel, the FOV values were decimals. Once I had the right numbers, it started working as expected. I then added another action prior to the set to loop through all hotspots so that every spot in the scene turns off at the desired zoom level. Works great.
-
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!