Skip to content

docs: update ImageOverlay with local file example #2111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions docs/user_guide/raster_layers/image_overlay.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,31 @@ If you have a static image file on your disk, you can simply draw it on the map.
import os
import folium

m = folium.Map([37, 0], zoom_start=1)
merc = os.path.join("data", "Mercator_projection_SW.png")


if not os.path.isfile(merc):
print(f"Could not find {merc}")
else:
img = folium.raster_layers.ImageOverlay(
name="Mercator projection SW",
image=merc,
bounds=[[-82, -180], [82, 180]],
opacity=0.6,
interactive=True,
cross_origin=False,
zindex=1,
)
m = folium.Map([0, 0], zoom_start=2)
image_filepath = os.path.join("..", "..", "_static", "folium_logo.png")

img = folium.raster_layers.ImageOverlay(
name="Folium logo",
image=image_filepath,
bounds=[[-50, -45], [50, 45]],
opacity=0.6,
interactive=True,
cross_origin=False,
zindex=1,
)

folium.Popup("I am an image").add_to(img)
folium.Popup("I am an image").add_to(img)

img.add_to(m)
folium.LayerControl().add_to(m)
img.add_to(m)
folium.LayerControl().add_to(m)

m
```

A few remarks:

* Note that your image has to be in Mercator projection format.
Note that your image has to be in Mercator projection format.

The image we've used is based on https://en.wikipedia.org/wiki/File:Mercator_projection_SW.jpg ; that you can find in wikipedia's article on Mercator Projection (https://en.wikipedia.org/wiki/Mercator_projection).

## Using an image from a url

You can also provide simply URL. In this case, the image will not be embedded in folium's output.

Expand Down