reearth.viewer
The reearth.viewer
namespace provides a set of functions to interact with the viewer.
Properties
property
property
provides a set of properties about the viewer, including globe, terrain, scene, tiles, sky, and more.
Syntax
Return Value
Type ViewerProperty
Currently, property returns only the properties that have been explicitly set; default values are not included.
viewport
The viewport is designed to provide properties related to the map area and includes the URL query parameters for the current viewport (page).
Syntax
Return Value
Type
- width: The width of the viewport.
- height: The height of the viewport.
- isMobile: A boolean value that indicates whether the viewport is a mobile device. Currently width <=
768
is considered a mobile device. - query: The URL query parameters for the current page.
env
env
provides the env info of current running Re:Earth Visualizer.
Syntax
Return Value
Type
inEditor
and isBuilt
has different values when running in different page or tab, plugin could provide different behavior based on these values.
Property | Editor - Map/Story/Widgets Tab | Editor - Publish Tab | Published Page |
---|---|---|---|
inEditor | true | false | false |
isBuilt | false | false | true |
interactionMode
interactionMode
provides a set of properties and methods to manage the interaction mode of the viewer in Re:Earth Visualizer.
interactionMode.mode
Current interaction mode of the viewer.
Syntax
Return Value
Type InteractionModeType = "default" | "move" | "selection" | "sketch"
default
: Default interaction mode.move
: Move interaction mode. Selection is disabled in this mode.selection
: Selection interaction mode. Move is disabled in this mode.sketch
: Sketch interaction mode. Sketch could be enabled in this mode only.
interactionMode.override
Overrides the interaction mode of the viewer.
Syntax
Parameters
mode
Type: InteractionModeType
The interaction mode to be set.
Return Value
None (void)
. The method performs its operation without returning a value.
Methods
overrideProperty
overrideProperty
is used to override the viewer property.
Syntax
Parameters
property
Type ViewerProperty
Return Value
Type void
This Method has no return value.
Example
capture
capture
function could generate an image for current viewer.
Syntax
Parameters
type
Type string
(optional)
A string indicating the image format. The default type is image/png; this image format will be also used if the specified type is not supported.
encoderOptions
Type number
(optional)
A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
Return Value
Type string | undefined
A string containing the requested data URL.
Example
tools
The tools module provides a collection of helper functions for performing various calculations around globe and scene.
> getLocationFromScreenCoordinate
Return the location on the earth from the screen coordinate.
Syntax
Parameters
x
Type number
The x pixel coordinate on the viewer.
y
Type number
The y pixel coordinate on the viewer.
withTerrain
Type boolean
(optional)
A boolean value that indicates whether the terrain height should be considered. The default value is false
.
Return Value
Type { lat: number; lng: number; height: number } | undefined
The location on the earth.
> getScreenCoordinateFromPosition
Return the screen coordinate from the position on the earth.
Syntax
Parameters
position
Type [x: number, y: number, z: number]
The position on the earth, in Cartesian.
Return Value
Type [x: number, y: number] | undefined
The pixel coordinate on viewer.
> getTerrainHeightAsync
Return the terrain height at the given location. This is an asynchronous function.
Syntax
Parameters
lat
Type number
The latitude of the location.
lng
Type number
The longitude of the location.
Return Value
Type Promise<number | undefined>
The height of the terrain at the given location.
> getGlobeHeight
Return the height of the surface at the given location.
Syntax
Parameters
lat
Type number
The latitude of the location.
lng
Type number
The longitude of the location.
Return Value
Type number | undefined
The height of the surface at the given location.
> cartographicToCartesian
Converts a cartographic position to a Cartesian position.
Syntax
Parameters
lng
Type number
The longitude of the location.
lat
Type number
The latitude of the location.
height
Type number
The height of the location.
options
Type { useGlobeEllipsoid?: boolean }
(optional)
- useGlobeEllipsoid: A boolean value that indicates whether the globe ellipsoid should be used. The default value is
false
.
Return Value
Type [x: number, y: number, z: number] | undefined
The Cartesian position.
> cartesianToCartographic
Converts a Cartesian position to a cartographic position.
Syntax
Parameters
x
Type number
The x coordinate of the location.
y
Type number
The y coordinate of the location.
z
Type number
The z coordinate of the location.
options
Type { useGlobeEllipsoid?: boolean }
(optional)
- useGlobeEllipsoid: A boolean value that indicates whether the globe ellipsoid should be used. The default value is
false
.
Return Value
Type [lng: number, lat: number, height: number] | undefined
The cartographic position.
> transformByOffsetOnScreen
Transforms the position by the offset on the screen.
Syntax
Parameters
rawPosition
Type [x: number, y: number, z: number]
The raw position on the earth.
screenOffset
Type [x: number, y: number]
The offset on the screen.
Return Value
Type [x: number, y: number, z: number] | undefined
The transformed position.
> isPositionVisibleOnGlobe
Check if the position is visible on the globe.
Syntax
Parameters
position
Type [x: number, y: number, z: number]
The position on the earth.
Return Value
Type boolean
A boolean value that indicates whether the position is visible on the globe.
Events
resize
resize
event will be triggered when the viewer is resized.
Syntax
Parameters
- width: The width of the viewport.
- height: The height of the viewport.
- isMobile: A boolean value that indicates whether the viewport is a mobile device. Currently width <=
768
is considered a mobile device.
Example
mouse events
Viewer has a set of mouse events that can be listened to. They have the same parameters.
Supported events are:
- click
- doubleClick
- mouseDown
- mouseUp
- rightClick
- rightDown
- rightUp
- middleClick
- middleDown
- middleUp
- mouseMove
- mouseEnter
- mouseLeave
- wheel
Syntax
Parameters
event: MouseEvent
- x: the x corrdinate of cursor relative to the viewer.
- y: the y corrdinate of cursor relative to the viewer.
- lat: the latitude of cursor on earth.
- lng: the longitude of cursor on earth.
- height: the height of cursor on earth.
- layerId: the layerId of the object that cursor is on.
- delta: the delta value of wheel event.