Camera

相机

new YS.Camera(global)

三维球中的相机类,控制视角等
Name Type Description
global Object 三维球对象(YouScene.earth)

Members

readonlycameraAltitude : Number

相机高程

readonlycameraFarDis : Number

相机视锥的远平面距离

readonlycameraFov : Number

相机视锥的视角

readonlycameraHeading : Number

相机方向角度(相机视线方向与正北方的夹角,其中正北方为0度,正东方为90度,范围0~360度)

readonlycameraLatitude : Number

相机纬度

readonlycameraLongitude : Number

相机经度

readonlycameraNearDis : Number

相机视锥的近平面距离

readonlycameraPitch : Number

相机俯仰角度(相机视线方向与水平方向的夹角,其中水平方向为0度,垂直向下为-90度)

readonlycameraViewRange

相机视图的最大宽度(角度)

readonlycameraViewRect

相机视图范围

maximumZoomDistance : Number

相机缩放的最大高度
Default Value: Infinity

minimumZoomDistance : Number

相机缩放的最小高度
Default Value: 20

readonlypixelWidth

当前视图一个像素代表的经纬度

readonlypixelWidthM

当前视图一个像素代表的米,未知时0

readonlyterrainElevation : Number

相机地面高程

readonlyviewDistance

相机位置到目标(三维地球当前视图中心点)的距离

readonlyviewerCenter

视图中心点坐标,即十字丝坐标经纬度,单位xy是度z是米

Methods

cancelFlight()

取消当前的飞行动作

earthRotation(ys, axis, time, direction, callback)Camera~RemoveCollback

地球自转, 默认转动轴为从南到北的极地轴, 默认转动时间为地球自转时间,也就是24小时
Name Type Default Description
ys Object YouScene对象
axis Object {x: 0, y: 0, z: 1} optional 转动轴
time Number 24 * 60 * 60 optional 转动一周所需时间,单位秒
direction Boolean true optional 顺时针或者逆时针旋转(true为逆时针,false为顺时针)
callback Camera~Callback 飞行中的回调函数,不间断返回已经过时间
Returns:
返回飞行结速函数,调用此函数即可结速飞行

fly(longitude, latitude, altitude, second)Promise

相机飞到某位置,等同flytoLonLatAlt
Name Type Description
longitude Number optional 相机经度,单位度
latitude Number optional 相机纬度,单位度
altitude Number optional 相机高程,单位米
second Number optional 飞行时间,单位秒, 默认值根据到目的地的距离动态计算
Returns:
飞行完成会触发Promise的resolve;取消飞行会触发reject
Example:
监听飞行动作完成和取消
ys.camera.fly(100, 20, 1000, 10).then(ok => { console.log(ok); }, cancel => { console.log(cancel); });

flyAroundPoint(ys, point, rotate, distance, time, direction, callback)Camera~RemoveCollback

相机绕点飞行一周
Name Type Default Description
ys Object YouScene对象
point Object 点的坐标{x: ,y: ,z: }
rotate Number 20 optional 相机看点的角度(90是俯视看,0是平视看)
distance Number 5000 optional 相机距离点的距离,单位m
time Number 10 optional 飞行一周所需时间,单位s
direction Boolean true optional 顺时针或者逆时针旋转(true为逆时针,false为顺时针)
callback Camera~Callback 飞行中的回调函数,不间断返回已经过时间
Returns:
返回飞行结速函数,调用此函数即可结速飞行

flyto(options)Promise

相机飞到某位置和角度
Name Type Description
options Object 对象有下面这些属性
Name Type Description
lon Number optional 相机经度,单位度
lat Number optional 相机纬度,单位度
alt Number optional 相机高程,单位米
heading Number optional 相机方向角度, 范围[0, 360],单位度
pitch Number optional 相机俯仰角度,范围[-90, 0],单位度
second Number optional 飞行时间,单位秒
Returns:
飞行完成会触发Promise的resolve;取消飞行会触发reject

flytoLonLatAlt(longitude, latitude, altitude, second)Promise

相机飞到某位置
Name Type Description
longitude Number optional 相机经度,单位度
latitude Number optional 相机纬度,单位度
altitude Number optional 相机高程,单位米
second Number optional 飞行时间,单位秒
Returns:
飞行完成会触发Promise的resolve;取消飞行会触发reject

flytoRect(rectangle, second)Promise

相机飞到目标视图范围
Name Type Description
rectangle Rectangle 目标视图范围{ west: -180, south: -90, east: 180, north: 90 }
second Number optional 飞行时间(秒)
Returns:
飞行完成会触发Promise的resolve;取消飞行会触发reject

getCameraViewRange()Number

相机视图的最大宽度(角度)
Returns:

getCameraViewRect()Rectangle

相机视图范围
Returns:

getPixelWidth()Number

当前视图一个像素代表的经纬度
Returns:

getPixelWidthM()Number

当前视图一个像素代表的米,未知时0
Returns:

getRectCameraPosition(rect)XYZ

根据视角矩形范围获取相机坐标
Name Type Default Description
rect Rectangle new Rectangle(-180, -90, 180, 90) optional 矩形范围
Returns:
相机坐标,(如果相机坐标不存在,则返回undefined)

getViewDistance()Number

相机位置到目标(三维地球当前视图中心点)的距离
Returns:

getViewerCenter()XYZ

视图中心点坐标,即十字丝坐标经纬度,单位xy是度z是米
Returns:

goto(options)

相机定位到某位置和角度
Name Type Description
options Object 对象有下面这些属性
Name Type Description
lon Number optional 相机经度,单位度
lat Number optional 相机纬度,单位度
alt Number optional 相机高程,单位米
heading Number optional 相机方向角度, 范围[0, 360],单位度
pitch Number optional 相机俯仰角度, 范围[-90, 0],单位度

gotoLonLatAlt(longitude, latitude, altitude)

相机定位到某位置
Name Type Description
longitude Number optional 相机经度,单位度
latitude Number optional 相机纬度,单位度
altitude Number optional 相机高程,单位米

gotoLonLatHeadViewRange(longitude, latitude, heading, viewRange)

设置相机经纬度、方向角度、视图宽度
Name Type Description
longitude Number 目标经度
latitude Number 目标纬度
heading Number Z轴旋转角度
viewRange Number 目标视图宽度

gotoLonLatViewRange(longitude, latitude, viewRange)

设置相机经纬度、视图宽度
Name Type Description
longitude Number 目标经度
latitude Number 目标纬度
viewRange Number 目标视图宽度

gotoRect(rectangle)

相机定位到目标视图范围
Name Type Description
rectangle Rectangle 目标视图范围{ west: -180, south: -90, east: 180, north: 90 }

lookAt(options)Promise

相机飞到某位置,视线定位到目标点
Name Type Description
options Object 对象有下面这些属性
Name Type Description
lon Number optional 目标点的经度,单位度
lat Number optional 目标点的纬度,单位度
alt Number optional 目标点的高度,单位米
distance Number optional 相机和目标点之间的距离,单位米
heading Number optional 相机方向角度, 即目标点相对于相机的方向角度,范围[0, 360],单位度
pitch Number optional 相机俯仰角度,即目标点相对于相机的俯仰角度,范围[-90, 0],单位度
second Number optional 飞行时间,单位秒,为0则直接定位
Returns:
飞行完成会触发Promise的resolve;取消飞行会触发reject

reset()

重置相机

rotate(axis, angle, second)Promise

相机围绕某点所在的轴线旋转
Name Type Description
axis XYZ optional 轴点的位置,单位度 {x:180, y:90, z:0}
angle Number optional 旋转的角度,单位度
second Number optional 飞行时间,单位秒,为0则直接定位
Returns:
旋转完成会触发Promise的resolve;取消旋转会触发reject

spinAround(ys, pitch, second, direction, callback)Camera~RemoveCollback

相机原地旋转一周
Name Type Default Description
ys Object YouScene对象
pitch Number 20 optional 相机俯仰角度, 范围[0, 90],(90是俯视,0是平视)
second Number 10 optional 旋转一周时间(秒)
direction Boolean true optional 顺时针或者逆时针旋转(true为逆时针,false为顺时针)
callback Camera~Callback 飞行中的回调函数,不间断返回已经过时间
Returns:
返回飞行结速函数,调用此函数即可结速飞行

Type Definitions

Callback(time)

飞行过程中回调函数
Name Type Description
time Number 返回经过时间

RemoveCollback()

飞行过程中回调函数 执行此函数可结速飞行

Events

changed

相机视域改变事件
Properties:
Name Type Description
percentChanged Number 视域范围变化量百分比,从完全未变0.0到完全改变1.0

heightChanged

相机高度改变事件
Properties:
Name Type Description
newHeight Number 改变后相机高度
oldHeight Number 改变前相机高度