new Camera()
二维相机
Methods
-
clientToWorld(x, y)
-
屏幕坐标转地图经纬度坐标
Parameters:
Name Type Description xNumber 屏幕x坐标 yNumber 屏幕y坐标 -
worldToClient(lon, lat)
-
地图经纬度坐标转屏幕坐标
Parameters:
Name Type Description lonNumber 地图坐标,经度 latNumber 地图坐标,纬度 Example
var camera = olView.getCamera(); var screenPos = camera.worldToClient(113, 40);
-
zoomToClientPos(leftupLonlat, rightdownLonlat)
-
相机漫游到地图指定范围
Parameters:
Name Type Description leftupLonlatCoordinate 左上角经纬度坐标 rightdownLonlatCoordinate 右下角经纬度坐标 Example
var camera = olView.getCamera(); camera.zoomToClientPos([100,40], [130,10]);
-
move(offsetX, offsetY)
-
移动相机
Parameters:
Name Type Description offsetXNumber 相机向x方向(屏幕向右为正)移动的像素 offsetYNumber 相机向y方向(屏幕向下为正)移动的像素 Example
var camera = olView.getCamera(); camera.move(10,10); // 相机向右移动10像素,向下移动10像素
-
rotate(deltaDegree [, opt_anchor])
-
旋转相机
Parameters:
Name Type Argument Description deltaDegreeNumber 相机旋转角度,逆时针为正。说明:相机逆时针旋转,看到的地图则是顺时针旋转 opt_anchorCoordinate <optional>
旋转的锚点,基于该点进行旋转,默认为屏幕中心 Example
var camera = olView.getCamera(); camera.rotate(5); // 相机逆时针旋转5度
-
zoom(delta [, opt_anchor])
-
缩放相机
Parameters:
Name Type Argument Description deltaNumber 相机缩放层级 opt_anchorCoordinate <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 optionsObject centerCoordinate <optional>
飞行到目的地所在的的经纬度位置 zoomnumber <optional>
飞行到目的地所在的缩放层级,如果设置了zoom,则resolution参数无效。 resolutionnumber <optional>
飞行到目的地所在的分辨率,如果设置了zoom,则当前参数无效。 rotationnumber <optional>
飞行到目的地所在的旋转角度 durationnumber <optional>
1000 飞行时间(毫秒) easingfunction <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. callbackfunction <optional>
回调函数,飞行到目的地之后调用 Examples
var camera = olView.getCamera(); camera.flyTo({ zoom: 6 });var camera = olView.getCamera(); camera.flyTo({ center: [116,39], zoom: 5 });