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

  • 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 :

    Code
    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 :

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

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!