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:
Event Processing Framework
The system processes raw browser events through a structured pipeline that normalizes input and applies conditional logic:
Event Condition Functions
The system provides a comprehensive set of condition functions for event filtering and behavior modification:
| Condition Function | Purpose | Usage Example |
|---|---|---|
| noModifierKeys | No modifier keys pressed | Default drawing condition |
| primaryAction | Primary button/touch action | Feature modification |
| altKeyOnly | Alt key only | Vertex deletion |
| shiftKeyOnly | Shift key only | Freehand drawing mode |
| singleClick | Single click event | Feature selection |
| always | Always true | Unconditional interactions |
| never | Always false | Disabled interactions |
Feature Editing Workflow
The feature editing interactions follow a coordinated workflow that integrates drawing, modification, selection, and snapping:
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/Property | Purpose | Implementation |
|---|---|---|
| handleDownEvent() | Initiates interaction sequence | Returns boolean to start drag |
| handleDragEvent() | Processes drag movements | Called during active drag |
| handleUpEvent() | Completes interaction sequence | Returns boolean to continue |
| handlingDownUpSequence | Tracks drag state | Boolean flag for active drag |
| targetPointers | Multi-touch pointer tracking | Array of active pointer events |
| getPointerCount() | Active pointer count | Used for multi-touch detection |
Drawing Interaction Details
The Draw interaction supports multiple geometry types with sophisticated coordinate management:
Geometry Type Support
Tracing Feature Integration
The Draw interaction includes advanced tracing capabilities for following existing geometry:
Snapping System Architecture
The Snap interaction provides intelligent coordinate adjustment for precise feature alignment:
Spatial Indexing and Target Detection
Integration with Map and Layer Systems
The Interaction System integrates seamlessly with other OpenLayers components:
Vector Layer Integration
| Integration Point | Purpose | Implementation |
|---|---|---|
| Feature Creation | Add new features to sources | Draw → VectorSource.addFeature() |
| Feature Modification | Update existing geometries | Modify → Direct geometry updates |
| Feature Selection | Visual highlighting | Select → Style overrides |
| Hit Detection | Identify target features | Map pixel queries |
Overlay System Integration
| Interaction | Overlay Usage | Purpose |
|---|---|---|
| Draw | Sketch overlay | Real-time drawing preview |
| Modify | Vertex overlay | Modification handle display |
| Snap | No overlay | Direct coordinate modification |
| Select | Style changes | Selection highlighting |
Event Lifecycle and State Management
Interactions maintain complex state through event-driven lifecycles: