function createPanorama(imgUrl,doc,imgHeight){
var img=imgUrl;
// var img = "http://qqmmsh.oss-cn-hangzhou.aliyuncs.com/apply/6113528861282912.jpg";
// 图片地址转BASE64
function getBase64Image(img) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var ext = img.src.substring(img.src.lastIndexOf(".")+1).toLowerCase();
var dataURL = canvas.toDataURL("image/"+ext);
return dataURL;
}
// 初始化全景图 核心代码段
function initVR(doc,imgData){
var renderDom=document.querySelector(doc);
// var div = document.getElementById('your-pano');
console.log(renderDom);
var PSV = new PhotoSphereViewer({
// Panorama, given in base 64
panorama: imgData,
// Container
container: renderDom,
// Deactivate the animation
time_anim: false,
// Display the navigation bar
navbar: true,
// Resize the panorama
size: {
width: '100%',
height: imgHeight
},
time_anim:500
});
}
// 获取图片地址并转码
var image = new Image();
image.crossOrigin = '';
image.src = img;
image.onload = function(){
var base64 = getBase64Image(image);
console.log(base64);
initVR(doc,base64);
}
}
// window.onload = function() {
// var whb = document.getElementById('container')
// var PSV = new PhotoSphereViewer({
// // Path to the panorama
// //panorama: 'https://t1.huanqiucdn.cn/47c78d08c1341b06d3c4b9054a7c6101.jpg',
// // panorama: 'https://www.fangpeng.net/fpvr/textures/R0010002_20190807101921.JPG',
// panorama:'http://localhost/1.jpg',
// // Container
// container: whb,
// // Deactivate the animation
// time_anim: false,