<aside> 💡 Layer and its objects can be accessed in the reearth.layers namespace, most especially when a user Iterates over Layers.

</aside>

THE LAYER OBJECT:

Layer<P = any, IBP = any> = {
  id: string;
  type?: string;
  pluginId?: string;
  extensionId?: string;
  title?: string;
  property?: P;
  infobox?: Infobox<IBP>;
  isVisible?: boolean;
  propertyId?: string;
  tags?: Tag[];
  readonly children?: Layer<P, IBP>[];
  creator?: string;
};

Properties:

id:

Description: This property represents the unique identifier associated with a specific layer within the reearth scene. This identifier is a string that is used to distinctly recognize and reference the layer across reearth The ID is crucial for various operations involving layers, such as retrieving layer details, manipulating layer properties, or linking layers with other data and functionalities within the application. It ensures that each layer can be uniquely and consistently identified throughout the lifecycle of the scene.

Type:

id: string;

string //This property is a string that serves as the unique identifier for the layer. It is typically assigned when the layer is created and remains constant, providing a reliable reference for accessing and managing the layer.

type:

Description: Specifies the type of a particular layer within the reearth scene. This type classification is used to describe the layer's function or the kind of content it holds, providing context about its role and usage within the application. Common types might include 'tile', 'vector', 'polygon', 'marker', and more, each defining a different kind of graphical or data representation in the scene.

Type:

type?: string;

string // This property is a string that categorizes the layer, indicating what kind of data the layer represents or what functionality it provides within the Reearth environment.

pluginId:

Description: This is an optional attribute that links a specific layer to a plugin within a reearth project. This property holds the identifier (ID) of the plugin that is associated with the layer, enabling the layer to utilize functionalities or visual enhancements provided by that plugin. The association with a plugin ID allows the layer to inherit or implement custom behaviors, rendering options, or data processing features that are defined by the plugin, enhancing the layer's capabilities beyond the standard features offered by reearth.

Type:

pluginId?: string;

string //This is an optional string that serves as the unique identifier for a plugin associated with the layer. If present, it indicates that the layer is linked to and potentially influenced by the specified plugin. If this property is undefined, it implies that the layer does not have any direct association with a plugin.

extensionId:

Description: This property identifies a specific extension associated with the layer. It holds the identifier (ID) of the extension that enhances or modifies the functionality of the layer within a reearth project. Extensions can provide additional capabilities such as custom visual effects, data manipulation tools, or interaction features that extend the layer's standard functionalities. The extensionId allows the layer to leverage specialized behaviors or processes defined by the extension, thereby enriching the layer's integration and interaction within the project's environment.

Type:

extensionId?: string;

string // This is an optional string that acts as the unique identifier for an extension associated with the layer. If this property is set, it indicates that the layer utilizes the functionalities provided by the linked extension. If the property is undefined, it implies that the layer is not currently linked to any specific extension.

title:

Description: This property represents the title or name of the layer. It is used to provide a human-readable label for the layer, which can be displayed in user interfaces, legends, or when listing layers within a project. The title helps users easily identify and distinguish between different layers, enhancing the usability and organization of the project. It is particularly useful in complex projects with many layers, where a clear, descriptive title can significantly improve navigation and management of the layers.

Type:

title?: string;

string //  serves as the descriptive name or title of the layer. If provided, it is used to label the layer in various parts of the user interface. If this property is undefined, the layer may be displayed without a specific title, depending on the default settings of the Reearth platform or the specific application configuration.

property:

Description: This holds custom data associated with a specific layer. It is a flexible and dynamic container that can store any type of data specific to the layer, typically defined or structured according to the needs of the application or the specific type of layer. For example, properties can include configuration settings, display options, metadata, or any other custom parameters that enhance or modify the behavior and presentation of the layer. The use of a generic type parameter P allows for strong typing in TypeScript, enabling developers to define what the structure of property should look like for different kinds of layers, ensuring type safety and consistency across the application.

Type:

property?: P;

P?: //This is a generic optional property (P), where P can be any type defined by the developer. This design allows for maximum flexibility and customization, catering to the specific needs of each layer within the application. 
		// The type could range from simple structures like { color: string; size: number } to more complex nested objects depending on what data needs to be associated with a particular layer. 
		// If the property is undefined, it indicates that no custom properties are set for the layer, and it will rely on default behavior or settings.

infobox:

Description: This is an optional attribute that provides a mechanism for attaching an informational box, or "infobox," to a layer. This infobox is designed to display additional details or interactive content associated with the layer, enhancing user engagement and understanding. The infobox can be customized to contain a variety of content types, structured according to the needs of the project or specific user interactions. It uses a generic type parameter, IBP, allowing developers to define the structure of the content within the infobox, ensuring that the data is consistent with the application's requirements and type-safe if using TypeScript.

<aside> 💡 The Infobox structure is explained in details here.

</aside>

Type:

Infobox<IBP>? // A generic optional property where IBP (Infobox Properties) can be any type defined by the developer to structure the infobox content. This property is highly customizable and can contain varied types of data, from simple text and images to complex structured data like tables or interactive elements. 
							// The specific structure might include fields like title, description, and others, depending on how the infobox is intended to interact with the user. If the property is undefined, it means that no infobox is currently associated with the layer, either because it is not needed or it has not been set up.
							
Infobox Structure:
	Infobox<BP = any> = {
  property?: InfoboxProperty; // (Optional) - Defines the default appearance and behavior settings of the infobox. These settings can include visual and functional properties such as size, position, padding, background color, typography, and more.
  blocks?: Block<BP>[]; //An array of Block objects, each potentially representing a different piece of content or functionality within the infobox. Each block can be a distinct component, like a text block, image, or interactive element, and is defined by its own properties.
};

isVisible:

Description: This is an optional boolean attribute that determines the visibility status of a layer within a reearth project. This property is crucial for controlling whether a layer is displayed or hidden in the user interface. Setting this property to true makes the layer visible to the user, while setting it to false hides the layer from view. This feature is particularly useful in managing complex projects with multiple layers, allowing users to customize their view by toggling the visibility of specific layers according to their needs or the requirements of the project.

Type:

isVisible?: boolean;

boolean?: // Indicates whether the layer is currently visible (true) or hidden (false) in the project. If this property is undefined, it typically implies that the layer's visibility is inheriting the default setting, which could either be defined by the system or set through other means in the project configuration.

propertyId:

Description: This serves as a unique identifier linking a layer to a specific set of properties stored externally. This identifier allows the layer to reference a predefined set of properties, which might include configurations, metadata, or any other custom attributes defined outside of the layer itself. By utilizing a propertyId, layers can share and inherit properties dynamically, facilitating consistent configurations across multiple layers without redundancy and simplifying the management of properties that are common to several layers.

Type:

propertyId?: string;

string?: // This acts as the unique identifier for a set of properties. If present, it indicates that the layer is linked to an external property set, which can be retrieved and applied to the layer based on this ID. 
				 // If this property is undefined, it implies that the layer does not currently reference any external set of properties and relies solely on properties defined locally within the layer or defaults provided by the system.

tags:

Description: This holds a collection of tags associated with a specific layer. Tags are useful for categorizing, grouping, or filtering layers, making it easier to manage, organize, and access layers in complex projects. Each tag provides a label to describe the category or characteristic it represents, and tags can also contain nested sub-tags, allowing for hierarchical grouping and more detailed organization.

Type:

tags?: Tag[] //This is an optional array of Tag objects. If present, this array provides additional metadata and categorization for the layer.

Tag Structure:
	id: string // A unique identifier for the tag, used to manage or reference the tag programmatically.
	label: string // A human-readable label that describes the tag's purpose or category.
	tags?: Tag[] // (Optional) - An optional array of sub-tags, enabling hierarchical categorization. Each sub-tag also has an id, label, and potentially its own nested tags.

children:

Description: This property holds an array of Layer objects, representing the child layers of a particular parent layer. This hierarchical organization allows for the structuring of layers in a tree-like fashion, where each layer can contain multiple sub-layers, facilitating complex layer management and nested data visualization scenarios. Each child layer can itself have its own properties, infobox content, visibility settings, and potentially further nested child layers.

Type:

children?: Layer<P, IBP>[] // An optional array of Layer objects, where each Layer may have its custom properties (P) and infobox properties (IBP). 
													 // The generic parameters P and IBP allow for flexibility in defining the types of properties and infobox content associated with each layer, ensuring that the layer data can be strongly typed and tailored to the specific needs of the application.
													 // It returns undefined if the layer has no children

Example Usage:

// Function to log details of a layer and its children recursively
function logLayerDetails(layer, depth = 0) {
    const indent = ' '.repeat(depth * 2);
    console.log(`${indent}Layer ID: ${layer.id}, Title: ${layer.title}`);
    if (layer.children) {
        console.log(`${indent}Children:`);
        layer.children.forEach(child => logLayerDetails(child, depth + 1));
    }
}

// Assuming a layer object with nested children
const layer = {
    id: "parentLayer",
    title: "Parent Layer",
    children: [
        { id: "child1", title: "Child Layer 1" },
        { id: "child2", title: "Child Layer 2" }
    ]
};

// Log details of the layer and its children
logLayerDetails(layer);

Examples Without Comments

creator:

Description: This property identifies the creator of a specific layer. This string property typically holds the username, user ID, or another identifier of the individual or entity responsible for creating the layer. By tracking the creator of each layer, the property provides additional context about the layer's origin, which can be useful for managing permissions, understanding contributions within collaborative projects, or maintaining records of authorship.

Type:

creator?: string;

string // This specifies the identifier of the creator of the layer. If this property is set, it indicates who created the layer, adding a layer of accountability and traceability to the actions performed on the platform.
			 // If the property is undefined, it suggests that the creator's information is not available or not applicable for the layer, which might be the case for system-generated layers or those migrated from other sources without creator metadata.