google / marzipano

A 360° media viewer for the modern web.
http://www.marzipano.net
Apache License 2.0
2k stars 998 forks source link

Externally link into each scene with unique lookto view parameters #349

Open 79pxls opened 4 years ago

79pxls commented 4 years ago

Hi, I have a pano with 3 scenes. Each scene has 4 embedded hotspots that link to external html pages on the same server.

I am able to link back to the scene I came from but I would like to be able to set lookto view parameters so the user will be facing the embedded hotspot they clicked instead of the preset initial view.

Any help would be greatly appreciated. I'm down to "donate" for a working code example. :)

Thanks!

joostvp commented 4 years ago

I already left it in the google group, but here for the github community; Add the following code to the end of your data.js file;

function findGetParameter(parameterName) {
    var result = null,
        tmp = [];
    location.search
        .substr(1)
        .split("&")
        .forEach(function (item) {
          tmp = item.split("=");
          if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
        });
    return result;
}

  var lSelectedScene = -1; //no scene selected yet
if (findGetParameter("scene") != null)
{
lSelectedScene = findGetParameter("scene");
if (findGetParameter("pitch") != null)
{
APP_DATA.scenes[lSelectedScene].initialViewParameters.pitch = findGetParameter("pitch");
}
if (findGetParameter("yaw") != null)
{
APP_DATA.scenes[lSelectedScene].initialViewParameters.yaw = findGetParameter("yaw");
}
if (findGetParameter("fov") != null)
{
APP_DATA.scenes[lSelectedScene].initialViewParameters.fov = findGetParameter("fov");
}
}

Now from an external url call: yourindexfile.html?scene=0&pitch=-0.80745305603870435&yaw=1.33213231&fov=1.23131132123 In the url set the scene, pitch, yaw and fov.

The script will override the initialViewParamaters when called like this.

Good luck and let me know if it worked!

greetz, Joost

gamebeaker commented 2 months ago

@79pxls I had the problem and created a little tool to help me: https://github.com/gamebeaker/marzipano-hotspot-view