Map Perspective
This example demonstrates how to toggle the map view angle between 2D (vertical look-down at the map) and 3D (perspective, tilted map, looking toward the horizon).
Live Demo
Code Implementation
Key Features
View Angle Control
Toggle between different map viewing perspectives:
- 2D View (90°): Vertical look-down view, map appears flat from directly above
- 3D View (30°): Tilted perspective view, looking toward the horizon
- Dynamic Switching: Smooth transition between view modes
Building Visibility
The example controls building rendering based on the perspective:
- 2D Mode: Buildings rendered in two-dimensional style
- 3D Mode: Buildings displayed with three-dimensional depth and detail
- Synchronized Settings: Building visibility automatically matches the view angle
How It Works
- Initialize Map: Create the map view and get access to map preferences
- Create UI Button: Add a toggle button in the top-right corner
- Handle Toggle: Switch between 2D and 3D perspectives on button click
- Update Settings: Adjust tilt angle and building visibility simultaneously
- Visual Feedback: Update button icon to reflect current mode
Implementation Details
Tilt Angle Configuration
The map perspective is controlled through the tiltAngle property:
- 90 degrees: Orthogonal/vertical view (looking straight down)
- 30 degrees: Perspective view (tilted toward horizon)
- Range: Valid angles are between 0° and 90°
Buildings Visibility Modes
The SDK provides two building rendering modes:
BuildingsVisibility.twoDimensional: Flat building representationBuildingsVisibility.threeDimensional: 3D building models with depth
Map Preferences
Map preferences are accessed through map.preferences:
- Control tilt angle with
mapPreferences.tiltAngle - Control building rendering with
mapPreferences.buildingsVisibility - Changes take effect immediately
UI Components
Perspective Toggle Button
The button provides visual feedback and interaction:
- Position: Fixed in top-right corner
- Icons: 🗻 for 2D mode, 🗺️ for 3D mode
- Styling: Purple background matching the app theme
- Interaction: Click to toggle between perspectives
Use Cases
- Navigation: 3D perspective helps users orient themselves while navigating
- Exploration: 2D view provides better overview for route planning
- Urban Areas: 3D buildings provide better context in cities
- Comparison: Switch between views to understand terrain and features