Skip to main content

Overview

LayerInterface is the base interface for all map layers in the Open Mobile Maps SDK. It defines the contract for layer lifecycle management, rendering, visibility control, and interaction with the map. Layers are responsible for building render passes and managing their visual state. Header Location: shared/public/LayerInterface.h:20

Lifecycle Methods

onAdded
void
Called when the layer is added to a map.
onRemoved
void
Called when the layer is removed from the map.
pause
void
Pauses the layer, typically stopping animations and data updates.
resume
void
Resumes the layer after being paused.
forceReload
void
Forces the layer to reload all its data and resources.

Rendering Methods

update
void
Updates the layer state before rendering. Called each frame to prepare the layer for rendering.
buildRenderPasses
std::vector<std::shared_ptr<RenderPassInterface>>
Builds and returns the render passes for this layer.
return
std::vector<std::shared_ptr<RenderPassInterface>>
Vector of render passes that define how the layer should be rendered
buildComputePasses
std::vector<std::shared_ptr<ComputePassInterface>>
Builds and returns the compute passes for this layer.
return
std::vector<std::shared_ptr<ComputePassInterface>>
Vector of compute passes for GPU computation tasks
setPrimaryRenderTarget
void
Sets the primary render target for the layer.

Visibility Control

hide
void
Hides the layer without removing it from the map.
show
void
Shows a previously hidden layer.
setAlpha
void
Sets the opacity/transparency of the layer.
getAlpha
float
Returns the current alpha value of the layer.
return
float
Current alpha value between 0.0 and 1.0
setScissorRect
void
Sets a rectangular clipping region for the layer.When set, only the portion of the layer within the scissor rectangle will be rendered. Pass an empty optional to remove scissoring.

Masking

setMaskingObject
void
Sets a masking object to control where the layer is rendered.

Ready State

isReadyToRenderOffscreen
LayerReadyState
Checks if the layer is ready to render offscreen.
return
LayerReadyState
Ready state enum indicating layer readiness:
  • READY (0): Layer is ready to render
  • NOT_READY (1): Layer is not yet ready
  • ERROR (2): Layer encountered an error
  • TIMEOUT_ERROR (3): Layer timed out while loading

Animation Control

enableAnimations
void
Enables or disables animations for the layer.

Error Handling

setErrorManager
void
Sets the error manager for handling layer errors.

Layer Ready States

The LayerReadyState enum defines the possible ready states:
enum class LayerReadyState : int {
    READY = 0,           // Layer is ready to render
    NOT_READY = 1,       // Layer is not yet ready
    ERROR = 2,           // Layer encountered an error
    TIMEOUT_ERROR = 3,   // Layer timed out while loading
};

Usage Example

// Create a custom layer implementation
class MyLayer : public LayerInterface {
public:
    void onAdded(const std::shared_ptr<MapInterface>& map, int32_t index) override {
        // Initialize layer resources
        mapInterface_ = map;
        layerIndex_ = index;
    }
    
    void onRemoved() override {
        // Clean up resources
        mapInterface_.reset();
    }
    
    void update() override {
        // Update layer state before rendering
    }
    
    std::vector<std::shared_ptr<RenderPassInterface>> buildRenderPasses() override {
        // Build and return render passes
        std::vector<std::shared_ptr<RenderPassInterface>> passes;
        // ... create passes
        return passes;
    }
    
    void setAlpha(float alpha) override {
        alpha_ = std::clamp(alpha, 0.0f, 1.0f);
    }
    
    // ... implement other methods
};

// Using a layer
auto layer = std::make_shared<MyLayer>();
layer->setAlpha(0.8f);
layer->enableAnimations(true);

map->addLayer(layer);

// Control visibility
layer->hide();
layer->show();

// Check ready state
if (layer->isReadyToRenderOffscreen() == LayerReadyState::READY) {
    // Layer is ready
}

// Remove layer
map->removeLayer(layer);

Layer Types

Several specialized layer types extend LayerInterface:
  • Tiled2dMapRasterLayerInterface - Raster tile layers
  • Tiled2dMapVectorLayerInterface - Vector tile layers
  • PolygonLayerInterface - Polygon rendering layers
  • LineLayerInterface - Line rendering layers
  • IconLayerInterface - Icon/marker layers
  • TextLayerInterface - Text rendering layers

See Also

Build docs developers (and LLMs) love