You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, May 31st 2012, 6:07am

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.

2

Thursday, May 31st 2012, 8:40am

Hi,

see here:
http://krpano.com/docu/actions/#addhotspot

e.g.

Source code

1
2
3
4
5
addhotspot(spot1);
set(hotspot[spot1].url, 'spotimage.png');
set(hotspot[spot1].ath, 123.45);
set(hotspot[spot1].atv, -12.34);
set(hotspot[spot1].onclick, showlog(); trace('spot1 clicked'); );


best regards,
Klaus

3

Friday, June 1st 2012, 11:10pm

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?.

Posts: 1,857

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

4

Saturday, June 2nd 2012, 12:52am

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?.


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

<event onclick="screentosphere(mouse.x,mouse.y,toh,tov);trace(toh,' ',tov);" />
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

5

Monday, June 4th 2012, 7:41pm

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.

Posts: 1,857

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

6

Monday, June 4th 2012, 8:53pm

Your function addhotspot has the same name as in internal function.. Change it to something unique..

http://krpano.com/docu/actions/#addhotspot
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

7

Sunday, June 10th 2012, 5:59am

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.

Posts: 1,857

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

8

Sunday, June 10th 2012, 3:24pm

It's not clear what you are trying to do or what manages the lasthotspot variable. Can you provide more details?
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

9

Sunday, June 10th 2012, 8:36pm

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.

Posts: 1,857

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

10

Monday, June 11th 2012, 1:57am

Then that's easy ...
set(onclick, 'trace(name)');
Or showtext(get(name),style);
Etc
This uses the local scope.
And if you want you can create other attributes in your action an assign any data there for later use.
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

11

Monday, June 18th 2012, 5:11am

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.

This post has been edited 1 times, last edit by "pablo_ivan57" (Jun 18th 2012, 6:19am)


12

Wednesday, June 20th 2012, 9:04am

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.

Source code

1
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