You are not logged in.

1

Thursday, April 20th 2017, 11:26pm

hotspot getcenter()

I'm getting up to speed (slowly)...

I tried the following in JS for a hotspot polygon:

var itemPos = krpano.get('hotspot[' + hsName + '].getcenter()');
--> returns null, I was expecting an object with ath and atv

var itemPosY = krpano.get('hotspot[' + hsName + '].getcenter().y');
--> returns null, I was expecting an atv value

If I use .getcenter(ath, atv) in an Action and then use krpano.get(atv) in JS all is well.

How can I do everything in JS? Is it possible? The doc seems to say that it is. (I haven't tried JS from inside an Action yet.)

Timescale

Trainee

Posts: 120

Location: Netherlands

Occupation: Archaeologist, Timescale R&D

  • Send private message

2

Sunday, April 23rd 2017, 2:51pm

Poygon ath atv

A polygon does not use ATH and ATV because it is defined by a set of points, not a single position. You can set these variables i believe, but they will not influence the polygon itself.

If you need the center of the polygon, you need to calculate it by adding all the vertical and horizontal coordinates for the polygon and divide that by the number of points. This will give you a average center of the polygon. With odd shaped poly's this does not always result in the desired effect. In this case you could manually set the desired point.

A poly point ATH and ATV looks like this :

Source code

1
2
3
4
5
6
7
hotspot[name].point[0].ath
hotspot[name].point[0].atv
hotspot[name].point[1].ath
hotspot[name].point[1].atv
hotspot[name].point[2].ath
hotspot[name].point[2].atv
etc....


And yes!, you can do it all in javascript, either within an action which looks like this :

Source code

1
2
3
4
5
6
7
	<action name="polygonCenteredWeight" type="Javascript" ><![CDATA[

	var variable = (args[1]); 
	
// your code here
	
	]]></action>


Or as a function in between the script tag or a seperate library. A combination of actionscript and JS is also possible. Sometimes it is more convenient to gather all the data in actionscript before passing it to JS.

jordi

Intermediate

Posts: 453

Location: Barcelona

Occupation: creating ideas & coding them

  • Send private message

3

Friday, November 23rd 2018, 12:42pm

Hi Kim,

probably you already found how to solve that.
any way the solution is here :

Source code

1
2
3
var hs = krpano.get("hotspot[" + hsName + "]");
var center = hs.getcenter();
console.log('ath:',center.x,'atv:',center.y);
everpano.com step beyond 360