基於web的全景漫遊自動生成加編輯平臺的技術實現(二)----krpano窺探

上次我們說到怎麼使用krpano自動製作一個全景漫遊,今天我們來說一下krpano是怎麼讓一個全景漫遊運作起來的

首先我們打開一個經過krpano自動生成後的全景漫遊,查看它的代碼,這裏我用的編輯器是Sublime Text 3(強烈推薦,用來編輯XML或者其它很方便)

查看這個html頁面的代碼內容

<!DOCTYPE html>
<html>
<head>
	<title>krpano - 1</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name="apple-mobile-web-app-status-bar-style" content="black" />
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<meta http-equiv="x-ua-compatible" content="IE=edge" />
	<style>
		@-ms-viewport { width:device-width; }
		@media only screen and (min-device-width:800px) { html { overflow:hidden; } }
		html { height:100%; }
		body { height:100%; overflow:hidden; margin:0; padding:0; font-family:Arial, Helvetica, sans-serif; font-size:16px; color:#FFFFFF; background-color:#000000; }
	</style>
</head>
<body>

<script src="tour.js"></script>

<div id="pano" style="width:100%;height:100%;">
	<noscript><table style="width:100%;height:100%;"><tr style="vertical-align:middle;"><td><div style="text-align:center;">ERROR:<br/><br/>Javascript not activated<br/><br/></div></td></tr></table></noscript>
	<script>
		embedpano({swf:"tour.swf", xml:"tour.xml", target:"pano", html5:"auto", mobilescale:1.0, passQueryParameters:true});
	</script>
</div>

</body>
</html>

<head>標籤內的代碼主要是針對設備的自動適應,不細說了

我們主要看下面<body>標籤裏的內容


第一行裏,告訴瀏覽器,讀取tour.js裏的內容

<script src="tour.js"></script>
就是這個文件啦,這個js文件包含了krpano的html5引擎以及flash嵌入,沒有它全景漫遊也運作不起來(可惜老外把它加密處理了)


下一行<div>標籤讓全景漫遊全屏顯示

<div id="pano" style="width:100%;height:100%;">

<noscript>標籤如果瀏覽器不支持javascript,則顯示錯誤信息Javascript not activated

<noscript><table style="width:100%;height:100%;javascript"><tr style="vertical-align:middle;"><td><div style="text-align:center;">ERROR:<br/><br/>Javascript not activated<br/><br/></div></td></tr></table></noscript>

最後的<script>標籤就是全景漫遊的參數配置了

這裏用了krpano裏的embedpano方法(這個方法在tour.js裏),方法裏的參數的具體意思是

swf:"tour.swf" :加載flash引擎(在全景文件夾裏的tour.swf文件)

xml:"tour.xml" :加載krpano的主XML配置文件(在全景文件夾裏的tour.xml文件

target:"pano" :加載上面id爲pano的div

html5:"auto" :讓瀏覽器首先使用HTML5來運行全景漫遊(有HTML5和flash兩種方式,不支持html5時才用flash)

passQueryParameters:true :true表示允許外部傳遞參數傳送到viewer視圖層中

<script>
		embedpano({swf:"tour.swf", xml:"tour.xml", target:"pano", html5:"auto", mobilescale:1.0, passQueryParameters:true});
	</script>

總的來說,就是在html頁面裏讀取tour.js文件裏的內容,再根據tour.xml文件裏的配置信息渲染全景漫遊頁面(渲染有flash和html5兩種方式,1.19版本默認首先使用html5方式),全景漫遊就這樣在瀏覽器裏展示出來了。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章