You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importfoliumimportnumpyasnpfromfolium.raster_layersimportImageOverlayfromPILimportImage, ImageDraw# Create sample datacoords=np.array([[37.7749, -122.4194]]) # San Francisco coordinatesimage_path="sample_overlay.png"# Create a sample image with a solid rectangleimg_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 circledraw.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 boundarieslat_min, lon_min=coords[0][0] -0.006, coords[0][1] -0.006lat_max, lon_max=coords[0][0] +0.006, coords[0][1] +0.006# Create folium mapmap_center= [coords[0][0], coords[0][1]]
m=folium.Map(location=map_center, zoom_start=15, control_scale=True)
# Add circle firstfolium.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 HTMLm.save("folium_layer_issue.html")
print("Saved folium_layer_issue.html")
Result:
The text was updated successfully, but these errors were encountered:
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:
Result:
The text was updated successfully, but these errors were encountered: