Grid Cell Layer Example¶
Regular grid cell visualization using deck.gl GridCellLayer.
In [ ]:
Copied!
# %pip install anymap-ts
# %pip install anymap-ts
In [ ]:
Copied!
import random
from anymap_ts import DeckGLMap
import random
from anymap_ts import DeckGLMap
Generate grid cell data¶
In [ ]:
Copied!
# Generate a grid of cells
grid_cells = []
center_lng, center_lat = -122.4, 37.8
grid_size = 10
for i in range(grid_size):
for j in range(grid_size):
grid_cells.append(
{
"position": [
center_lng + (i - grid_size / 2) * 0.003,
center_lat + (j - grid_size / 2) * 0.003,
],
"elevation": random.randint(100, 1000),
"color": [
random.randint(100, 255),
random.randint(100, 255),
255,
200,
],
}
)
# Generate a grid of cells
grid_cells = []
center_lng, center_lat = -122.4, 37.8
grid_size = 10
for i in range(grid_size):
for j in range(grid_size):
grid_cells.append(
{
"position": [
center_lng + (i - grid_size / 2) * 0.003,
center_lat + (j - grid_size / 2) * 0.003,
],
"elevation": random.randint(100, 1000),
"color": [
random.randint(100, 255),
random.randint(100, 255),
255,
200,
],
}
)
Create map with grid cell layer¶
In [ ]:
Copied!
m = DeckGLMap(center=[-122.4, 37.8], zoom=12, pitch=45, bearing=-17)
m.add_basemap("CartoDB.DarkMatter")
m.add_grid_cell_layer(
data=grid_cells,
get_position="position",
get_elevation="elevation",
get_fill_color="color",
cell_size=200,
extruded=True,
elevation_scale=1,
pickable=True,
)
m
m = DeckGLMap(center=[-122.4, 37.8], zoom=12, pitch=45, bearing=-17)
m.add_basemap("CartoDB.DarkMatter")
m.add_grid_cell_layer(
data=grid_cells,
get_position="position",
get_elevation="elevation",
get_fill_color="color",
cell_size=200,
extruded=True,
elevation_scale=1,
pickable=True,
)
m
Export to HTML¶
In [ ]:
Copied!
m.to_html("gridcell_layer_example.html")
m.to_html("gridcell_layer_example.html")