Class: Camera

olview~ Camera


new Camera()

二维相机

Methods


clientToWorld(x, y)

屏幕坐标转地图经纬度坐标
Parameters:
Name Type Description
x Number 屏幕x坐标
y Number 屏幕y坐标

worldToClient(lon, lat)

地图经纬度坐标转屏幕坐标
Parameters:
Name Type Description
lon Number 地图坐标,经度
lat Number 地图坐标,纬度
Example
var camera = olView.getCamera();
var screenPos = camera.worldToClient(113, 40);

zoomToClientPos(leftupLonlat, rightdownLonlat)

相机漫游到地图指定范围
Parameters:
Name Type Description
leftupLonlat Coordinate 左上角经纬度坐标
rightdownLonlat Coordinate 右下角经纬度坐标
Example
var camera = olView.getCamera();
camera.zoomToClientPos([100,40], [130,10]);

move(offsetX, offsetY)

移动相机
Parameters:
Name Type Description
offsetX Number 相机向x方向(屏幕向右为正)移动的像素
offsetY Number 相机向y方向(屏幕向下为正)移动的像素
Example
var camera = olView.getCamera();
camera.move(10,10); // 相机向右移动10像素,向下移动10像素

rotate(deltaDegree [, opt_anchor])

旋转相机
Parameters:
Name Type Argument Description
deltaDegree Number 相机旋转角度,逆时针为正。说明:相机逆时针旋转,看到的地图则是顺时针旋转
opt_anchor Coordinate <optional>
旋转的锚点,基于该点进行旋转,默认为屏幕中心
Example
var camera = olView.getCamera();
camera.rotate(5); // 相机逆时针旋转5度

zoom(delta [, opt_anchor])

缩放相机
Parameters:
Name Type Argument Description
delta Number 相机缩放层级
opt_anchor Coordinate <optional>
缩放的锚点,基于该点进行缩放,默认为屏幕中心
Example
var camera = olView.getCamera();
camera.zoom(1); // 相机缩放层级增加1级

flyTo(options [, center] [, zoom] [, resolution] [, rotation] [, duration] [, easing] [, callback])

Parameters:
Name Type Argument Default Description
options Object
center Coordinate <optional>
飞行到目的地所在的的经纬度位置
zoom number <optional>
飞行到目的地所在的缩放层级,如果设置了zoom,则resolution参数无效。
resolution number <optional>
飞行到目的地所在的分辨率,如果设置了zoom,则当前参数无效。
rotation number <optional>
飞行到目的地所在的旋转角度
duration number <optional>
1000 飞行时间(毫秒)
easing function <optional>
The easing function used during the animation (defaults to module:ol/easing~inAndOut). The function will be called for each frame with a number representing a fraction of the animation's duration. The function should return a number between 0 and 1 representing the progress toward the destination state.
callback function <optional>
回调函数,飞行到目的地之后调用
Examples
var camera = olView.getCamera();
camera.flyTo({
    zoom: 6
});
var camera = olView.getCamera();
camera.flyTo({
    center: [116,39],
    zoom: 5
});