Sie sind nicht angemeldet.

1

Mittwoch, 22. April 2020, 23:52

Display hotspots only when zoomed in

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!

2

Donnerstag, 23. April 2020, 18:06

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:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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

Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von »_Matthias_« (23. April 2020, 19:31)


Beiträge: 1 117

Wohnort: Poland, Europe

Beruf: krpano developer : virtual tours : the cms4vr owner

  • Nachricht senden

3

Donnerstag, 23. April 2020, 19:08

Try this code (not tested)

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  <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>
Your own professional, online cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: youtube :: wiki.cms4vr.com

cms4vr team *thumbsup*

4

Donnerstag, 23. April 2020, 19:37

Getting this in the console with that code:
ERROR: js_show_hs - SyntaxError: Unexpected identifier

I'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)

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  <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>

5

Donnerstag, 23. April 2020, 19:42

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.

6

Donnerstag, 23. April 2020, 21:08

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.

Beiträge: 1 117

Wohnort: Poland, Europe

Beruf: krpano developer : virtual tours : the cms4vr owner

  • Nachricht senden

7

Donnerstag, 23. April 2020, 21:45

tested and works *thumbup*

Quellcode

1
2
3
4
5
6
7
8
9
10
  <events name="ev_show_hs" keep="true" onviewchange="show_hs()" />
  <action name="show_hs" scope="local" protect="true">
    for(set(i,0), i LT hotspot.count, inc(i), 
      if(global.view.fov LT 80,
        set(hotspot[get(i)].visible, true);
      ,
        set(hotspot[get(i)].visible, false);
      );
    );  
  </action>
Your own professional, online cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: youtube :: wiki.cms4vr.com

cms4vr team *thumbsup*