您可能希望控制镜头的平移、最大海拔高度,或创建纬度和经度边界来限制用户在给定地图上的移动。为此,您可以使用摄像头限制。
下例所示的地图将位置边界设置为限制镜头的移动:
限制地图边界
您可以通过设置 bounds
选项来限制相机的地理边界。
以下代码示例演示了如何限制地图边界:
async function init() {
const { Map3DElement, MapMode } = await google.maps.importLibrary("maps3d");
const map = new Map3DElement({
center: { lat: 37.7704, lng: -122.3985, altitude: 500 },
tilt: 67.5,
mode: MapMode.HYBRID,
bounds: {south: 37, west: -123, north: 38, east: -121}
});
init();
}
限制相机
您可以通过设置以下任一选项来限制镜头的移动:
maxAltitude
minAltitude
maxHeading
minHeading
maxTilt
minTilt
以下代码示例演示了如何限制相机:
async function init() {
const { Map3DElement, MapMode } = await google.maps.importLibrary("maps3d");
const map = new Map3DElement({
center: { lat: 37.7704, lng: -122.3985, altitude: 500 },
tilt: 67.5,
mode: MapMode.HYBRID,
minAltitude: 1,
maxAltitude: 1000,
minTilt: 35,
maxTilt: 55
});
document.body.append(map);
}
init();
限制地图和相机边界
您可以同时限制地图边界和镜头边界。以下代码示例展示了如何同时限制地图边界和镜头边界:
async function init() {
const { Map3DElement, MapMode } = await google.maps.importLibrary("maps3d");
const map = new Map3DElement({
center: { lat: 37.7704, lng: -122.3985, altitude: 500 },
tilt: 67.5,
mode: MapMode.HYBRID,
minAltitude: 1,
maxAltitude: 1000,
minTilt: 35,
maxTilt: 55,
bounds: {south: 37, west: -123, north: 38, east: -121}
});
document.body.append(map);
}
init();