카메라 뷰 및 경계 제한

플랫폼 선택: Android iOS JavaScript

카메라의 화면 이동, 최대 고도 또는 특정 지도에서 사용자의 이동을 제한하는 위도 및 경도 경계를 만드는 것이 바람직할 수 있습니다. 카메라 제한 을 사용하여 이 작업을 수행할 수 있습니다.

다음 예는 카메라의 이동을 제한하도록 위치 경계가 설정된 지도를 보여줍니다.

지도 경계 제한

bounds 옵션을 설정하여 카메라의 지리적 경계를 제한할 수 있습니다.

다음 코드 샘플은 지도 경계를 제한하는 방법을 보여줍니다.

TypeScript

async function init(): Promise<void> {
    await google.maps.importLibrary('maps3d');

    const map3DElement = document.querySelector('gmp-map-3d')!;

    // Restrict the position of the camera to the specified bounds.
    map3DElement.bounds = {
        south: -48.3,
        west: 163.56,
        north: -32.86,
        east: -180,
    };
}

void init();

JavaScript

async function init() {
    await google.maps.importLibrary('maps3d');

    const map3DElement = document.querySelector('gmp-map-3d');

    // Restrict the position of the camera to the specified bounds.
    map3DElement.bounds = {
        south: -48.3,
        west: 163.56,
        north: -32.86,
        east: -180,
    };
}

void init();

CSS

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
}

HTML

<html>
    <head>
        <title>Map</title>

        <link rel="stylesheet" type="text/css" href="./style.css" />
        <script type="module" src="./index.js"></script>
        <script>
            // prettier-ignore
            (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
                key: "GOOGLE_MAPS_API_KEY"
            });
        </script>
    </head>
    <body>
        <gmp-map-3d
            id="gmp-map-3d"
            center="-47.1375,169.5235,150000"
            tilt="67.5"
            mode="hybrid"
            gesture-handling="cooperative">
        </gmp-map-3d>
    </body>
</html>

카메라 제한

다음 옵션 중 하나를 설정하여 카메라의 이동을 제한할 수 있습니다.

  • maxAltitude
  • minAltitude
  • maxHeading
  • minHeading
  • maxTilt
  • minTilt

다음 코드 샘플은 카메라를 제한하는 방법을 보여줍니다.

// Restrict the movement of the camera.
map3DElement.maxAltitude = 1000;
map3DElement.minAltitude = 500;
map3DElement.maxTilt = 55;
map3DElement.minTilt = 35;

지도 및 카메라 경계 제한

지도 경계와 카메라 경계를 동시에 제한할 수 있습니다. 다음 코드 샘플은 지도 경계와 카메라 경계를 모두 제한하는 방법을 보여줍니다.

// Restrict the movement of the camera.
map3DElement.maxAltitude = 1000;
map3DElement.minAltitude = 500;
map3DElement.maxTilt = 55;
map3DElement.minTilt = 35;

// Restrict the position of the camera to the specified bounds.
map3DElement.bounds = {
    north: 20.93,
    west: -156.38,
    south: 20.90,
    east: -156.31,
};

동작 처리 관리

사용자가 지도가 포함된 페이지를 스크롤할 때 스크롤 작업으로 인해 의도치 않게 지도가 확대/축소될 수 있습니다. gestureHandling 지도 옵션을 설정하여 이 동작을 관리할 수 있습니다.

gestureHandling: cooperative

'협력적' 동작 처리를 사용하면 지도의 확대/축소 또는 화면 이동에 영향을 주지 않고 사용자가 페이지를 스크롤할 수 있습니다. 확대/축소하려면 사용자는 컨트롤, 두 손가락 동작 (터치스크린 기기)을 사용하거나 스크롤하는 동안 CMD/CTRL을 누르면 됩니다.

다음 코드는 동작 처리를 '협력적'으로 설정하는 방법을 보여줍니다.

<gmp-map-3d
    id="gmp-map-3d"
    center="20.92,-156.36,500"
    tilt="67.5"
    mode="hybrid"
    gesture-handling="cooperative">
</gmp-map-3d>

gestureHandling: greedy

'탐욕적' 동작 처리는 모든 스크롤 이벤트와 터치 동작에 반응합니다.

gestureHandling: auto

"자동" 동작 처리는 지도가 지도가 <iframe>에 포함되어 있는지 여부와 페이지를 스크롤할 수 있는지 여부에 따라 지도의 동작을 변경합니다.

  • 지도가 <iframe> 내에 있으면 동작 처리가 "협력적"이 됩니다.
  • 지도가 <iframe> 내에 없으면 동작 처리가 "탐욕적"이 됩니다.