123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Photo Sphere Viewer</title>
- <meta name="viewport" content="initial-scale=1.0" />
- <link rel="stylesheet" href="./css/viewer.min.css">
- <link rel="stylesheet" href="./css/reset.css">
- <script src="./js/three.min.js"></script>
- <script src="./js/viewer.min.js"></script>
- <script src="./js/photo-sphere-viewer.min.js"></script>
- <style>
- html,
- body {
- margin: 0;
- width: 100%;
- height: 100%;
- overflow: hidden;
- }
-
- #container {
- width: 100%;
- height: 100%;
- }
-
- #container video {
- width: 100%;
- height: 100%;
- }
-
- #container .div {
- height: 100%;
- width: 100%;
- }
-
- #container #images {
- height: 100%;
- width: 100%;
- background-color: rgba(0, 0, 0, .5)
- }
-
- #images img {
- width: 200px;
- height: 200px;
- text-align: center;
- margin-left: auto;
- display: block;
- margin-right: auto;
- margin-top: 300px;
- }
-
- .spinner {
- margin: 100px auto;
- width: 50px;
- height: 60px;
- text-align: center;
- font-size: 10px;
- }
-
- .spinner>div {
- background-color: #67CF22;
- height: 100%;
- width: 6px;
- display: inline-block;
- -webkit-animation: stretchdelay 1.2s infinite ease-in-out;
- animation: stretchdelay 1.2s infinite ease-in-out;
- }
-
- .spinner .rect2 {
- -webkit-animation-delay: -1.1s;
- animation-delay: -1.1s;
- }
-
- .spinner .rect3 {
- -webkit-animation-delay: -1.0s;
- animation-delay: -1.0s;
- }
-
- .spinner .rect4 {
- -webkit-animation-delay: -0.9s;
- animation-delay: -0.9s;
- }
-
- .spinner .rect5 {
- -webkit-animation-delay: -0.8s;
- animation-delay: -0.8s;
- }
-
- @-webkit-keyframes stretchdelay {
- 0%,
- 40%,
- 100% {
- -webkit-transform: scaleY(0.4)
- }
- 20% {
- -webkit-transform: scaleY(1.0)
- }
- }
-
- @keyframes stretchdelay {
- 0%,
- 40%,
- 100% {
- transform: scaleY(0.4);
- -webkit-transform: scaleY(0.4);
- }
- 20% {
- transform: scaleY(1.0);
- -webkit-transform: scaleY(1.0);
- }
- }
-
- .viewer-canvas,
- html {
- background-color: rgba(0, 0, 0, .5)
- }
-
- #loading {
- position: absolute;
- top: 30%;
- left: 45%;
- z-index: 10;
- }
-
- #container>div {
- z-index: 40;
- }
- </style>
- </head>
- <body>
- <div id="container">
- </div>
- <div id="loading"></div>
- <script>
- var falg = false,
- dataView
- function receiveMessageFromIndex(event) {
- console.log('receiveMessageFromIndex', event.data)
- dataView = event.data
- falg = true
- this.postView()
- }
- //监听message事件
- window.addEventListener("message", receiveMessageFromIndex, false);
- if (!falg) {
- var div = document.getElementById('container'), //获取承接容器
- key = getQueryString('key'), //获取传来的图片或视频key值
- type = getQueryString('type'), //获取图片的类型 image正常图片 image/name全景图 video视频
- name = getQueryString('name'); //获得到的名字
- div.innerHTML = '';
- if (!!type) {
- if (type == 'panorama') {
- panorama()
- } else if (type == 'video') {
- video()
- } else if (type.indexOf('image') != '-1') {
- preview()
- }
- }
- } else {
- this.postView()
- }
- function postView() {
- var dom = ``
- for (var j = 0; j < dataView.length; j++) {
- dom += `<li><img src="img/image-service/common/image_get?systemId=dataPlatform&key=` + dataView[j].key + `" alt=` + dataView[j].name + `></li>`
- }
- var text = `
- <div class="div">
- <ul id="images">
- ` + dom + `
- </ul>
- </div>`
- div.innerHTML = text
- console.log(text, "text")
- var viewer = new Viewer(document.getElementById('images'), {
- backdrop: false
- });
- viewer.show()
- }
- function preview() {
- var con = `
- <div class="div">
- <ul id="images">
- <li><img src="img/image-service/common/image_get?systemId=dataPlatform&key=` + key + `" alt="` + name + `"></li>
- </ul>
- </div>`
- div.innerHTML = con
- // View a list of images
- if (!!key) {
- var viewer = new Viewer(document.getElementById('images'), {
- backdrop: false
- });
- viewer.show()
- }
- }
- function video() {
- var videoCainter = document.createElement('video');
- videoCainter.setAttribute('src', 'img/ image-service/common/fileget?systemId=dataPlatform&key=' + key);
- videoCainter.setAttribute('controls', 'controls');
- videoCainter.innerText = '您的浏览器不支持 video 标签。'
- div.appendChild(videoCainter)
- }
- //获取url传参
- function getQueryString(name) {
- var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
- var r = window.location.search.substr(1).match(reg);
- if (r != null) {
- return unescape(r[2]);
- }
- return null;
- }
- function panorama() {
- //加上width避免图片过大导致请求时间长而认为请求失败
- var loading = `<div class="spinner">
- <div class="rect1"></div>
- <div class="rect2"></div>
- <div class="rect3"></div>
- <div class="rect4"></div>
- <div class="rect5"></div>
- </div>`;
- document.getElementById('loading').innerHTML = loading
- var url = 'img/image-service/common/image_get?systemId=dataPlatform&key=' + key + '&width=5000';
- var PSV = new PhotoSphereViewer({
- panorama: url,
- // panorama: './image/IMG_0518.JPG',
- container: div,
- time_anim: 3000,
- navbar: true,
- navbar_style: {
- backgroundColor: 'rgba(58, 67, 77, 0.7)'
- },
- });
- }
- </script>
- </body>
- </html>
|