photo-View.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Photo Sphere Viewer</title>
  6. <meta name="viewport" content="initial-scale=1.0" />
  7. <link rel="stylesheet" href="./css/viewer.min.css">
  8. <link rel="stylesheet" href="./css/reset.css">
  9. <script src="./js/three.min.js"></script>
  10. <script src="./js/viewer.min.js"></script>
  11. <script src="./js/photo-sphere-viewer.min.js"></script>
  12. <style>
  13. html,
  14. body {
  15. margin: 0;
  16. width: 100%;
  17. height: 100%;
  18. overflow: hidden;
  19. }
  20. #container {
  21. width: 100%;
  22. height: 100%;
  23. }
  24. #container video {
  25. width: 100%;
  26. height: 100%;
  27. }
  28. #container .div {
  29. height: 100%;
  30. width: 100%;
  31. }
  32. #container #images {
  33. height: 100%;
  34. width: 100%;
  35. background-color: rgba(0, 0, 0, .5)
  36. }
  37. #images img {
  38. width: 200px;
  39. height: 200px;
  40. text-align: center;
  41. margin-left: auto;
  42. display: block;
  43. margin-right: auto;
  44. margin-top: 300px;
  45. }
  46. .spinner {
  47. margin: 100px auto;
  48. width: 50px;
  49. height: 60px;
  50. text-align: center;
  51. font-size: 10px;
  52. }
  53. .spinner>div {
  54. background-color: #67CF22;
  55. height: 100%;
  56. width: 6px;
  57. display: inline-block;
  58. -webkit-animation: stretchdelay 1.2s infinite ease-in-out;
  59. animation: stretchdelay 1.2s infinite ease-in-out;
  60. }
  61. .spinner .rect2 {
  62. -webkit-animation-delay: -1.1s;
  63. animation-delay: -1.1s;
  64. }
  65. .spinner .rect3 {
  66. -webkit-animation-delay: -1.0s;
  67. animation-delay: -1.0s;
  68. }
  69. .spinner .rect4 {
  70. -webkit-animation-delay: -0.9s;
  71. animation-delay: -0.9s;
  72. }
  73. .spinner .rect5 {
  74. -webkit-animation-delay: -0.8s;
  75. animation-delay: -0.8s;
  76. }
  77. @-webkit-keyframes stretchdelay {
  78. 0%,
  79. 40%,
  80. 100% {
  81. -webkit-transform: scaleY(0.4)
  82. }
  83. 20% {
  84. -webkit-transform: scaleY(1.0)
  85. }
  86. }
  87. @keyframes stretchdelay {
  88. 0%,
  89. 40%,
  90. 100% {
  91. transform: scaleY(0.4);
  92. -webkit-transform: scaleY(0.4);
  93. }
  94. 20% {
  95. transform: scaleY(1.0);
  96. -webkit-transform: scaleY(1.0);
  97. }
  98. }
  99. .viewer-canvas,
  100. html {
  101. background-color: rgba(0, 0, 0, .5)
  102. }
  103. #loading {
  104. position: absolute;
  105. top: 30%;
  106. left: 45%;
  107. z-index: 10;
  108. }
  109. #container>div {
  110. z-index: 40;
  111. }
  112. </style>
  113. </head>
  114. <body>
  115. <div id="container">
  116. </div>
  117. <div id="loading"></div>
  118. <script>
  119. var falg = false,
  120. dataView
  121. function receiveMessageFromIndex(event) {
  122. console.log('receiveMessageFromIndex', event.data)
  123. dataView = event.data
  124. falg = true
  125. this.postView()
  126. }
  127. //监听message事件
  128. window.addEventListener("message", receiveMessageFromIndex, false);
  129. if (!falg) {
  130. var div = document.getElementById('container'), //获取承接容器
  131. key = getQueryString('key'), //获取传来的图片或视频key值
  132. type = getQueryString('type'), //获取图片的类型 image正常图片 image/name全景图 video视频
  133. name = getQueryString('name'); //获得到的名字
  134. div.innerHTML = '';
  135. if (!!type) {
  136. if (type == 'panorama') {
  137. panorama()
  138. } else if (type == 'video') {
  139. video()
  140. } else if (type.indexOf('image') != '-1') {
  141. preview()
  142. }
  143. }
  144. } else {
  145. this.postView()
  146. }
  147. function postView() {
  148. var dom = ``
  149. for (var j = 0; j < dataView.length; j++) {
  150. dom += `<li><img src="img/image-service/common/image_get?systemId=dataPlatform&key=` + dataView[j].key + `" alt=` + dataView[j].name + `></li>`
  151. }
  152. var text = `
  153. <div class="div">
  154. <ul id="images">
  155. ` + dom + `
  156. </ul>
  157. </div>`
  158. div.innerHTML = text
  159. console.log(text, "text")
  160. var viewer = new Viewer(document.getElementById('images'), {
  161. backdrop: false
  162. });
  163. viewer.show()
  164. }
  165. function preview() {
  166. var con = `
  167. <div class="div">
  168. <ul id="images">
  169. <li><img src="img/image-service/common/image_get?systemId=dataPlatform&key=` + key + `" alt="` + name + `"></li>
  170. </ul>
  171. </div>`
  172. div.innerHTML = con
  173. // View a list of images
  174. if (!!key) {
  175. var viewer = new Viewer(document.getElementById('images'), {
  176. backdrop: false
  177. });
  178. viewer.show()
  179. }
  180. }
  181. function video() {
  182. var videoCainter = document.createElement('video');
  183. videoCainter.setAttribute('src', 'img/ image-service/common/fileget?systemId=dataPlatform&key=' + key);
  184. videoCainter.setAttribute('controls', 'controls');
  185. videoCainter.innerText = '您的浏览器不支持 video 标签。'
  186. div.appendChild(videoCainter)
  187. }
  188. //获取url传参
  189. function getQueryString(name) {
  190. var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  191. var r = window.location.search.substr(1).match(reg);
  192. if (r != null) {
  193. return unescape(r[2]);
  194. }
  195. return null;
  196. }
  197. function panorama() {
  198. //加上width避免图片过大导致请求时间长而认为请求失败
  199. var loading = `<div class="spinner">
  200. <div class="rect1"></div>
  201. <div class="rect2"></div>
  202. <div class="rect3"></div>
  203. <div class="rect4"></div>
  204. <div class="rect5"></div>
  205. </div>`;
  206. document.getElementById('loading').innerHTML = loading
  207. var url = 'img/image-service/common/image_get?systemId=dataPlatform&key=' + key + '&width=5000';
  208. var PSV = new PhotoSphereViewer({
  209. panorama: url,
  210. // panorama: './image/IMG_0518.JPG',
  211. container: div,
  212. time_anim: 3000,
  213. navbar: true,
  214. navbar_style: {
  215. backgroundColor: 'rgba(58, 67, 77, 0.7)'
  216. },
  217. });
  218. }
  219. </script>
  220. </body>
  221. </html>