Cesium Example¶
This notebook demonstrates the Cesium integration in anymap-ts.
Cesium is a powerful 3D globe visualization library with terrain and 3D Tiles support.
Note: Some features like Cesium World Terrain require a Cesium Ion access token. Set the CESIUM_TOKEN environment variable.
In [ ]:
Copied!
from anymap_ts import CesiumMap
# Create a Cesium globe (uses CESIUM_TOKEN env var)
m = CesiumMap(center=[-122.4, 37.8], zoom=10)
m.add_basemap("OpenStreetMap")
m
from anymap_ts import CesiumMap
# Create a Cesium globe (uses CESIUM_TOKEN env var)
m = CesiumMap(center=[-122.4, 37.8], zoom=10)
m.add_basemap("OpenStreetMap")
m
In [ ]:
Copied!
# Enable terrain (requires Cesium Ion token)
# m.set_terrain()
# Enable terrain (requires Cesium Ion token)
# m.set_terrain()
In [ ]:
Copied!
# Add GeoJSON
geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-122.4194, 37.7749]},
"properties": {"name": "San Francisco"},
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-122.5, 37.7],
[-122.3, 37.7],
[-122.3, 37.9],
[-122.5, 37.9],
[-122.5, 37.7],
]
],
},
"properties": {"name": "Area"},
},
],
}
m.add_geojson(geojson, name="features", stroke="#ff0000", fill="rgba(255,0,0,0.3)")
# Add GeoJSON
geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-122.4194, 37.7749]},
"properties": {"name": "San Francisco"},
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-122.5, 37.7],
[-122.3, 37.7],
[-122.3, 37.9],
[-122.5, 37.9],
[-122.5, 37.7],
]
],
},
"properties": {"name": "Area"},
},
],
}
m.add_geojson(geojson, name="features", stroke="#ff0000", fill="rgba(255,0,0,0.3)")
In [ ]:
Copied!
# Fly to a location with camera orientation
m.fly_to(-122.4194, 37.7749, height=50000, heading=45, pitch=-45)
# Fly to a location with camera orientation
m.fly_to(-122.4194, 37.7749, height=50000, heading=45, pitch=-45)
In [ ]:
Copied!
# Reset to home view
m.reset_view()
# Reset to home view
m.reset_view()
In [ ]:
Copied!
# Add 3D Tileset (requires Cesium Ion token and asset ID)
# m.add_3d_tileset(url="your_ion_asset_id", name="buildings")
# Add 3D Tileset (requires Cesium Ion token and asset ID)
# m.add_3d_tileset(url="your_ion_asset_id", name="buildings")
In [ ]:
Copied!
# Export to HTML
m.to_html("cesium_example.html")
# Export to HTML
m.to_html("cesium_example.html")