Khôi phục góc nhìn và nơi đang xem sau khi reload page
This commit is contained in:
@@ -24,6 +24,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
// Chạy tuần tự để tránh xung đột luồng xử lý
|
// Chạy tuần tự để tránh xung đột luồng xử lý
|
||||||
checkAuthStatus(); // 2. Kiểm tra đăng nhập
|
checkAuthStatus(); // 2. Kiểm tra đăng nhập
|
||||||
|
|
||||||
|
// 3. Khôi phục cảnh đang xem nếu có (sau khi người dùng reload trang)
|
||||||
|
restoreActiveScene();
|
||||||
|
|
||||||
// Đảm bảo map đã sẵn sàng trước khi nạp data
|
// Đảm bảo map đã sẵn sàng trước khi nạp data
|
||||||
if (map) {
|
if (map) {
|
||||||
// Chỉ nạp danh sách Scene để vẽ marker lên bản đồ
|
// Chỉ nạp danh sách Scene để vẽ marker lên bản đồ
|
||||||
@@ -713,7 +716,7 @@ async function deleteScene(sceneId) {
|
|||||||
/**
|
/**
|
||||||
* Fetches secure scene details and triggers the Panorama viewer
|
* Fetches secure scene details and triggers the Panorama viewer
|
||||||
*/
|
*/
|
||||||
async function openScene(sceneId, privacy, shareToken, force = false) {
|
async function openScene(sceneId, privacy, shareToken, force = false, initialPitch = 0, initialYaw = 0) {
|
||||||
// Nếu đang xem chính scene này và không yêu cầu làm mới (force), không cần nạp lại
|
// Nếu đang xem chính scene này và không yêu cầu làm mới (force), không cần nạp lại
|
||||||
if (!force && currentSceneId === sceneId && document.getElementById('viewer-container').style.display === 'block') {
|
if (!force && currentSceneId === sceneId && document.getElementById('viewer-container').style.display === 'block') {
|
||||||
return;
|
return;
|
||||||
@@ -781,7 +784,7 @@ async function openScene(sceneId, privacy, shareToken, force = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize 3D Viewer with secure, referer-protected image stream
|
// Initialize 3D Viewer with secure, referer-protected image stream
|
||||||
initPanoramaViewer(secureImageUrl, hotspots || [], sceneOwnerId);
|
initPanoramaViewer(secureImageUrl, hotspots || [], sceneOwnerId, initialPitch, initialYaw);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
localStorage.removeItem('activeSceneId');
|
localStorage.removeItem('activeSceneId');
|
||||||
@@ -799,7 +802,9 @@ function restoreActiveScene() {
|
|||||||
if (savedSceneId) {
|
if (savedSceneId) {
|
||||||
const savedPrivacy = localStorage.getItem('activeScenePrivacy');
|
const savedPrivacy = localStorage.getItem('activeScenePrivacy');
|
||||||
const savedToken = localStorage.getItem('activeSceneToken');
|
const savedToken = localStorage.getItem('activeSceneToken');
|
||||||
openScene(savedSceneId, savedPrivacy, savedToken);
|
const savedPitch = parseFloat(localStorage.getItem('activeScenePitch')) || 0;
|
||||||
|
const savedYaw = parseFloat(localStorage.getItem('activeSceneYaw')) || 0;
|
||||||
|
openScene(savedSceneId, savedPrivacy, savedToken, false, savedPitch, savedYaw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,14 @@ let currentHotspots = [];
|
|||||||
let securityApplied = false;
|
let securityApplied = false;
|
||||||
let currentSceneOwnerId = null;
|
let currentSceneOwnerId = null;
|
||||||
|
|
||||||
|
// Lưu lại góc nhìn hiện tại vào localStorage trước khi trang bị reload (F5)
|
||||||
|
window.addEventListener('beforeunload', () => {
|
||||||
|
if (activeViewer) {
|
||||||
|
localStorage.setItem('activeScenePitch', activeViewer.getPitch());
|
||||||
|
localStorage.setItem('activeSceneYaw', activeViewer.getYaw());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hàm render tùy chỉnh cho hotspot để hiển thị bong bóng callout kèm ảnh thumbnail.
|
* Hàm render tùy chỉnh cho hotspot để hiển thị bong bóng callout kèm ảnh thumbnail.
|
||||||
* Thay thế icon mặc định của Pannellum bằng cấu trúc HTML mới.
|
* Thay thế icon mặc định của Pannellum bằng cấu trúc HTML mới.
|
||||||
@@ -42,8 +50,10 @@ function renderCustomHotspot(hotSpotDiv, args) {
|
|||||||
* @param {string} imageUrl - Authorized URL to fetch the secure image stream
|
* @param {string} imageUrl - Authorized URL to fetch the secure image stream
|
||||||
* @param {Array} hotspots - List of hotspots from the database
|
* @param {Array} hotspots - List of hotspots from the database
|
||||||
* @param {string} ownerId - ID of the scene owner
|
* @param {string} ownerId - ID of the scene owner
|
||||||
|
* @param {number} initialPitch - Góc nhìn dọc khởi tạo
|
||||||
|
* @param {number} initialYaw - Góc nhìn ngang khởi tạo
|
||||||
*/
|
*/
|
||||||
function initPanoramaViewer(imageUrl, hotspots = [], ownerId = null) {
|
function initPanoramaViewer(imageUrl, hotspots = [], ownerId = null, initialPitch = 0, initialYaw = 0) {
|
||||||
currentHotspots = hotspots;
|
currentHotspots = hotspots;
|
||||||
currentSceneOwnerId = ownerId;
|
currentSceneOwnerId = ownerId;
|
||||||
const container = document.getElementById('viewer-container');
|
const container = document.getElementById('viewer-container');
|
||||||
@@ -98,6 +108,8 @@ function initPanoramaViewer(imageUrl, hotspots = [], ownerId = null) {
|
|||||||
"type": "equirectangular",
|
"type": "equirectangular",
|
||||||
"panorama": imageUrl,
|
"panorama": imageUrl,
|
||||||
"autoLoad": true,
|
"autoLoad": true,
|
||||||
|
"pitch": initialPitch,
|
||||||
|
"yaw": initialYaw,
|
||||||
"showControls": true,
|
"showControls": true,
|
||||||
"compass": false,
|
"compass": false,
|
||||||
"mouseZoom": true,
|
"mouseZoom": true,
|
||||||
@@ -120,6 +132,8 @@ function closeViewer() {
|
|||||||
localStorage.removeItem('activeSceneId');
|
localStorage.removeItem('activeSceneId');
|
||||||
localStorage.removeItem('activeScenePrivacy');
|
localStorage.removeItem('activeScenePrivacy');
|
||||||
localStorage.removeItem('activeSceneToken');
|
localStorage.removeItem('activeSceneToken');
|
||||||
|
localStorage.removeItem('activeScenePitch');
|
||||||
|
localStorage.removeItem('activeSceneYaw');
|
||||||
|
|
||||||
if (activeViewer) {
|
if (activeViewer) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user