You are not logged in.

mindlessboss

Professional

  • "mindlessboss" started this thread

Posts: 1,082

Location: Russia, Kaliningrad

  • Send private message

1

Friday, January 20th 2012, 6:36am

Get URL to current vew

Hi!
i want to share javascript code (get variables from URL, make url to current view)
enjoy

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<script>
	var krpano = document.getElementById("krpanoSWFObject");
	function gotoscene(sc) {
		var scene = sc; var ath = "0"; var atv = "0"; var fov = "100";
		var vars = window.location.search.split("&");
		for(j = 0; j < vars.length; j++){
			if (vars[j].search("scene=") > 0) { scene = vars[j].replace("?scene=",""); }
			if (vars[j].search("ath=") > 0) { ath = vars[j].replace("?ath=","") }	
			if (vars[j].search("atv=") > 0) { atv = vars[j].replace("?atv=",""); }
			if (vars[j].search("fov=") > 0) { fov = vars[j].replace("?fov=",""); }
		}
		krpano.call("loadscene(" + scene +  ")");
		krpano.call("lookto(" + ath + "," + atv + "," + fov + ")"); 
	}
	function getlink() {
		var scene = krpano.get("xml.scene");
		var ath = krpano.get("view.hlookat").toFixed(2);
		var atv = krpano.get("view.vlookat").toFixed(2);
		var fov = krpano.get("view.fov").toFixed(2);
		var link = "?scene=" + scene + "&?ath=" + ath + "&?atv=" + atv + "&?fov=" + fov;
		link = window.location.protocol + window.location.pathname  + link;
		alert(link);
	}
</script>



In this example I show how you can get variables from url ( example url: http://domen.com/tour.html?scene=name&?a…?atv=5&?fov=100 )
in gotoscene function you can egt variables from url
scene = name, ath = 20, atv = 5, fov = 100;
and use it with krpano.call as you want.

getlink function create link variable as http://domen.com/tour.html?scene=current…nt_hlooat&?atv= current_vlooat&?fov=current_fov

Hope it help to somebody
Andrey
VRAP - desktop VR content player based on krpano.
Common tasks in one place in one click! Discussion thread
DOWNLOAD for MAC
DOWNLOAD for WIN

mindlessboss

Professional

  • "mindlessboss" started this thread

Posts: 1,082

Location: Russia, Kaliningrad

  • Send private message

2

Friday, January 20th 2012, 10:06am

Oh, sorry
this part must be

link = window.location.protocol + "//" + window.location.hostname + window.location.port + window.location.pathname + link;



Andrey *thumbup*
VRAP - desktop VR content player based on krpano.
Common tasks in one place in one click! Discussion thread
DOWNLOAD for MAC
DOWNLOAD for WIN

3

Wednesday, January 2nd 2013, 11:48pm

Hi Andrey

Is the following line supposed to set and load the scene?:

Source code

1
krpano.call("loadscene(" + scene +  ")");


I'm having trouble getting it to work - in my current xml file I have the following:

Source code

1
<action name="startup">		<!-- load the first scene -->		loadscene(get(scene[0].name), null, MERGE);



Am i supposed to remove this or put something else in it's place - when i remove it nothing loads!

thanks