Skip to content

Interaction System

Purpose and Scope

The Interaction System provides a comprehensive framework for handling user input and enabling interactive map manipulation in OpenLayers. This system manages mouse, touch, and keyboard events to support map navigation, feature creation, editing, and selection operations. It transforms raw browser events into meaningful map interactions through a modular, extensible architecture.

For information about rendering interactions and visual feedback, see Rendering System. For UI controls and widgets, see Controls System.

System Architecture

The Interaction System is built around a hierarchical class structure with event-driven communication patterns:

SVG
100%

Event Processing Framework

The system processes raw browser events through a structured pipeline that normalizes input and applies conditional logic:

SVG
100%

Event Condition Functions

The system provides a comprehensive set of condition functions for event filtering and behavior modification:

Condition FunctionPurposeUsage Example
noModifierKeysNo modifier keys pressedDefault drawing condition
primaryActionPrimary button/touch actionFeature modification
altKeyOnlyAlt key onlyVertex deletion
shiftKeyOnlyShift key onlyFreehand drawing mode
singleClickSingle click eventFeature selection
alwaysAlways trueUnconditional interactions
neverAlways falseDisabled interactions

Feature Editing Workflow

The feature editing interactions follow a coordinated workflow that integrates drawing, modification, selection, and snapping:

SVG
100%

Pointer Interaction Base Class

The PointerInteraction class provides the foundation for most user input handling, managing drag sequences and multi-touch scenarios:

Key Methods and Properties

Method/PropertyPurposeImplementation
handleDownEvent()Initiates interaction sequenceReturns boolean to start drag
handleDragEvent()Processes drag movementsCalled during active drag
handleUpEvent()Completes interaction sequenceReturns boolean to continue
handlingDownUpSequenceTracks drag stateBoolean flag for active drag
targetPointersMulti-touch pointer trackingArray of active pointer events
getPointerCount()Active pointer countUsed for multi-touch detection

Drawing Interaction Details

The Draw interaction supports multiple geometry types with sophisticated coordinate management:

Geometry Type Support

SVG
100%

Tracing Feature Integration

The Draw interaction includes advanced tracing capabilities for following existing geometry:

SVG
100%

Snapping System Architecture

The Snap interaction provides intelligent coordinate adjustment for precise feature alignment:

Spatial Indexing and Target Detection

SVG
100%

Integration with Map and Layer Systems

The Interaction System integrates seamlessly with other OpenLayers components:

Vector Layer Integration

Integration PointPurposeImplementation
Feature CreationAdd new features to sourcesDraw → VectorSource.addFeature()
Feature ModificationUpdate existing geometriesModify → Direct geometry updates
Feature SelectionVisual highlightingSelect → Style overrides
Hit DetectionIdentify target featuresMap pixel queries

Overlay System Integration

InteractionOverlay UsagePurpose
DrawSketch overlayReal-time drawing preview
ModifyVertex overlayModification handle display
SnapNo overlayDirect coordinate modification
SelectStyle changesSelection highlighting

Event Lifecycle and State Management

Interactions maintain complex state through event-driven lifecycles:

Interaction State Transitions

SVG
100%