Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef } from "react";
// import { useRef } from "react";
import MyLocation from "../../../../../assets/icon/myLocation.svg?react";
import { isCompassModeStore } from "../../../../../stores/mapStore";
import { useNavermaps } from "react-naver-maps";
Expand All @@ -13,50 +13,50 @@ const CompassButton = ({
const { isCompassMode, setIsCompassMode } = isCompassModeStore();
const navermaps = useNavermaps();

const markerRef = useRef<kakao.maps.Marker | null>(null);
// const markerRef = useRef<kakao.maps.Marker | null>(null);
const handleClick = async () => {
if (!isCompassMode) {
// 내 위치로 이동
map.panTo(new navermaps.LatLng(center.lat, center.lng));
setIsCompassMode(true);
} else {
// 나침반 모드 활성화
if (typeof DeviceOrientationEvent !== "undefined") {
try {
// iOS의 경우 권한 요청 필요
if (
typeof (DeviceOrientationEvent as any).requestPermission ===
"function"
) {
const permission = await (
DeviceOrientationEvent as any
).requestPermission();
if (permission !== "granted") return;
}
// if (typeof DeviceOrientationEvent !== "undefined") {
// try {
// // iOS의 경우 권한 요청 필요
// if (
// typeof (DeviceOrientationEvent as any).requestPermission ===
// "function"
// ) {
// const permission = await (
// DeviceOrientationEvent as any
// ).requestPermission();
// if (permission !== "granted") return;
// }

window.addEventListener("deviceorientation", (event) => {
console.log("alpha:", event.alpha);
if (event.alpha != null && markerRef.current) {
const heading = 360 - event.alpha;
console.log(heading);
const marker = markerRef.current;
const icon = marker.getImage();
if (icon) {
// 회전용 transform 적용
const imgEl = document.querySelector<HTMLImageElement>(
`img[src="${(icon as any).src}"]`
);
if (imgEl) {
imgEl.style.transform = `rotate(${heading}deg)`;
imgEl.style.transition = "transform 0.1s linear";
}
}
}
});
} catch (e) {
console.warn("Device orientation not available:", e);
}
}
// window.addEventListener("deviceorientation", (event) => {
// console.log("alpha:", event.alpha);
// if (event.alpha != null && markerRef.current) {
// const heading = 360 - event.alpha;
// console.log(heading);
// const marker = markerRef.current;
// const icon = marker.getImage();
// if (icon) {
// // 회전용 transform 적용
// const imgEl = document.querySelector<HTMLImageElement>(
// `img[src="${(icon as any).src}"]`
// );
// if (imgEl) {
// imgEl.style.transform = `rotate(${heading}deg)`;
// imgEl.style.transition = "transform 0.1s linear";
// }
// }
// }
// });
// } catch (e) {
// console.warn("Device orientation not available:", e);
// }
// }
setIsCompassMode(false);
}
};
Expand Down