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.
add
Description: This method is used to add a new layer to the reearth scene. This method is crucial 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: 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. The structure of the Layer object is as follows:
Layer Type Reference
Return Value
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 manipulations or queries. If the operation fails, it returns undefined.
Description: This method provides a way to search for a layer within the reearth scene based on a custom search function. This method is crucial for locating a specific layer that matches certain criteria, such as attributes, properties, or conditions defined dynamically. The method takes a callback function that evaluates each layer and returns true for a layer that meets the desired conditions, facilitating targeted operations or analyses on specific parts of the scene.
Returns the first Layer object that satisfies the provided testing function. If no layer meets the criteria, the function returns undefined
Examples Usage:
findAll
Description: 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.
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 Usage:
findById
Description: 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.
Returns the Layer object if a layer with the specified ID is found. If no layer matches the provided ID, it returns undefined.
Example Usage:
findByIds
Description: 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.
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 Usage:
findFeatureById
Description: This method provides a way to retrieve a feature associated with the feature ID. This function accepts a spread of string arguments, each representing 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.
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 Usage:
findFeaturesByIds
Description: This is designed to retrieve all features that are labeled with one or more specified feature IDs. This function accepts a spread of string arguments, each representing the ID of a layer and the ID of features, and returns an array of Feature objects that match the provided layer ID and Feature ID.
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 Usage:
hide
Description: This method is designed to hide a layer or group of 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.
Return Value: None (void). The method does not require any input parameters and performs its operation without returning a value.
Example Usage:
show
Description: 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.
Return Value: None (void). The method does not require any input parameters and performs its operation without returning a value.
Example Usage:
delete
Description: This method is used to delete specified layers within the reearth scene. This function removes only temporary layers added by the Plugin API. This function allows users to programmatically control which layers are deleted, making it a crucial for managing the layers. The method takes the ID of the layer as its primary argument.
Return Value: None (void). The method does not require any input parameters and performs its operation without returning a value.
Example Usage:
override
Description: This method dynamically overrides or sets a specific property 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.
Return Value: None (void). The method does not require any input parameters and performs its operation without returning a value.
Example Usage:
overridden
Description: 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.
Description: This method is used to programmatically select a specific layer within the reearth scene. This function is essential for highlighting or focusing on a particular layer, potentially triggering additional UI elements or actions, such as displaying an infobox or other contextual information.
Return Value: None (void). The method does not require any input parameters and performs its operation without returning a value.
Example Usage:
selectFeature
Description:Description: 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.
Return Value: None (void). The method does not require any input parameters and performs its operation without returning a value.
Example Usage:
selectFeatures
Description:Description: 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.
Return Value: None (void). The method does not require any input parameters and performs its operation without returning a value.
Example Usage:
selected
Description: This represents the currently selected layer within a reearth project. It is an optional property that holds a Layer 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:reearth.layers.selected?: Layer;
Example Usage:
selectedFeature
Description: 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, modifying properties, or displaying additional information in UI components.