reearth.layers
The reearth.layers
namespace provides a set of methods to manage and manipulate layers within a reearth scene, allowing plugin developers to add, find, modify, or delete layers programmatically.
Properties
layers
This property provides a list of all layers currently exists in the reearth
scene, allowing plugin developers to access and manipulate the layers as needed. The property returns an array of LazyLayer
objects, each representing a distinct layer within the scene.
Syntax
Return Value
Type LazyLayer[]
An array of LazyLayer
objects, each representing a distinct layer within the scene.
overridden
This is an optional property that provides a layer in the reearth
scene whose properties are overridden. This method allows users to confirm how the layer is overridden. The flexibility offered by this method is crucial for scenarios where layer properties need to be adjusted in response to user interactions, application state changes, or external data updates.
Syntax
Return Value
Type Omit<Layer, "type" | "children">
A type that excludes type
and children
from the Layer
type definition.
Example
selected
This represents the currently selected layer within a reearth
project. It is an optional property that holds a ComputedLayer
object if a layer is selected, or it may be undefined
if no layer is currently selected. This property provides an easy way to access details about the selected layer directly, facilitating operations or interactions that depend on the user’s selection, such as querying specific layer data, modifying properties, or displaying additional information in UI components.
Syntax
Return Value
Type ComputedLayer
A layer obtained after all processing is completed, containing both original and processed geographic data with applied & evaluated styles and states.
Example
selectedFeature
This represents the currently selected feature within a reearth
project. It is an optional property that holds a feature
object if a feature is selected, or it may be undefined
if no feature is currently selected. This property provides an easy way to access details about the selected feature directly, facilitating operations or interactions that depend on the user’s selection, such as querying specific feature data or displaying additional information in plugin extensions.
Syntax
Return Value
Type ComputedFeature
A single geographic feature (point, line, polygon, etc.) with all its final evaluated properties and styles applied.
Example
Methods
add
This method is used to add a new layer to the reearth
scene. This method is essential for dynamically enhancing the scene with additional content layers, which can include elements such as imagery, data representations, or interactive widgets. The method takes a Layer
object as its primary argument, which defines the characteristics and properties of the layer being added.
Syntax
Parameters
layer
Type: Layer
An object that includes all the data and metadata necessary to create and manage a layer. This object defines the characteristics and properties of the layer being added to the scene.
Return Value
Type string | undefined
The method returns the unique identifier id
of the newly added layer if the operation is successful, providing a reference that can be used for further operations or queries. If the operation fails, it returns undefined
.
Example
find
This method enables efficient searching for layers within the Reearth scene by applying a custom search function. It is helpful for identifying specific layers that meet dynamically defined criteria, such as particular attributes, properties, or conditions. The method accepts a callback function that evaluates each layer, returning true for layers that satisfy the specified conditions. This approach allows for precise operations or analyses on targeted parts of the scene, enhancing flexibility and control in layer management.
Syntax
Parameters
fn
Type: (layer: Layer, index: number) => boolean
A callback function used to evaluate each layer within the scene. The function receives three arguments:
layer: Layer
: An object that includes all the data of the layer.index: number
: The index of the current layer.
Return Value
Type Layer | undefined
Returns the first Layer
object that satisfies the provided testing function. If no layer meets the criteria, the function returns undefined
Example
findAll
This method performs a comprehensive search through all layers in a project to find and return an array of layers that match a specified condition. This method takes a callback function that is applied to each layer in the project.
Syntax
Parameters
layer
Type Layer
An object that includes all the data and metadata necessary to create and manage a layer.
index
Type number
The index of the current layer within its level of the hierarchy.
Return Value
Type Layer[]
Returns an array of Layer
objects that satisfy the conditions specified by the callback function. If no layers meet the criteria, it returns an empty array.
Example
findById
This method is designed to retrieve a specific layer object based on its unique identifier (ID). This method is essential for directly accessing a layer when its ID is known, allowing for efficient and precise operations such as editing properties, toggling visibility, or analyzing layer-specific data. It simplifies the process of interacting with individual layers by providing a direct path to them without the need to search or iterate through the entire layer hierarchy. This method takes a single string parameter, which is the ID of the layer you want to find.
Syntax
Parameters
layerId
Type string
The unique identifier of the layer that is being searched for within the scene.
Return Value
Type Layer | undefined
Returns the Layer
object if a layer with the specified ID is found. If no layer matches the provided ID, it returns undefined
.
Example
findByIds
This method allows for the retrieval of multiple layers from the reearth
scene simultaneously based on an array of layer IDs. This method is particularly useful for applications that need to interact with or manipulate several specific layers at once, such as batch updating properties, applying effects, or managing group visibility. This method accepts a spread of string arguments, each representing the ID of a layer, and returns an array where each element corresponds to a Layer
object or undefined
.
Syntax
Parameters
...layerIds
Type ...string[]
An array of layer ids, each representing the unique identifier of a layer to be retrieved. This allows for flexible input of one or multiple IDs.
When use it we should spread the array as multiple arguments.
Return Value
Type (Layer | undefined)[]
Returns an array containing Layer
objects or undefined
for each input ID, depending on whether the layer with that ID exists in the scene. Each position in the returned array corresponds directly to the position of the ID in the input list, maintaining order consistency. If a layer with a given ID does not exist, the method returns undefined
at that position in the array.
Example
findFeatureById
This method provides a way to retrieve a feature associated with the feature ID. This function accepts the ID of a layer and the ID of a feature and returns a Feature
objects that match the provided layer ID and Feature ID.
Syntax
Parameters
layerId
Type string
The unique identifier of the layer that is being searched for within the scene.
featureId
Type string
The unique identifier of the feature in the layer
Return Value
Type Feature | undefined
Returns a Feature
object if a feature with the specified ID is found in the specified layer. If no feature matches the provided ID, it returns undefined
.
Example
findFeaturesByIds
This is designed to retrieve all features that are labeled with one or more specified feature IDs. This function accepts one single layer ID and the IDs of features, and returns an array of Feature
objects that match the provided layer ID and Feature ID.
Syntax
Parameters
layerId
Type string
The unique identifier of the layer that is being searched for within the scene.
featureId
Type string[]
The unique identifier of features in the layer. This allows for flexible input of one or multiple IDs.
Return Value
Type (Feature[] | underined)
Returns an array of Feature
objects that have feature IDs found in the specified layer. If no features match the provided IDs, it returns undefined
.
Example
hide
This method is designed to hide one or more layers based on array of layer IDs provided. This function accepts a spread of string arguments, each representing the unique identifier (ID) of a layer. When invoked, this method sets the visibility of each specified layer to false
, effectively hiding them from view in the project. This is particularly useful for managing the display of layers dynamically, allowing developers to control which elements are visible to the end user at any given time based on specific conditions or interactions.
Syntax
Parameters
...layerIds
Type ...string[]
A spread of string parameters, where each string is the ID of a layer that needs to be hidden.
Return Value
Type None (void)
The method does not require any input parameters and performs its operation without returning a value.
Example
show
This method is used to set the visibility of specified layers within the reearth
scene to true. This function allows users to programmatically control which layers are visible to the user, making it a crucial tool for managing the display of various data sets, features, or graphical elements on the map or scene. It is particularly useful in scenarios where layers need to be dynamically shown or hidden based on user interactions, application states, or specific conditions.
Syntax
Parameters
...layerIds
Type ...string[]
A spread of string parameters, where each string is the ID of a layer that needs to be made visible.
Return Value
Type None (void)
The method does not require any input parameters and performs its operation without returning a value.
Example
delete
This method is used to delete specified layers within the reearth
scene. This function removes only temporary layers added by the Plugin API. The method takes the ID of the layer as its primary argument.
Syntax
Parameters
...layerIds
Type ...string[]
A spread of string parameters, where each string is the ID of a layer that needs to be made visible.
Return Value
Type None (void)
The method does not require any input parameters and performs its operation without returning a value.
Example
override
This method dynamically overrides properties for a designated layer identified by its ID. This function can modify the layer properties. The method allows for modifying layer properties on-the-fly, such as visibility, color, or any custom attributes that might have been defined in the layer’s structure. This dynamic manipulation is essential for responsive applications where layer attributes need to change in response to user interactions, data updates, or other application logic, without permanently altering the original layer configuration. This function takes two parameters: the ID of the layer and the partial layer object.
Syntax
Parameters
layerId
Type string
The unique identifier of the layer whose property is to be overridden.
properties
Type Partial<Layer>
It represents an object that can optionally include any properties from the Layer type.
Return Value
Type None (void)
The method does not require any input parameters and performs its operation without returning a value.
Example
select
This method is used to programmatically select a specific layer within the reearth
scene.
Syntax
Parameters
layerId
Type string
The unique identifier of the layer to be selected.
Return Value
Type None (void)
The method does not require any input parameters and performs its operation without returning a value.
Example
selectFeature
This method is used to programmatically select a specific feature within the reearth
scene. This function is essential for highlighting or focusing on a particular feature, potentially triggering additional UI elements or actions, such as displaying an infobox or other contextual information.
Syntax
Parameters
layerId
Type string
The unique identifier of the layer to be selected.
featureId
Type string
The unique identifier of the feature in the layer
Return Value
Type None (void)
The method does not require any input parameters and performs its operation without returning a value.
Example
selectFeatures
This method is used to programmatically select specific features within the reearth
scene. This function is essential for highlighting or focusing on a particular feature, potentially triggering additional UI elements or actions, such as displaying an infobox or other contextual information.
Syntax
Parameters
targets
Type { layerId?: string; featureId?: string[] }[]
layerId: string
: The unique identifier of the layer to be selected.featureId: string[]
: An array of string parameters, where each string is the ID of a feature
Return Value
Type None (void)
The method does not require any input parameters and performs its operation without returning a value.
Example
Events
select
This event is triggered when a layer is selected within the reearth
scene. It provides a way to listen for layer selection events and respond to them with custom actions or behaviors.
Syntax
Parameters
selection
Type LayerSelection:[layerId: string | undefined, featureId: string | undefined]
layerId: string | undefined
: The unique identifier of the selected layer.featureId: string | undefined
: The unique identifier of the selected feature.
Example
References
Layer Type
An object that includes all the data and metadata necessary to create and manage a layer.
LazyLayer Type
A lightweight representation of a layer.
ComputedLayer Type
A layer obtained after all processing is completed, containing both original and processed geographic data with applied & evaluated styles and states.
Layer Appearance Types
Properties for each layer type.
Feature Type
An object that includes all the data and metadata necessary to create and manage a feature.
ComputedFeature Type
A single geographic feature (point, line, polygon, etc.) with all its final evaluated properties and styles applied.