GlobeViewport (Experimental)
The GlobeViewport
class takes globe view states (latitude
, longitude
, and zoom
), and performs projections between world and screen coordinates. It is a helper class for visualizing the earth as a 3D globe.
Usage
A GlobeViewport
instance is created under the hood by a GlobeView.
import {_GlobeViewport as GlobeViewport} from '@deck.gl/core';
const viewport = new GlobeViewport({
width: 600,
height: 400,
longitude: -122.45,
latitude: 37.78,
zoom: 12
});
viewport.project([-122.45, 37.78]);
// [300,200]
Constructor
new GlobeViewport({width, height, longitude, latitude, zoom});
Parameters:
opts
(object) - Globe viewport optionswidth
(number) - Width of the viewport.height
(number) - Height of the viewport.
geospatial arguments:
latitude
(number, optional) - Latitude of the viewport center on map. Default to0
.longitude
(number, optional) - Longitude of the viewport center on map. Default to0
.zoom
(number, optional) - Map zoom (scale is calculated as2^zoom
). Default to11
.altitude
(number, optional) - Altitude of camera, 1 unit equals to the height of the viewport. Default to1.5
.
projection matrix arguments:
nearZMultiplier
(number, optional) - Scaler for the near plane, 1 unit equals to the height of the viewport. Default to0.1
.farZMultiplier
(number, optional) - Scaler for the far plane, 1 unit equals to the distance from the camera to the top edge of the screen. Default to1
.
Remarks:
width
andheight
are forced to 1 if supplied as 0, to avoid division by zero. This is intended to reduce the burden of apps to check values before instantiating aViewport
.- Per cartographic tradition, longitudes and latitudes are specified as degrees.
Inherits all Viewport methods.
Methods
Inherits all methods from Viewport.
project
Projects world coordinates to pixel coordinates on screen.
Parameters:
coordinates
(number[]) -[longitude, latitude, altitude]
.altitude
is in meters and default to0
if not supplied.opts
(object)topLeft
(boolean, optional) - Whether projected coords are top left. Default totrue
.
Returns:
[x, y]
or[x, y, z]
in pixels coordinates.z
is pixel depth.- If input is
[longitude, latitude]
: returns[x, y]
. - If input is
[longitude, latitude: altitude]
: returns[x, y, z]
.
- If input is
unproject
Unproject pixel coordinates on screen into world coordinates.
Parameters:
pixels
(number[]) -[x, y, z]
in pixel coordinates. Passing az
is optional.opts
(object)topLeft
(boolean, optional) - Whether projected coords are top left. Default totrue
.targetZ
(number, optional) - If pixel depthz
is not specified inpixels
, this is used as the elevation plane to unproject onto. Default0
.
Returns:
[longitude, latitude]
or[longitude, latitude, altitude]
in world coordinates.altitude
is in meters.- If input is
[x, y]
without specifyingopts.targetZ
: returns[longitude, latitude]
. - If input is
[x, y]
withopts.targetZ
: returns[longitude, latitude, targetZ]
. - If input is
[x, y, z]
: returns[longitude, latitude, altitude]
.
- If input is