|
@@ -40,6 +40,7 @@ var _this = this; |
|
|
var config, |
|
|
var config, |
|
|
renderer, |
|
|
renderer, |
|
|
preview, |
|
|
preview, |
|
|
|
|
|
draggingHotSpot, |
|
|
isUserInteracting = false, |
|
|
isUserInteracting = false, |
|
|
latestInteraction = Date.now(), |
|
|
latestInteraction = Date.now(), |
|
|
onPointerDownPointerX = 0, |
|
|
onPointerDownPointerX = 0, |
|
@@ -378,8 +379,15 @@ function init() { |
|
|
|
|
|
|
|
|
if (config.dynamic !== true) { |
|
|
if (config.dynamic !== true) { |
|
|
// Still image |
|
|
// Still image |
|
|
|
|
|
if (config.panorama instanceof Image || config.panorama instanceof ImageData || |
|
|
|
|
|
config.panorama instanceof ImageBitmap) { |
|
|
|
|
|
panoImage = config.panorama; |
|
|
|
|
|
onImageLoad(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
p = absoluteURL(config.panorama) ? config.panorama : p + config.panorama; |
|
|
p = absoluteURL(config.panorama) ? config.panorama : p + config.panorama; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
panoImage.onload = function() { |
|
|
panoImage.onload = function() { |
|
|
window.URL.revokeObjectURL(this.src); // Clean up |
|
|
window.URL.revokeObjectURL(this.src); // Clean up |
|
|
onImageLoad(); |
|
|
onImageLoad(); |
|
@@ -712,7 +720,7 @@ function onDocumentMouseDown(event) { |
|
|
container.focus(); |
|
|
container.focus(); |
|
|
|
|
|
|
|
|
// Only do something if the panorama is loaded |
|
|
// Only do something if the panorama is loaded |
|
|
if (!loaded || !config.draggable) { |
|
|
|
|
|
|
|
|
if (!loaded || !config.draggable || config.draggingHotSpot) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -797,7 +805,9 @@ function mouseEventToCoords(event) { |
|
|
* @param {MouseEvent} event - Document mouse move event. |
|
|
* @param {MouseEvent} event - Document mouse move event. |
|
|
*/ |
|
|
*/ |
|
|
function onDocumentMouseMove(event) { |
|
|
function onDocumentMouseMove(event) { |
|
|
if (isUserInteracting && loaded) { |
|
|
|
|
|
|
|
|
if (draggingHotSpot) { |
|
|
|
|
|
moveHotSpot(draggingHotSpot, event); |
|
|
|
|
|
} else if (isUserInteracting && loaded) { |
|
|
latestInteraction = Date.now(); |
|
|
latestInteraction = Date.now(); |
|
|
var canvas = renderer.getCanvas(); |
|
|
var canvas = renderer.getCanvas(); |
|
|
var canvasWidth = canvas.clientWidth, |
|
|
var canvasWidth = canvas.clientWidth, |
|
@@ -821,6 +831,10 @@ function onDocumentMouseMove(event) { |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
function onDocumentMouseUp(event) { |
|
|
function onDocumentMouseUp(event) { |
|
|
|
|
|
if (draggingHotSpot && draggingHotSpot.dragHandlerFunc) |
|
|
|
|
|
draggingHotSpot.dragHandlerFunc(event, draggingHotSpot.dragHandlerArgs); |
|
|
|
|
|
draggingHotSpot = null; |
|
|
|
|
|
|
|
|
if (!isUserInteracting) { |
|
|
if (!isUserInteracting) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@@ -845,7 +859,7 @@ function onDocumentMouseUp(event) { |
|
|
*/ |
|
|
*/ |
|
|
function onDocumentTouchStart(event) { |
|
|
function onDocumentTouchStart(event) { |
|
|
// Only do something if the panorama is loaded |
|
|
// Only do something if the panorama is loaded |
|
|
if (!loaded || !config.draggable) { |
|
|
|
|
|
|
|
|
if (!loaded || !config.draggable || draggingHotSpot) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -936,6 +950,8 @@ function onDocumentTouchMove(event) { |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
function onDocumentTouchEnd() { |
|
|
function onDocumentTouchEnd() { |
|
|
|
|
|
draggingHotSpot = null; |
|
|
|
|
|
|
|
|
isUserInteracting = false; |
|
|
isUserInteracting = false; |
|
|
if (Date.now() - latestInteraction > 150) { |
|
|
if (Date.now() - latestInteraction > 150) { |
|
|
speed.pitch = speed.yaw = 0; |
|
|
speed.pitch = speed.yaw = 0; |
|
@@ -973,6 +989,11 @@ function onDocumentPointerDown(event) { |
|
|
*/ |
|
|
*/ |
|
|
function onDocumentPointerMove(event) { |
|
|
function onDocumentPointerMove(event) { |
|
|
if (event.pointerType == 'touch') { |
|
|
if (event.pointerType == 'touch') { |
|
|
|
|
|
if (draggingHotSpot) { |
|
|
|
|
|
moveHotSpot(draggingHotSpot, event); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (!config.draggable) |
|
|
if (!config.draggable) |
|
|
return; |
|
|
return; |
|
|
for (var i = 0; i < pointerIDs.length; i++) { |
|
|
for (var i = 0; i < pointerIDs.length; i++) { |
|
@@ -994,6 +1015,10 @@ function onDocumentPointerMove(event) { |
|
|
* @param {PointerEvent} event - Document pointer up event. |
|
|
* @param {PointerEvent} event - Document pointer up event. |
|
|
*/ |
|
|
*/ |
|
|
function onDocumentPointerUp(event) { |
|
|
function onDocumentPointerUp(event) { |
|
|
|
|
|
if (draggingHotSpot && draggingHotSpot.dragHandlerFunc) |
|
|
|
|
|
draggingHotSpot.dragHandlerFunc(event, draggingHotSpot.dragHandlerArgs); |
|
|
|
|
|
draggingHotSpot = null; |
|
|
|
|
|
|
|
|
if (event.pointerType == 'touch') { |
|
|
if (event.pointerType == 'touch') { |
|
|
var defined = false; |
|
|
var defined = false; |
|
|
for (var i = 0; i < pointerIDs.length; i++) { |
|
|
for (var i = 0; i < pointerIDs.length; i++) { |
|
@@ -1412,7 +1437,8 @@ function animate() { |
|
|
} else if (renderer && (renderer.isLoading() || (config.dynamic === true && update))) { |
|
|
} else if (renderer && (renderer.isLoading() || (config.dynamic === true && update))) { |
|
|
requestAnimationFrame(animate); |
|
|
requestAnimationFrame(animate); |
|
|
} else { |
|
|
} else { |
|
|
fireEvent('animatefinished', {pitch: _this.getPitch(), yaw: _this.getYaw(), hfov: _this.getHfov()}); |
|
|
|
|
|
|
|
|
if (_this.getPitch && _this.getYaw && _this.getHfov) |
|
|
|
|
|
fireEvent('animatefinished', {pitch: _this.getPitch(), yaw: _this.getYaw(), hfov: _this.getHfov()}); |
|
|
animating = false; |
|
|
animating = false; |
|
|
prevTime = undefined; |
|
|
prevTime = undefined; |
|
|
var autoRotateStartTime = config.autoRotateInactivityDelay - |
|
|
var autoRotateStartTime = config.autoRotateInactivityDelay - |
|
@@ -1813,10 +1839,51 @@ function createHotSpot(hs) { |
|
|
div.className += ' pnlm-pointer'; |
|
|
div.className += ' pnlm-pointer'; |
|
|
span.className += ' pnlm-pointer'; |
|
|
span.className += ' pnlm-pointer'; |
|
|
} |
|
|
} |
|
|
|
|
|
if (hs.draggable) { |
|
|
|
|
|
// Handle mouse by container event listeners |
|
|
|
|
|
div.addEventListener('mousedown', function (e) { |
|
|
|
|
|
if (hs.dragHandlerFunc) |
|
|
|
|
|
hs.dragHandlerFunc(e, hs.dragHandlerArgs); |
|
|
|
|
|
draggingHotSpot = hs; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (document.documentElement.style.pointerAction === '' && |
|
|
|
|
|
document.documentElement.style.touchAction === '') { |
|
|
|
|
|
div.addEventListener('pointerdown', function (e) { |
|
|
|
|
|
if (hs.dragHandlerFunc) |
|
|
|
|
|
hs.dragHandlerFunc(e, hs.dragHandlerArgs); |
|
|
|
|
|
draggingHotSpot = hs; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Handle touch events by hotspot event listener |
|
|
|
|
|
div.addEventListener('touchmove', function(e) { |
|
|
|
|
|
moveHotSpot(hs, e.targetTouches[0]); |
|
|
|
|
|
}); |
|
|
|
|
|
div.addEventListener('touchend', function (e) { |
|
|
|
|
|
if (hs.dragHandlerFunc) |
|
|
|
|
|
hs.dragHandlerFunc(e, hs.dragHandlerArgs); |
|
|
|
|
|
draggingHotSpot = null; |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
hs.div = div; |
|
|
hs.div = div; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
* Moves a curently displayed hot spot. |
|
|
|
|
|
* @private |
|
|
|
|
|
* @param {Object} hs - Hot spot to move. |
|
|
|
|
|
* @param {MouseEvent} event - Mouse event to get coordinates from. |
|
|
|
|
|
*/ |
|
|
|
|
|
function moveHotSpot(hs, event){ |
|
|
|
|
|
var coords = mouseEventToCoords(event); |
|
|
|
|
|
hs.pitch = coords[0]; |
|
|
|
|
|
hs.yaw = coords[1]; |
|
|
|
|
|
renderHotSpot(hs); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
* Creates hot spot elements for the current scene. |
|
|
* Creates hot spot elements for the current scene. |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|