Deckgl example
# DeckGL Map Example
This notebook demonstrates the DeckGLMap widget for high-performance data visualization in Jupyter environments.
DeckGL is a WebGL-powered framework for visual exploratory data analysis of large datasets.
## Basic DeckGL Map
Create a basic DeckGL map widget with default settings.
## Scatterplot Layer
Add a scatterplot layer with random points around San Francisco.
## Hexagon Layer
Add a hexagon layer for spatial aggregation visualization. This demonstrates DeckGL's ability to aggregate point data into hexagonal bins.
## Layer Management
Demonstrate layer management capabilities like listing and controlling layers.
## Summary
This notebook demonstrated the key features of the DeckGLMap widget:
1. **Basic map creation** with center, zoom, and size configuration
2. **Scatterplot layer** for visualizing point data with custom colors and sizes
3. **Hexagon layer** for spatial aggregation and 3D visualization
4. **Layer management** for listing and controlling layers
5. **3D controls** for setting pitch and bearing to create perspective views
The DeckGLMap widget provides high-performance WebGL-based visualization capabilities suitable for large datasets and complex geospatial visualizations. It's particularly effective for:
- Large-scale data visualization (millions of points)
- Interactive data exploration
- 3D geospatial visualization
- Real-time data streaming visualization
- Custom data aggregation and analysis
To test the map functionality, run all cells above and interact with the map by panning, zooming, and clicking on the visualization layers.
In [1]:
Copied!
import anymap
import numpy as np
import random
import anymap
import numpy as np
import random
In [2]:
Copied!
# Create a basic DeckGL map
deck_map = anymap.DeckGLMap(
center=[37.7749, -122.4194], zoom=10, width="100%", height="600px" # San Francisco
)
deck_map
# Create a basic DeckGL map
deck_map = anymap.DeckGLMap(
center=[37.7749, -122.4194], zoom=10, width="100%", height="600px" # San Francisco
)
deck_map
Out[2]:
In [3]:
Copied!
# Generate random data points around San Francisco
num_points = 1000
base_lat, base_lng = 37.7749, -122.4194
scatterplot_data = []
for i in range(num_points):
lat = base_lat + (random.random() - 0.5) * 0.1
lng = base_lng + (random.random() - 0.5) * 0.1
scatterplot_data.append(
{
"position": [lng, lat],
"radius": random.randint(20, 100),
"color": [
random.randint(0, 255),
random.randint(0, 255),
random.randint(0, 255),
200,
],
}
)
# Add scatterplot layer
deck_map.add_scatterplot_layer(
layer_id="scatterplot",
data=scatterplot_data,
get_position="position",
get_radius="radius",
get_color="color",
radius_scale=1,
pickable=True,
)
print(f"Added {len(scatterplot_data)} points to the scatterplot layer")
# Generate random data points around San Francisco
num_points = 1000
base_lat, base_lng = 37.7749, -122.4194
scatterplot_data = []
for i in range(num_points):
lat = base_lat + (random.random() - 0.5) * 0.1
lng = base_lng + (random.random() - 0.5) * 0.1
scatterplot_data.append(
{
"position": [lng, lat],
"radius": random.randint(20, 100),
"color": [
random.randint(0, 255),
random.randint(0, 255),
random.randint(0, 255),
200,
],
}
)
# Add scatterplot layer
deck_map.add_scatterplot_layer(
layer_id="scatterplot",
data=scatterplot_data,
get_position="position",
get_radius="radius",
get_color="color",
radius_scale=1,
pickable=True,
)
print(f"Added {len(scatterplot_data)} points to the scatterplot layer")
Added 1000 points to the scatterplot layer
In [4]:
Copied!
# Generate data for hexagon layer
num_hex_points = 2000
hex_data = []
for i in range(num_hex_points):
lat = base_lat + (random.random() - 0.5) * 0.2
lng = base_lng + (random.random() - 0.5) * 0.2
hex_data.append({"position": [lng, lat], "weight": random.random() * 10})
# Add hexagon layer
deck_map.add_hexagon_layer(
layer_id="hexagons",
data=hex_data,
get_position="position",
get_weight="weight",
radius=500,
elevation_scale=4,
pickable=True,
extruded=True,
)
print(f"Added hexagon layer with {len(hex_data)} data points")
# Generate data for hexagon layer
num_hex_points = 2000
hex_data = []
for i in range(num_hex_points):
lat = base_lat + (random.random() - 0.5) * 0.2
lng = base_lng + (random.random() - 0.5) * 0.2
hex_data.append({"position": [lng, lat], "weight": random.random() * 10})
# Add hexagon layer
deck_map.add_hexagon_layer(
layer_id="hexagons",
data=hex_data,
get_position="position",
get_weight="weight",
radius=500,
elevation_scale=4,
pickable=True,
extruded=True,
)
print(f"Added hexagon layer with {len(hex_data)} data points")
Added hexagon layer with 2000 data points
In [5]:
Copied!
# List all layers
layers = deck_map.get_layers()
print("Current layers:")
for layer_id in layers.keys():
print(f"- {layer_id}")
# Demonstrate map controls
deck_map.set_pitch(45) # Tilt the map for 3D effect
deck_map.set_bearing(30) # Rotate the map
print("\nSet pitch to 45° and bearing to 30° for a 3D perspective view")
# List all layers
layers = deck_map.get_layers()
print("Current layers:")
for layer_id in layers.keys():
print(f"- {layer_id}")
# Demonstrate map controls
deck_map.set_pitch(45) # Tilt the map for 3D effect
deck_map.set_bearing(30) # Rotate the map
print("\nSet pitch to 45° and bearing to 30° for a 3D perspective view")
Current layers: - scatterplot - hexagons Set pitch to 45° and bearing to 30° for a 3D perspective view