Animate map camera around a point
This source code of this example is adapted from the MapLibre GL JS example - Animate map camera around a point.
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# %pip install "leafmap[maplibre]"
# %pip install "leafmap[maplibre]"
In [2]:
Copied!
import time
import leafmap.maplibregl as leafmap
import time
import leafmap.maplibregl as leafmap
In [3]:
Copied!
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
In [4]:
Copied!
m = leafmap.Map(center=[-87.62712, 41.89033], zoom=15, pitch=45, style="streets")
layers = m.get_style_layers()
for layer in layers:
if layer["type"] == "symbol" and ("text-field" in layer["layout"]):
m.remove_layer(layer["id"])
layer = {
"id": "3d-buildings",
"source": "composite",
"source-layer": "building",
"filter": ["==", "extrude", "true"],
"type": "fill-extrusion",
"min_zoom": 15,
"paint": {
"fill-extrusion-color": "#aaa",
"fill-extrusion-height": [
"interpolate",
["linear"],
["zoom"],
15,
0,
15.05,
["get", "height"],
],
"fill-extrusion-base": [
"interpolate",
["linear"],
["zoom"],
15,
0,
15.05,
["get", "min_height"],
],
"fill-extrusion-opacity": 0.6,
},
}
m.add_layer(layer)
m
m = leafmap.Map(center=[-87.62712, 41.89033], zoom=15, pitch=45, style="streets")
layers = m.get_style_layers()
for layer in layers:
if layer["type"] == "symbol" and ("text-field" in layer["layout"]):
m.remove_layer(layer["id"])
layer = {
"id": "3d-buildings",
"source": "composite",
"source-layer": "building",
"filter": ["==", "extrude", "true"],
"type": "fill-extrusion",
"min_zoom": 15,
"paint": {
"fill-extrusion-color": "#aaa",
"fill-extrusion-height": [
"interpolate",
["linear"],
["zoom"],
15,
0,
15.05,
["get", "height"],
],
"fill-extrusion-base": [
"interpolate",
["linear"],
["zoom"],
15,
0,
15.05,
["get", "min_height"],
],
"fill-extrusion-opacity": 0.6,
},
}
m.add_layer(layer)
m
Failed to retrieve the MapTiler style. Defaulting to 'dark-matter' style.
In [5]:
Copied!
for degree in range(0, 360, 1):
m.rotate_to(degree, {"duration": 0})
time.sleep(0.1)
for degree in range(0, 360, 1):
m.rotate_to(degree, {"duration": 0})
time.sleep(0.1)