거리/항공뷰 전환하기
공식 예제 대응네이버 공식 예제 보기 ↗
거리뷰와 항공뷰를 전환하는 컨트롤을 켜고 끕니다.
코드 접기코드 보기
import { useState } from 'react';
import {
NavermapsProvider,
Container as PanoDiv,
useNavermaps,
} from 'react-naver-maps';
import { Panorama } from 'react-naver-maps/panorama';
function AroundControlPanorama({ aroundControl }: { aroundControl: boolean }) {
const navermaps = useNavermaps();
return (
<Panorama
position={{ lat: 37.3599605, lng: 127.1058814 }}
pov={{ pan: -135, tilt: 29, fov: 100 }}
aroundControl={aroundControl}
aroundControlOptions={{ position: navermaps.Position.TOP_RIGHT }}
/>
);
}
function PanoramaAroundControl() {
const [aroundControl, setAroundControl] = useState(true);
return (
<>
<PanoDiv style={{ width: '100%', height: '500px' }}>
<AroundControlPanorama aroundControl={aroundControl} />
</PanoDiv>
<input
type="button"
style={{ marginTop: 8 }}
value={
aroundControl ? '거리/항공뷰 전환 끄기' : '거리/항공뷰 전환 켜기'
}
onClick={() => setAroundControl((on) => !on)}
/>
</>
);
}
export default function PanoramaTutorial7AroundcontrolExample() {
return (
<NavermapsProvider ncpKeyId="aluya4ff04" submodules={['panorama']}>
<PanoramaAroundControl />
</NavermapsProvider>
);
}설명
aroundControl과 aroundControlOptions가 prop입니다. 버튼은 aroundControl state를 토글합니다.
React로 옮기며 바꾼 점
| 네이버 공식 예제 | 이 예제 |
|---|---|
pano.getOptions('aroundControl')을 보고 setOptions({ aroundControl }) | aroundControl prop에 state 전달 |
jQuery val · addClass · removeClass로 버튼 상태 바꾸기 | 버튼 글자를 같은 state로 설정 |