Skip to content

Circle elements always appear above ImageOverlay regardless of addition order #2131

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

Closed
dhyanKaro opened this issue Apr 10, 2025 · 2 comments
Closed

Comments

@dhyanKaro
Copy link

Attempting to place an ImageOverlay above Circle elements doesn't work in Folium. Regardless of the order elements are added to the map, circles always appear on top.

Example:

import folium
import numpy as np
from folium.raster_layers import ImageOverlay
from PIL import Image, ImageDraw

# Create sample data
coords = np.array([[37.7749, -122.4194]])  # San Francisco coordinates
image_path = "sample_overlay.png"

# Create a sample image with a solid rectangle
img_size = (500, 500)
img = Image.new('RGBA', img_size, (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
# Draw a solid blue rectangle that will partially overlap with the circle
draw.rectangle(
    [(img_size[0]//2, img_size[1]//4), 
     (img_size[0], 3*img_size[1]//4)], 
    fill=(0, 0, 255, 255)
)
img.save(image_path)

# Map boundaries
lat_min, lon_min = coords[0][0] - 0.006, coords[0][1] - 0.006
lat_max, lon_max = coords[0][0] + 0.006, coords[0][1] + 0.006

# Create folium map
map_center = [coords[0][0], coords[0][1]]
m = folium.Map(location=map_center, zoom_start=15, control_scale=True)

# Add circle first
folium.Circle(
    location=map_center,
    radius=500,
    color='red',
    fill=True,
    fill_color='red',
    fill_opacity=0.5,
    weight=2,
    opacity=0.7,
).add_to(m)

# Then add image overlay (should be on top but isn't)
ImageOverlay(
    image=image_path,
    bounds=[[lat_min, lon_min], [lat_max, lon_max]],
    opacity=1.0,
    interactive=True,
    cross_origin=False,
).add_to(m)

# Save HTML
m.save("folium_layer_issue.html")
print("Saved folium_layer_issue.html")

Result:

Image

@hoangquochung1110
Copy link

hoangquochung1110 commented Apr 12, 2025

I think you should clearly specify:
Actual result
and Expected result

by this way, people can grasp your issue well and help you out
*I'm not sure if you'd like to remove and put the circle at back

@hansthen
Copy link
Collaborator

hansthen commented Apr 12, 2025

@dhyanKaro You expected the blue rectangle to be in front of the red circle, correct?

You can make the zIndex (try > 400) of the ImageOverlay higher to move it in front of the folium.Circle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants