Skip to content

Core Architecture

OpenLayers is built around four fundamental components that form the backbone of every mapping application: Map, View, Layers, and Sources. These components work together to create an interactive map that can display and manipulate geospatial data from various sources.

The Four Core Components

OpenLayers Core Architecture Overview

SVG
100%

Map: The Central Orchestrator

The Map class (src/ol/Map.js242) serves as the central orchestrator that coordinates all other components. It manages the rendering lifecycle and maintains the overall state of the mapping application.

Map Class Structure

SVG
100%

Map Responsibilities

The Map class orchestrates the rendering process through several key mechanisms:

ComponentResponsibility
DOM ManagementCreates viewport, overlay containers src/ol/Map.js369-401
Rendering CoordinationManages FrameState and triggers renders src/ol/Map.js336-338
Tile LoadingCoordinates tile loading through TileQueue src/ol/Map.js484-487
Event RoutingRoutes browser events to interactions and controls
Component LifecycleManages collections of layers, controls, interactions, overlays

View: State Management and Projections

The View class manages the visual state of the map including center position, resolution (zoom level), and rotation. It provides the geometric context for rendering and user interactions.

View State and FrameState Integration

SVG
100%

Key View Responsibilities

FunctionPurposeImplementation
State ManagementTrack center, resolution, rotationViewState object in FrameState
Projection HandlingConvert between coordinate systemsUses ol/proj system
Constraint ApplicationLimit view changes to valid rangesConstraint functions applied on change
Animation SupportSmooth transitions between statesAnimation queue with easing functions
Transform CalculationConvert coordinates to pixelsCreates transform matrices for FrameState

Layers: Display Hierarchy

Layers define what gets rendered on the map and in what order. Each layer references a source for its data and can have rendering-specific properties like opacity and visibility.

Layer Architecture and Inheritance

SVG
100%

Layer-Source Relationship

SVG
100%

Sources: Data Providers

Sources provide the data that layers display. They handle loading, caching, and managing geospatial data from various formats and protocols.

Source Types and Tile Management

SVG
100%

Tile Loading and Priority System

The TileQueue manages tile loading with a priority system based on distance from viewport center:

ComponentFunctionLocation
TileQueueManages loading queuesrc/ol/TileQueue.js19-50
getTilePriorityCalculates tile prioritysrc/ol/TileQueue.js131-159
Tile statesTrack loading progresssrc/ol/TileState.js8-18
VectorRenderTileSpecial tiles for vector datasrc/ol/VectorRenderTile.js24-100

Tile State Lifecycle

SVG
100%

FrameState: The Rendering Context

The FrameState object is central to OpenLayers' rendering architecture. It captures a snapshot of the map's state at a specific moment and provides all information needed for rendering.

FrameState Structure and Usage

SVG
100%

Key FrameState Properties

PropertyTypePurpose
viewStateViewStateCurrent view center, resolution, rotation
layerStatesArrayArray<LayerState>Visibility, opacity, extent for each layer
tileQueueTileQueueTile loading management
coordinateToPixelTransformTransformConvert map coordinates to screen pixels
pixelToCoordinateTransformTransformConvert screen pixels to map coordinates
timenumberTimestamp for animations and transitions
extentExtentVisible map extent in map units
sizeSizeMap size in pixels

Component Lifecycle and Initialization

The four core components follow a specific initialization order and lifecycle when creating an OpenLayers map.

Initialization Sequence

SVG
100%

Core Component Dependencies

SVG
100%

Summary

The OpenLayers Core Architecture is built around four fundamental components:

Component Responsibilities

ComponentPrimary RoleKey Classes
MapCentral orchestrator and rendering coordinatorMap, FrameState
ViewState management and coordinate transformationsView, ViewState
LayersDisplay hierarchy and rendering configurationLayerGroup, VectorLayer, TileLayer
SourcesData provision and tile managementVectorSource, OSM, XYZ, TileQueue

Critical Interactions

  1. Map creates and maintains FrameState objects that capture rendering context
  2. View provides geometric state (ViewState) that becomes part of FrameState
  3. Layers organize what gets rendered and reference Sources for data
  4. Sources manage data loading through the TileQueue system
  5. TileQueue prioritizes tile loading based on distance from viewport center

This architecture provides a clean separation of concerns while maintaining efficient coordination between components. The FrameState concept is central to understanding how these components work together during rendering.

Default Interactions and Controls

OpenLayers provides default sets of interactions and controls that are automatically added to maps unless specified otherwise:

Default InteractionsDescription
DragRotateRotate the map by dragging with Alt+Shift+drag
DragPanPan the map by dragging
PinchRotateRotate the map using two-finger rotation
PinchZoomZoom the map using two-finger pinch
KeyboardPanPan the map using keyboard arrows
KeyboardZoomZoom the map using keyboard +/-
MouseWheelZoomZoom the map using the mouse wheel
DragZoomZoom to a box by Shift+drag
DoubleClickZoomZoom by double-clicking
Default ControlsDescription
ZoomButtons to zoom in and out
RotateButton to reset rotation to north
AttributionAttribution text

These default sets can be customized or replaced entirely:

// Custom interactions
const map = new Map({
  interactions: [
    new DragPan(),
    new MouseWheelZoom({
      constrainResolution: true
    })
  ],
  // ... other options
});

// No interactions
const map = new Map({
  interactions: [],
  // ... other options
});

// Default interactions with custom options
const map = new Map({
  interactions: defaultInteractions({
    altShiftDragRotate: false,
    pinchRotate: false
  }),
  // ... other options
});

Summary

The Core Architecture of OpenLayers is built around the Map as the central component, which manages a View for handling the map's visual state, collections of Interactions for user input, and collections of Layers for displaying content. This architecture provides a clean separation of concerns while maintaining efficient communication between components.

The constraints system in the View ensures consistent and predictable behavior when interacting with the map, while the Interaction system provides a flexible way to handle various types of user input. Together, these components form the foundation of the OpenLayers library.