Draggable hotspots with swfaddress

  • Hello! Does anyone know if it's possible for the swfaddress plugin to record the movements of draggable hotspots rather than just the current view? I think I've got it working for tweeting the current view, but when I open the tweeted link, the draggable hotspots are all back at their starting positions...

    Thanks v much for any ideas.

  • No that doesn't make much sense unless you want to keep track of a bunch of variables.

    The max length of a url is 2000 characters or so. So in theory you could get by with a few. The point is WHY?

    To add the functionality, you need to have some code in your startup function to take the variables and set each hotspots ath and atv and ensure the variables of each hotspot are exported correctly. hotspot1_atv=90&hotspot2_ath=20 etc
    and then you have to parse the variables to set the right hotspot names either programatic or hard coded.

  • Thanks very much for the reply! Crikey, that sounds complicated - I'll keep on learning xml and maybe one day I'll be able to do it! When you mention parsing the variables, would that be in the parseparams action in the swfaddress.xml?
    The reason I want to do it is for a 'choose your team' picture; I have a flat pano picturing half a football pitch, and then players' names down the sides. People can drag the names of their chosen starting XI team on to the pitch and then tweet it to show people how they'd like the team to line up. I've got the hotspots working but when I try tweeting the picture, the hotspots are all back in their starting positions. Would 15 or so draggable hotspots be too many, do you think?

    Thanks again for the reply - greatly appreciated. Sometimes you can only get to a certain point by yourself and then need some help! *smile*


    (For reference, this is what I've got so far in my main xml:


    <krpano version="1.16" showerrors="true" logkey="true" onstart="startup();">
    <!-- dragable hotsots example -->


    <include url="swfaddress.xml"/>


    <plugin name="email_button"
    url="assets/images/email.png"
    align="topright"
    x="10"
    y="10"
    altonloaded="if(isphone, mul(x,2); mul(y,2); mul(scale,2));"
    onhover="showtext(Share this view via e-mail);"
    onclick="share_via_email();"
    />

    <plugin name="pinterest_button"
    url="assets/images/pinterest.png"
    align="topright"
    x="50"
    y="10"
    altonloaded="if(isphone, mul(x,2); mul(y,2); mul(scale,2));"
    onhover="showtext(Share this view on Pinterest);"
    onclick="share_on_pinterest();"
    />

    <plugin name="twitter_button"
    url="assets/images/twitter.png"
    align="topright"
    x="90"
    y="10"
    altonloaded="if(isphone, mul(x,2); mul(y,2); mul(scale,2));"
    onhover="showtext(Share this view on Twitter);"
    onclick="share_on_twitter();"
    />

    <plugin name="googleplus_button"
    url="assets/images/googleplus.png"
    align="topright"
    x="130"
    y="10"
    altonloaded="if(isphone, mul(x,2); mul(y,2); mul(scale,2));"
    onhover="showtext(Share this view on Google+);"
    onclick="share_on_googleplus();"
    />

    <plugin name="facebook_button"
    url="assets/images/facebook.png"
    align="topright"
    x="170"
    y="10"
    altonloaded="if(isphone, mul(x,2); mul(y,2); mul(scale,2));"
    onhover="showtext(Share this view on Facebook);"
    onclick="share_on_facebook();"
    />


    <action name="startup">
    delayedcall(0.1, add_scenes_to_swfaddress());
    </action>


    <scene name="scene0" title="Choose your NUFC line up for this weekend">
    <preview url="dreamteam.tiles/preview.jpg" />

    <image type="CYLINDER" hfov="1.00" vfov="0.520977" voffset="0.00" multires="true" tilesize="512" progressive="true" >
    <level tiledimagewidth="1883" tiledimageheight="981" download="view">
    <cylinder url="dreamteam.tiles/l3/%v/l3_%v_%h.jpg" />
    </level>
    <level tiledimagewidth="942" tiledimageheight="491" download="view">
    <cylinder url="dreamteam.tiles/l2/%v/l2_%v_%h.jpg" />
    </level>
    <level tiledimagewidth="512" tiledimageheight="267" download="view">
    <cylinder url="dreamteam.tiles/l1/%v/l1_%v_%h.jpg" />
    </level>
    </image>


    <style name="dragablehotspot"
    dragging="if(pressed, sub(dx,mouse.stagex,drag_adjustx); sub(dy,mouse.stagey,drag_adjusty); screentosphere(dx,dy,ath,atv); if(onDrag!==null, onDrag() ); delayedcall(0,dragging()); , if(onDragEnd!==null, onDragEnd() ); );"
    ondown="spheretoscreen(ath,atv,hotspotcenterx,hotspotcentery); sub(drag_adjustx,mouse.stagex,hotspotcenterx); sub(drag_adjusty,mouse.stagey,hotspotcentery); if(onDragStart!==null, onDragStart() ); dragging();"
    />


    <hotspot name="testimage" url="skin/krul.jpg" ath="0.4" atv="-0.2" zoom="true" keep="true" distorted="false" scale="0.008"
    style="dragablehotspot"
    />

    <hotspot
    name="testimage2" url="skin/remy.jpg" ath="0.4" atv="-0.15" zoom="true" keep="true" distorted="false" scale="0.008"
    style="dragablehotspot"
    />


    <hotspot name="testimage3" url="skin/taylor.jpg" ath="0.4" atv="-0.1" zoom="true" keep="true" distorted="false" scale="0.008"
    style="dragablehotspot"
    />

    <hotspot name="testimage4" url="skin/dejong.jpg" ath="0.4" atv="-0.05" zoom="true" keep="true" distorted="false" scale="0.008"
    style="dragablehotspot"
    />

    </scene>



    </krpano>


    And swfaddress.xml is:


    <krpano>
    <!-- Email Share Data -->
    <data name="email_url"
    content="mailto:?subject={SUBJECT}&amp;body={BODY}{URL}"/>
    <data name="email_share_subject_text"
    content="Check out this view!"/>
    <data name="email_share_body_text"
    content="I really liked this view inside VIRTUAL TOUR! %0D%0A"/>

    <!-- Facebook Share Data -->
    <data name="facebook_url"
    content="http://www.facebook.com/sharer.php?s=100&amp;p[title]={TITLE}&amp;p[url]={URL}&amp;p[images][0]={IMAGE}&amp;p[summary]={TEXT}"/>
    <data name="facebook_share_title"
    content="VIRTUAL TOUR"/>
    <data name="facebook_share_text"
    content="I really liked this view inside this virtual tour!"/>
    <data name="facebook_share_image"
    content="http://jaydee.ru/kp/sa/demo/images/fbthumb.gif"/>

    <!-- Facebook Mobile Share Data -->
    <data name="facebook_mobile_url"
    content="http://m.facebook.com/sharer.php?u={URL}&amp;t={TITLE}"/>
    <data name="facebook_mobile_share_title"
    content="VIRTUAL TOUR"/>

    <!-- Twitter Share Data -->
    <data name="twitter_url"
    content="http://twitter.com/share?url={URL}&amp;text={TEXT}"/>
    <data name="twitter_share_text"
    content="Check out this view inside VIRTUAL TOUR!"/>

    <!-- Google Plus Share Data -->
    <data name="google_plus_url"
    content="https://plus.google.com/share?url={URL}"/>

    <!-- Pinterest Share Data -->
    <data name="pinterest_url"
    content="http://pinterest.com/pin/create/button/?url={URL}&amp;description={DESCRIPTION}&amp;media={IMAGE}"/>
    <data name="pinterest_share_description"
    content="VIRTUAL TOUR description"/>
    <data name="pinterest_share_image"
    content="http://jaydee.ru/images/pinterest_thumb.png"/>

    <!-- Plugins -->
    <plugin name="swfaddress"
    url="%SWFPATH%/plugins/sa.swf"
    alturl="%SWFPATH%/plugins/sa.js"
    keep="true"
    preload="true"

    randomRoot="false"
    titlePrefix="Virtual tour: "
    titlePostfix=""

    bitlyAPIKey="R_48b308ba7da245ddbc0d6f7744f872ca"
    bitlyLogin="jaydeee"

    onURLChange=""
    onParamsChange=""
    >
    </plugin>

    <!-- Actions -->
    <action name="activatepano">
    if (%1 != null,
    if (get(action[mainloadpano].content) !== null,
    if (%2 == xml, mainloadpano(%SWFPATH%/%1), mainloadpano(%1)),
    if (%2 == xml, loadpano(%SWFPATH%/%1,null,KEEPBASE,BLEND(1)), loadscene(%1,null,KEEPBASE,BLEND(1)));
    wait(blend);
    )
    );
    </action>

    <action name="paramschangeaction">
    ifnot (plugin[swfaddress].hasparams === false, parseparams(); plugin[swfaddress].removeparams(););
    </action>

    <action name="parseparams">
    plugin[swfaddress].getParam(ath, p_ath);
    plugin[swfaddress].getParam(atv, p_atv);
    plugin[swfaddress].getParam(fov, p_fov);

    ifnot (get(p_ath), copy(p_ath, view.hlookat));
    ifnot (get(p_atv), copy(p_atv, view.vlookat));
    ifnot (get(p_fov), copy(p_fov, view.fov));

    lookto(get(p_ath), get(p_atv), get(p_fov));
    </action>

    <action name="shorten_view_url">
    plugin[swfaddress].shorten(get(plugin[swfaddress].viewurl));
    </action>

    <action name="replace_string">
    plugin[swfaddress].replace(%1, %1, %2, %3);
    </action>

    <action name="open_link">
    if (ishtml5, plugin[swfaddress].replaceampersands(get(%1), %1));
    if (ishtml5, set(data[link_target].content, '_self'), set(data[link_target].content, '_blank'));
    if (plugin[swfaddress].isiframe, set(data[link_target].content, '_top'));
    openurl(get(%1), get(data[link_target].content))));
    </action>

    <action name="add_scenes_to_swfaddress">
    set(plugin[swfaddress].onURLChange, null);
    set(plugin[swfaddress].onParamsChange, null);

    for (set(i,0), i LT scene.count, inc(i),
    if (get(scene[get(i)].url), copy(data[s.url].content, scene[get(i)].url), copy(data[s.url].content, scene[get(i)].name));
    plugin[swfaddress].addPano(get(scene[get(i)].name), get(scene[get(i)].name), true, get(data[s.url].content), get(scene[get(i)].title), get(scene[get(i)].onxmlcomplete));
    );

    set(plugin[swfaddress].onURLChange, activatepano(%PANOID%, %TYPE%));
    set(plugin[swfaddress].onParamsChange, paramschangeaction());

    plugin[swfaddress].forceDispatchURLChange();
    </action>

    <!-- Share via e-mail actions -->
    <action name="share_via_email">
    set(plugin[swfaddress].onShortenSuccess, share_url_via_email(%URL%));
    shorten_view_url();
    </action>

    <action name="share_url_via_email">
    copy(data[link].content, data[email_url].content);
    replace_string(data[link].content, '{URL}', %1);
    replace_string(data[link].content, '{SUBJECT}', get(data[email_share_subject_text].content));
    replace_string(data[link].content, '{BODY}', get(data[email_share_body_text].content));

    open_link(data[link].content);
    </action>

    <!-- Share on Facebook actions -->
    <action name="share_on_facebook">
    set(plugin[swfaddress].onShortenSuccess, share_url_on_facebook(%URL%));
    shorten_view_url();
    </action>

    <action name="share_url_on_facebook" devices="desktop">
    copy(data[link].content, data[facebook_url].content);
    replace_string(data[link].content, '{URL}', %1);
    replace_string(data[link].content, '{TITLE}', get(data[facebook_share_title].content));
    replace_string(data[link].content, '{IMAGE}', get(data[facebook_share_image].content));
    replace_string(data[link].content, '{TEXT}', get(data[facebook_share_text].content));

    open_link(data[link].content);
    </action>

    <action name="share_url_on_facebook" devices="mobile|tablet">
    copy(data[link].content, data[facebook_mobile_url].content);
    replace_string(data[link].content, '{URL}', %1);
    replace_string(data[link].content, '{TITLE}', get(data[facebook_mobile_share_title].content));

    open_link(data[link].content);
    </action>

    <!-- Share on Twitter actions -->
    <action name="share_on_twitter">
    set(plugin[swfaddress].onShortenSuccess, share_url_on_twitter(%URL%));
    shorten_view_url();
    </action>

    <action name="share_url_on_twitter">
    copy(data[link].content, data[twitter_url].content);
    replace_string(data[link].content, '{URL}', %1);
    replace_string(data[link].content, '{TEXT}', get(data[twitter_share_text].content));

    open_link(data[link].content);
    </action>

    <!-- Share on Google+ actions -->
    <action name="share_on_googleplus">
    set(plugin[swfaddress].onShortenSuccess, share_url_on_googleplus(%URL%));
    shorten_view_url();
    </action>

    <action name="share_url_on_googleplus">
    copy(data[link].content, data[google_plus_url].content);
    replace_string(data[link].content, '{URL}', %1);

    open_link(data[link].content);
    </action>

    <!-- Share on Pinterest -->
    <action name="share_on_pinterest">
    copy(data[link].content, data[pinterest_url].content);
    replace_string(data[link].content, '{URL}', get(plugin[swfaddress].viewurlescaped));
    replace_string(data[link].content, '{DESCRIPTION}', get(data[pinterest_share_description].content));
    replace_string(data[link].content, '{IMAGE}', get(data[pinterest_share_image].content));

    open_link(data[link].content);
    </action>
    </krpano>

  • Maybe it would work.

    You've got passquery parameters so its a straight drop from the url to inside krpano.

    http://www.domain.com/project/?hs1_a…v=30&hs2_ath=40 etc

    then you need an action to set your hotspot positions

    <action name="letsgo">
    if(hs1_atv,copy(hotspot[hs1].atv,hs1_atv););
    if(hs1_ath,copy(hotspot[hs1].atv,hs1_ath););
    ...........
    .....

    </action>

    You could get all slick by parsing the url names and figuring out what hotspots names so you don't have to use 30 lines of code but why bother.

    And you need to make sure when you share the address these variables are added by figuring out how swfaddress does it and adding them. I don't use swfaddress myself.

Participate now!

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