cameraToPosition()
Information
Implementation version: beta 1.00
Updated in: beta 1.09
Description
Moves the map viewer's camera to some specific coordinates (either geographic or Cartesian ones) in the map, at a given altitude, and with the possibility of defining a heading, pitch and roll.
Invocation
cameraToPosition( zoomType, coordinates, height*, heading*, pitch*, roll* )
* Optional parameters
Input parameters
zoomType
The type of zoom that the viewer's camera will perform. The parameter to enter is type text, and accepts one of these two options:
- fly:Â implies a smooth movement from the camera's current position to its final position.
- zoom:Â instant scrolling to the camera's final position.
coordinates
The value of the coordinates to zoom. Depending on the type of coordinates that you want to enter (geographical or Cartesian), this parameter will be different. The difference is:
- Geographical coordinates: the parameter will be a list with two numerical values; the first between -180 and 180, and the second between -90 and 90: [-15.43, 28.12]
- Cartesian coordinates: the parameter will be an object with three elements of type Cartesian3:Â {x: 0.0, y: 0.0, z: 0.0}
height
Optional parameter. If not included, it uses the default value 5000. It corresponds to the numerical value of the height at which the viewer camera will be placed. If Cartesian coordinates are being used and this value exists, this value will overwrite the altitude value already implied.
heading
Optional parameter. If not included, it uses the default value 0. It refers to the camera heading with respect to the north, receiving a numerical value between 0 and 360.
pitch
Optional parameter. If not included, it uses the default value -90. It defines the camera's pitch with respect to the horizontal plane, accepting a numerical value between -180 and 180.
roll
Optional parameter. If not included, it uses the default value 0. It specifies the camera's roll with respect to its axis of vision (warping).
More on pitch, roll and warp
If you want to know a little better the concepts of pitch, roll and warping of the camera, this post from the Google group of Cesium gives a good explanation.
Use examples
Define the viewer's start view on the El Retiro park in Madrid, calling the function after the viewer has been declared:
viewer = new Cesium.Viewer('cesiumContainer') cameraToPosition( 'zoom', [-3.683881,40.414404], 1500 )
Softly the camera from its current position in the map to the central area of ​​Las Palmas de Gran Canaria, without defining any specific height:
cameraToPosition( 'fly', [-15.4351,28.1195] )
Center the camera directly on the coordinates of the viewer's first dataSource's first entity, placing the camera 500 meters high:
cameraToPosition( 'zoom', viewer.dataSources._dataSources[0].entities.values[0].position._value, 1500 )
By executing in the console the call to viewer.dataSources._dataSources [0] .entities.values ​​[0] .position._value, you get a Cartesian coordinate object, which in this case would be {x: 4899369.464544161, and: -547533.5655109598, z : 4033284.450355943}. Hence, this call can be used as a parameter.