Multiview Map
In this guide, you will learn how to display multiple interactive maps in one viewport.
Live Demo
Overview
This example demonstrates the following features:
- Display multiple map views in a grid layout
- Each map view is independently interactive (panning, zooming)
- Dynamic add/remove map views with buttons
- Maximum of 4 map views in a 2x2 grid
Code Implementation
Setup UI and Grid
Add and Remove Map Views
Render Map Views
Initialize Application
Key Features
Grid Layout
The example uses CSS Grid for responsive layout:
- 2 columns: Maps displayed in a 2x2 grid
- Auto rows: Each row takes equal height
- Gap and padding: 10px spacing between map views
- Responsive: Adjusts to viewport size
Dynamic View Management
Map views are managed dynamically:
- Add views: Click ➕ to add a new map (up to 4)
- Remove views: Click ➖ to remove the last map
- Independent maps: Each map is a separate instance
- Proper cleanup: Map resources are released when removed
View Creation
Each map view is created with:
- Unique view ID (0, 1, 2, 3)
- Individual container element
- Separate GemMap instance
- Independent interaction (pan, zoom)
Implementation Details
Map View Entry Type
type MapViewEntry = {
container: HTMLElement,
gemMap: GemMap | null
};
This tracks both the DOM container and the GemMap instance for each view.
Resource Management
When removing a map view:
- Pop the entry from the array
- Release the GemMap instance (if available)
- Remove the container from the DOM
- Clean up resources properly
View Limits
The maximum number of views is set to 4:
- Prevents performance issues
- Maintains usable view size
- Fits in 2x2 grid layout
Use Cases
- Comparison: Compare different map locations side by side
- Multi-region monitoring: View multiple areas simultaneously
- Before/after: Compare different map styles or time periods
- Analysis: Analyze different map layers or data sets
Next Steps
- Overlapped Maps - Layer maps on top of each other
- Map Selection - Select and interact with map objects