fix: xoay màn hình theo hướng người nhìn trong màn hình bản đồ vẫn còn xoay tròn
This commit is contained in:
@@ -172,9 +172,9 @@ const MapRotationHandler = ({ rotation }: { rotation: number }) => {
|
|||||||
const map = useMap();
|
const map = useMap();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const container = map.getContainer();
|
const container = map.getContainer();
|
||||||
// Tăng scale lên 1.8 để đảm bảo bao phủ toàn bộ màn hình điện thoại (vốn có tỉ lệ dài) khi xoay ở mọi góc độ
|
// Tăng scale lên 2.5 để bao phủ hoàn toàn các màn hình siêu dài (như 21:9)
|
||||||
container.style.transform = `rotate(${rotation}deg) scale(${rotation === 0 ? 1 : 1.8})`;
|
container.style.transform = `rotate(${rotation}deg) scale(${rotation === 0 ? 1 : 2.5})`;
|
||||||
container.style.transition = 'transform 0.3s ease-out';
|
container.style.transition = 'transform 0.1s linear';
|
||||||
}, [rotation, map]);
|
}, [rotation, map]);
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@@ -384,7 +384,6 @@ export const TourDetailPage = ({
|
|||||||
|
|
||||||
// State mới cho hướng thiết bị (la bàn)
|
// State mới cho hướng thiết bị (la bàn)
|
||||||
const [deviceOrientationHeading, setDeviceOrientationHeading] = useState<number | null>(null);
|
const [deviceOrientationHeading, setDeviceOrientationHeading] = useState<number | null>(null);
|
||||||
const rotationUpdateTimer = useRef<NodeJS.Timeout | null>(null);
|
|
||||||
|
|
||||||
// Theo dõi hướng thiết bị (la bàn)
|
// Theo dõi hướng thiết bị (la bàn)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -408,10 +407,6 @@ export const TourDetailPage = ({
|
|||||||
|
|
||||||
// Logic kết hợp để xác định hướng xoay bản đồ
|
// Logic kết hợp để xác định hướng xoay bản đồ
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (rotationUpdateTimer.current) {
|
|
||||||
clearTimeout(rotationUpdateTimer.current);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isHeadingMode) {
|
if (!isHeadingMode) {
|
||||||
setMapRotation(0); // Đặt lại hướng Bắc nếu chế độ xoay tắt
|
setMapRotation(0); // Đặt lại hướng Bắc nếu chế độ xoay tắt
|
||||||
return;
|
return;
|
||||||
@@ -427,17 +422,9 @@ export const TourDetailPage = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newRotation !== null) {
|
if (newRotation !== null) {
|
||||||
// Debounce cập nhật xoay để làm mượt chuyển động
|
// Cập nhật ngay lập tức để tăng độ nhạy, CSS transition sẽ lo phần mượt mà
|
||||||
rotationUpdateTimer.current = setTimeout(() => {
|
setMapRotation(newRotation);
|
||||||
setMapRotation(newRotation!);
|
|
||||||
}, 100); // Trì hoãn 100ms
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (rotationUpdateTimer.current) {
|
|
||||||
clearTimeout(rotationUpdateTimer.current);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [isHeadingMode, gpsHeading, userSpeed, deviceOrientationHeading]);
|
}, [isHeadingMode, gpsHeading, userSpeed, deviceOrientationHeading]);
|
||||||
|
|
||||||
const [isStartPointAction, setIsStartPointAction] = useState(false);
|
const [isStartPointAction, setIsStartPointAction] = useState(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user