Add hotspot dinamically inside the viewer

  • Hello everyone, I was wondering how could I add a new hotspot inside the viewer. For example, I want the user to click on any empty spot inside the viewer, and then a hotspot would be created at that place. What actions or code should I read in order to achieve this? Thanks a lot.

  • Ok thanks, now I had another doubt while I was adding the hotspot, how could I retrieve the event's click position... The documentation states that we have the events tag, where I would set the actions that I want to execute on the onclick event, but then I would like to do some processing wich the data of the position where I clicked on the screen, ath, atw... etc. Is there a way to retrieve this?.

  • Ok thanks, now I had another doubt while I was adding the hotspot, how could I retrieve the event's click position... The documentation states that we have the events tag, where I would set the actions that I want to execute on the onclick event, but then I would like to do some processing wich the data of the position where I clicked on the screen, ath, atw... etc. Is there a way to retrieve this?.

    https://krpano.com/docu/xml/#events.onclick
    https://krpano.com/docu/actions/#mouse.x
    https://krpano.com/docu/actions/#screentosphere

    <event onclick="screentosphere(mouse.x,mouse.y,toh,tov);trace(toh,' ',tov);" />

  • Hi, well thanks for the help... thanks to that I managed to create a piece of code that should be able to add a hotspot dinamically bu clicking on the screen. However I got a flash error when loading the pano. Specifically it says:

    ArgumentError: Error #1063: Argument count mismatch on krpano::krpano_base/addhotspot(). Expected 1, got 2.
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at krpano::krpano_interface/call()
    at kflashpano::Kactionqueue/process_actions()
    at kflashpano::Kactionqueue/parse_action()
    at kflashpano::Kactionqueue/callaction()
    at krpano::krpano_interface/call()
    at krpano::krpano_events/dispatch()
    at kflashpano::Kpano/mouse_click()


    <action name="addHotspot">
    set(lastCreatedHotspotName,"");
    txtadd(get(lastCreatedHotspotName),'newHotspot',get(serial));
    set(serial,get(serial)+1);
    addhotspot(get(lastCreatedHotspotName));
    set(hotspot[get(lastCreatedHotspotName)].url, 'hotspots/hotspotInfoImage.png');
    set(hotspot[get(lastCreatedHotspotName)].ath, %1);
    set(hotspot[get(lastCreatedHotspotName)].atv, %2);
    set(infoText,"");
    txtadd(get(infoText),get(lastCreatedHotspotName),' clicked');
    set(hotspot[get(lastCreatedHotspotName)].onclick, showlog(); trace(get(infoText)); );
    </action>

    <events onclick="addHotspot(toh,tov)">
    </events>

    What I'm doing wrong? according to documentation that's the correct way to call an action, right?
    Thanks a lot.

  • Thank you, now I faced some trouble when adding them dinamically, the problem is that I need to retrieve the name that was used to create the hotspot when the user clicks on it. However since the name is dinamically generated, the variable that's used to create the names changes after that. For example the following code:

    <action name="addNewHotspot">txtadd(lastCreatedHotspotName,'newHotspot',get(serial));
    addhotspot(get(lastCreatedHotspotName));
    set(hotspot[get(lastCreatedHotspotName)].url, '%CURRENTXML%/hotspot/hotspotInfoImage.png');
    screentosphere(mouse.x,mouse.y,toh,tov);
    set(hotspot[get(lastCreatedHotspotName)].ath, get(toh));
    set(hotspot[get(lastCreatedHotspotName)].atv, get(tov));
    showtext(get(lastCreatedHotspotName),infostyle);
    set(hotspot[get(lastCreatedHotspotName)].onclick , showtext(get(lastCreatedHotspotName),infostyle););
    add(serial,1);
    </action>

    The problem is that when a hotspot is clicked, it's showing the lastCreatedHostpotName value ( In other words tha last generated name)... how could I modify it in order to retrieve the clicked hotspot's name? Thank you so much.

  • Ok, lastCreatedHotspotName is a variable that stores a generated name, based on the serial value that's passed to the viewer from js code. This is done in order to allow the user to click anywhere inside the panorama and create a new hotspot dinamically (Administration of hotspots in other words).
    the lastCreatedHotspotName is used in order for the txtAdd action to have a variable to alter; wich would be the first parameter it receives.
    The problem is the following use case, let's suppose the user adds a new hotspot and at that moment serial has the value of 1. The action code that I posted then creates a new name 'newHotspot1' in this case, and adds a new hotspot to the viewer with that name. Finally it adds 1 to the serial value, so that the next generated name is newHotspot2 (to avoid replacing the hotspot that was already created). However, the problem comes because I need a way to identify wich one was clicked when the user clicks on the hotspot, and the only way to do that is (I think...) is by getting it's name. so that I could retrieve the selected hotspot ath or atv, or whatever I need. That's what I'm trying to do with that code on the hotspot's onclick event. But since lastCreatedHotspotName was already altered ( Let's say the user created 5 hotspots after that and the actualName is newHotspot6). When I click on it, the hotspot it's showing 'newHotspot6', but what I actually need it the 'newHotspot1' value.
    Hope now it's more clear what I'm trying to achieve.
    Thanks a lot.

  • I tried it, but it didn't worked...

    set(hotspot[get(lastCreatedHotspotName)].onclick , showtext('get(lastCreatedHotspotName)',infostyle));

    even this retrieves the altered variable when clicking on the hotspot. I need a way to retrieve the variable's value and then convert it to string, and put that result on the hotspot's onclick event. Is there a way to do this?

    EDIT: Sorry it worked with the name variable, I got confused. Thanks a lot.

  • Hi,

    EDIT: Sorry it worked with the name variable, I got confused. Thanks a lot.

    you can create and store any kind of variables directly at the hotspot,
    e.g.

    Code
    set(hotspot[get(lastCreatedHotspotName)].anything, ...);

    and when calling code directly from an hotspot event like onclick, you can access these variables directly (just 'varname') without specifying the full path like 'hotspot[name].varname'.

    So in your case it's possible to use the directly the name of the hotspot itself, but you could also store other informations direct at the hotspot and then access them.

    Best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!