Animate a series of images
This source code of this example is adapted from the MapLibre GL JS example - Animate a series of images.
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=[-75.789, 41.874], zoom=5, min_zoom=4, max_zoom=6, style="streets"
)
def get_path(index):
return f"https://maplibre.org/maplibre-gl-js/docs/assets/radar{index}.gif"
source = {
"type": "image",
"url": get_path(0),
"coordinates": [
[-80.425, 46.437],
[-71.516, 46.437],
[-71.516, 37.936],
[-80.425, 37.936],
],
}
m.add_source("radar", source)
layer = {
"id": "radar-layer",
"type": "raster",
"source": "radar",
"paint": {"raster-fade-duration": 0},
}
m.add_layer(layer)
m
m = leafmap.Map(
center=[-75.789, 41.874], zoom=5, min_zoom=4, max_zoom=6, style="streets"
)
def get_path(index):
return f"https://maplibre.org/maplibre-gl-js/docs/assets/radar{index}.gif"
source = {
"type": "image",
"url": get_path(0),
"coordinates": [
[-80.425, 46.437],
[-71.516, 46.437],
[-71.516, 37.936],
[-80.425, 37.936],
],
}
m.add_source("radar", source)
layer = {
"id": "radar-layer",
"type": "raster",
"source": "radar",
"paint": {"raster-fade-duration": 0},
}
m.add_layer(layer)
m
Failed to retrieve the MapTiler style. Defaulting to OpenFreeMap 'liberty' style.
The following step does not work properly yet. Will revisit this when it becomes possible.
In [5]:
Copied!
for i in range(5):
time.sleep(1)
source = {
"type": "image",
"url": get_path(i),
"coordinates": [
[-80.425, 46.437],
[-71.516, 46.437],
[-71.516, 37.936],
[-80.425, 37.936],
],
}
m.set_data("radar", source)
for i in range(5):
time.sleep(1)
source = {
"type": "image",
"url": get_path(i),
"coordinates": [
[-80.425, 46.437],
[-71.516, 46.437],
[-71.516, 37.936],
[-80.425, 37.936],
],
}
m.set_data("radar", source)