基於Three.js的360度全景--photo-sphere-viewer--簡介

這個是基於three.js的全景插件  photo-sphere-viewer.js 

————————————————————————————————————————javascript

一、能添加熱點;css

二、能調用陀螺儀;html

三、功能比較完善,能知足大多數人的需求了;html5

四、最主要的是操做簡單,提供一長全景圖片便可(大多數手機均可以拍攝)。java

直接上代碼:git

var photosphere = document.getElementById('photosphere');
 var PSV = new PhotoSphereViewer({
  // 全景圖片路徑
//  panorama: 'Bryce-Canyon-National-Park-Mark-Doliner.jpg',
  panorama: 'sun.jpg',
  // 容器
  container: photosphere,
  //標題
  caption:"",
  // 關閉動畫
  time_anim: false,
  //魚眼鏡頭
  fisheye:true,
  // 顯示導航欄
//  navbar: true,
//  自定義導航的順序
  navbar:  [
   'autorotate',
   'zoom',
   'gyroscope',
   'markers',
   'caption',
   'fullscreen'
  ],
  //按鈕提示
  lang: {
   autorotate: 'Automatic rotation',
   zoom: 'Zoom',
   zoomOut: 'Zoom out',
   zoomIn: 'Zoom in',
   download: 'Download',
   fullscreen: 'Fullscreen',
   markers: 'Markers',
   gyroscope: 'Gyroscope'
  },
  // 設置畫布大小
  size: {
   width: '100%',
//   height: '323px'
   height: '603px'
  },
//  啓用陀螺儀
  gyroscope:true,
//  準備就緒就執行
//  onready:Ready,
  // 標記列表
  markers: [{
   // 當單擊時打開面板的圖像標記
   id: 'image',
   longitude: 5.69810,
   latitude: -0.13770,
   image: 'http://photo-sphere-viewer.js.org/assets/pin-blue.png',
   width: 32,
   height: 32,
   anchor: 'bottom center',
   tooltip: 'A image marker. <b>Click me!</b>',
   content: document.getElementById('lorem-content').innerHTML
  },
   {
    // 具備自定義樣式的html標記
    id: 'text',
    longitude: 0,
    latitude: 0,
    html: 'HTML <a href="javascript:;" onclick="top.hello();">markerd</a> ♥',
    anchor: 'bottom right',
    style: {
     maxWidth: '100px',
     color: 'white',
     fontSize: '20px',
     fontFamily: 'Helvetica, sans-serif',
     textAlign: 'center'
    },
    tooltip: {
     content: 'An HTML marker',
     position: 'right'
    }
   },
   {
    // 圓圈標記
    id: 'circle',
    circle: 20,
    x: 2500,
    y: 1000,
    tooltip: 'A circle marker'
   },
   {
    // 圓圈標記
    id: 'circle2',
    circle: 30,
    x: 2000,
    y: 1200,
    tooltip: 'A circle marker'
   }
  ]
 });

  

注:調用陀螺儀須要 引用 DeviceOrientationControls.js;github

使用方法:web

一、這個插件的用法很簡單,引入以下2個jscanvas

<script src="js/three.min.js"></script>
<script src="js/photo-sphere-viewer.min.js"></script> 

二、初始化一下,(具體各類參數配置根據狀況而定)緩存

複製代碼
var PSV = new PhotoSphereViewer({
        // 全景圖的完整路徑
        panorama: 'images/360img03.jpg',

        // 放全景圖的元素
        container: div
})
複製代碼

 

配置參數

下面是該全景圖插件的全部可用配置參數:

複製代碼
panorama:必填參數,全景圖的路徑。
container:必填參數,放置全景圖的div元素。
autoload:可選,默認值爲true,true爲自動調用全景圖,false爲在後面加載全景圖(經過.load()方法)。
usexmpdata:可選,默認值爲true,若是Photo Sphere Viewer必須讀入XMP數據則爲true。
default_position:可選,默認值爲{},定義默認的位置,及用戶看見的第一個點,例如:{long: Math.PI, lat: Math.PI/2}。
min_fov:可選,默認值爲30,觀察的最小區域,單位degrees,在1-179之間。
max_fov:可選,默認值爲90,觀察的最大區域,單位degrees,在1-179之間。
allow_user_interactions:可選,默認值爲true,設置爲false則禁止用戶和全景圖交互(導航條不可用)。
tilt_up_max:可選,默認值爲Math.PI/2,向上傾斜的最大角度,單位radians。
tilt_down_max:可選,默認值爲Math.PI/2,向下傾斜的最大角度,單位radians。
zoom_level:可選,默認值爲0,默認的縮放級別,值在0-100之間。
long_offset:可選,默認值爲PI/360,mouse/touch移動時每像素通過的經度值。
lat_offset:可選,默認值爲PI/180,mouse/touch移動時每像素通過的緯度值。
time_anim:可選,默認值爲2000,全景圖在time_anim毫秒後會自動進行動畫。(設置爲false禁用它)
theta_offset:過期的選項,可選,默認值爲1440,自動動畫時水平方向的速度。
anim_speed:可選,默認值爲2rpm,動畫的速度,每秒/分鐘多少radians/degrees/revolutions。
navbar:可選值,默認爲false。顯示導航條。
navbar_style:可選值,默認爲{}。導航條的自定義樣式。下面是可用的樣式列表:
backgroundColor:導航條的背景顏色,默認值爲rgba(61, 61, 61, 0.5)。
buttonsColor:按鈕的前景顏色,默認值爲transparent。
activeButtonsBackgroundColor:按鈕激活狀態的背景顏色,默認值爲rgba(255, 255, 255, 0.1)。
buttonsHeight:按鈕的高度,單位像素,默認值爲20。
autorotateThickness:autorotate圖標的厚度,單位像素,默認值爲1。
zoomRangeWidth:縮放的範圍,單位顯示,默認值50。
zoomRangeThickness:縮放的範圍的厚度,單位像素,默認值1。
zoomRangeDisk:縮放範圍的圓盤直徑,單位像素,默認值爲7。
fullscreenRatio:全屏圖標的比例,默認值爲3/4。
fullscreenThickness:全屏圖標的厚度,單位像素,默認值爲2。
loading_msg:可選,默認值爲Loading…,圖片加載時的提示文字。
loading_img:可選,默認值爲null,在加載時顯示的圖片的路徑。
size:可選,默認值null,全景圖容器的最終尺寸。例如:{width: 500, height: 300}。
onready:可選值,默認值爲null。當全景圖準備就緒而且第一張圖片顯示時的回調函數。
複製代碼

 三、上面demo的代碼

複製代碼
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>360全景圖</title>
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <!-- 啓用webAPP全屏模式-->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <!-- 隱藏狀態欄或者設置狀態欄的顏色-->
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <!-- 禁止緩存訪問頁面-->
    <meta http-equiv="Pragma" content="no-cache">
    <meta name="applicable-device" content="mobile">
    <!-- 頁面關鍵詞-->
    <link rel="stylesheet" href="css/demo01.css">
    <script src="js/three.min.js"></script>
    <script src="js/photo-sphere-viewer.min.js"></script>
    <!---->
    <script src="js/demo01.js"></script>
    <!--[if IE]>
        <script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="main">
        <h3 id="title">旋轉查看效果</h3>
        <div id="container"></div>
    </div>
</body>
</html>
複製代碼
複製代碼
*{
    margin: 0;
    padding: 0;
    list-style: none;
    box-sizing: border-box;
    text-decoration: none;
    border: 0;
    outline: 0;
}
.main{
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
}
.main h3{
    text-align: center;
    padding: 10px 0;
}
複製代碼
複製代碼
/**
 * Created by Administrator on 2016/11/29.
 */


//必須在服務器上才能看到效果!
window.onload=function(){
    getTitleHeight();
    loadingAllImg();
}
//讓全景圖恰好撐滿屏幕
var canvasHeight;
function getTitleHeight(){
    var title=document.getElementById('title');
    var titleHeight=parseFloat(getComputedStyle(title).height);
    var maxHeight=window.innerHeight;
    canvasHeight=parseFloat(maxHeight-titleHeight)+'px';
}
//全景圖參數配置函數
function loadingAllImg(){
    var div = document.getElementById('container');
    var PSV = new PhotoSphereViewer({
        // 全景圖的完整路徑
        panorama: 'images/360img03.jpg',

        // 放全景圖的元素
        container: div,

        // 可選,默認值爲2000,全景圖在time_anim毫秒後會自動進行動畫。(設置爲false禁用它)
        time_anim: false,

        // 可選值,默認爲false。顯示導航條。
        navbar: true,

        // 可選,默認值null,全景圖容器的最終尺寸。例如:{width: 500, height: 300}。
        size: {
            width: '100%',
            height: canvasHeight
        }
    });
}
複製代碼

 

同時,在github上面,你們搜索(Photo Sphere Viewer),也能找到!目前這個插件感受還不是很完善。

最後附上 photo-sphere-viewer.js API-------http://photo-sphere-viewer.js.org/

相關文章
相關標籤/搜索